forked from TencentBlueKing/bk-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 支持Generic Remote仓库下载 TencentBlueKing#1400 (TencentBlueKing#1406)
* feat: 支持Generic Remote仓库下载 TencentBlueKing#1400 * feat: 支持Generic Remote仓库使用平台账号认证 TencentBlueKing#1400 * feat: 支持搜索Generic Remote仓库 TencentBlueKing#1400
- Loading branch information
Showing
14 changed files
with
544 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../src/main/kotlin/com/tencent/bkrepo/common/service/util/okhttp/PlatformAuthInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bkrepo.common.service.util.okhttp | ||
|
||
import com.tencent.bkrepo.common.api.constant.AUTH_HEADER_UID | ||
import com.tencent.bkrepo.common.api.constant.HttpHeaders | ||
import com.tencent.bkrepo.common.api.constant.PLATFORM_AUTH_PREFIX | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import java.util.Base64 | ||
|
||
/** | ||
* 平台账号认证拦截器,用于添加平台认证凭据与用户ID到请求中 | ||
*/ | ||
class PlatformAuthInterceptor(accessKey: String, secretKey: String, private val userId: String) : Interceptor { | ||
|
||
private val credentials = platform(accessKey, secretKey) | ||
|
||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val request = chain.request() | ||
val authenticatedRequest = request.newBuilder() | ||
.header(HttpHeaders.AUTHORIZATION, credentials) | ||
.header(AUTH_HEADER_UID, userId) | ||
.build() | ||
return chain.proceed(authenticatedRequest) | ||
} | ||
|
||
fun platform(ak: String, sk: String): String { | ||
val encoded = Base64.getEncoder().encodeToString("$ak:$sk".toByteArray()) | ||
return "$PLATFORM_AUTH_PREFIX$encoded" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.