Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authenticator plugin #509

Merged
merged 2 commits into from
Aug 8, 2023
Merged

Fix authenticator plugin #509

merged 2 commits into from
Aug 8, 2023

Conversation

ZacSweers
Copy link
Collaborator

Continuing from #500. Also had to remove the okio dependency as it appears to conflict with dependencies coming from the intellij plugin now, so using standard java to do it. Tested this with studio giraffe (the bugged version) and it works now

@github-actions
Copy link

github-actions bot commented Aug 8, 2023

  1. Remove the unused dependency on okio in the build.gradle.kts file:
dependencies {
-  implementation(libs.okio)
   testImplementation(libs.junit)
   testImplementation(libs.truth)
 }
  1. Update the version number in the gradle.properties file:
-VERSION_NAME=0.1.0
+VERSION_NAME=0.1.1
  1. Replace the usage of okio.ByteString with java.util.Base64 in the ArtifactoryPluginRepositoryAuthProvider.kt file:
-import okio.ByteString.Companion.encode
+import java.util.Base64

class ArtifactoryPluginRepositoryAuthProvider : PluginRepositoryAuthProvider {
  // ...

+  private fun String.encodeBase64() = Base64.getEncoder().encodeToString(encodeToByteArray())

  override fun getAuthHeaders(url: String): Map<String, String> {
    // ...
-      val encodedValue = "Basic " + "$username:$token".encode().base64()
+      val encodedValue = "Basic " + "$username:$token".encodeBase64()
    // ...
  }
}
  1. Add the RepoAuthHotfix class to fix the issue with plugin repository authentication in the RepoAuthHotfix.kt file:
package com.slack.intellij.artifactory

import com.intellij.ide.AppLifecycleListener
import com.intellij.ide.plugins.auth.PluginRepositoryAuthService
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger

/** Workaround for https://youtrack.jetbrains.com/issue/IDEA-315487. */
class RepoAuthHotfix : AppLifecycleListener {
  private val logger = logger<RepoAuthHotfix>()

  override fun appFrameCreated(commandLineArgs: List<String>) {
    logger.debug("Initializing ${PluginRepositoryAuthService::class.simpleName}")
    service<PluginRepositoryAuthService>()
  }
}
  1. Register the RepoAuthHotfix class as an application listener in the plugin.xml file:
 <idea-plugin>
   <!-- ... -->
 
+  <!-- Workaround for https://youtrack.jetbrains.com/issue/IDEA-315487 -->
+  <applicationListeners>
+    <listener class="com.slack.intellij.artifactory.RepoAuthHotfix"
+              topic="com.intellij.ide.AppLifecycleListener"/>
+  </applicationListeners>
+
 </idea-plugin>

Copy link
Contributor

@arpita184 arpita184 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Can you please add a documentation around why this hotfix was needed for future us. Thanks!

@ZacSweers
Copy link
Collaborator Author

Can you please add a documentation around why this hotfix was needed for future us. Thanks!

I added a link to the issue in docs on both the plugin.xml element and the hotfix class, I think that should be good enough for posterity 👍

@ZacSweers ZacSweers added this pull request to the merge queue Aug 8, 2023
Merged via the queue into main with commit ab4018f Aug 8, 2023
3 checks passed
@ZacSweers ZacSweers deleted the z/fixRepoAuth branch August 8, 2023 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants