Skip to content

Commit

Permalink
Fix authenticator plugin (#509)
Browse files Browse the repository at this point in the history
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

<!--
  ⬆ Put your description above this! ⬆

  Please be descriptive and detailed.
  
Please read our [Contributing
Guidelines](https://github.com/tinyspeck/slack-gradle-plugin/blob/main/.github/CONTRIBUTING.md)
and [Code of Conduct](https://slackhq.github.io/code-of-conduct).

Don't worry about deleting this, it's not visible in the PR!
-->
  • Loading branch information
ZacSweers authored Aug 8, 2023
1 parent bf0b308 commit ab4018f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
1 change: 0 additions & 1 deletion skate-plugin/artifactory-authenticator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ version = property("VERSION_NAME").toString()
repositories { mavenCentral() }

dependencies {
implementation(libs.okio)
testImplementation(libs.junit)
testImplementation(libs.truth)
}
2 changes: 1 addition & 1 deletion skate-plugin/artifactory-authenticator/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ INTELLIJ_PLUGIN=true
PLUGIN_ID=com.slack.intellij.artifactory
PLUGIN_NAME=Artifactory Authenticator
PLUGIN_DESCRIPTION=A plugin for authenticating plugin repositories with Artifactory.
VERSION_NAME=0.1.0
VERSION_NAME=0.1.1
PLUGIN_SINCE_BUILD=222
ARTIFACTORY_URL_SUFFIX=artifactory-authenticator
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@ package com.slack.intellij.artifactory
import com.intellij.ide.plugins.auth.PluginRepositoryAuthProvider
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.logger
import okio.ByteString.Companion.encode
import java.util.Base64

class ArtifactoryPluginRepositoryAuthProvider : PluginRepositoryAuthProvider {

private val settings =
ApplicationManager.getApplication().getService(AuthPluginSettings::class.java)
private val logger = logger<ArtifactoryPluginRepositoryAuthProvider>()

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

override fun getAuthHeaders(url: String): Map<String, String> {
logger.debug("Getting auth headers for $url")
val username = settings.username
val token = settings.token
logger.debug("Username: $username, token is null? ${token == null}")
return if (username != null && token != null) {
val encodedValue = "Basic " + "$username:$token".encode().base64()
val encodedValue = "Basic " + "$username:$token".encodeBase64()
mapOf("Authorization" to encodedValue)
} else {
emptyMap()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2023 Slack Technologies, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@
implementation="com.slack.intellij.artifactory.ArtifactoryPluginRepositoryAuthProvider"/>
<projectConfigurable instance="com.slack.intellij.artifactory.AuthConfig"/>
</extensions>

<!-- 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>

0 comments on commit ab4018f

Please sign in to comment.