Skip to content

Commit

Permalink
feat: copilot 编辑器支持免登录 TencentBlueKing#11290
Browse files Browse the repository at this point in the history
  • Loading branch information
hejieehe committed Dec 5, 2024
1 parent 65c1c4f commit cf21239
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ object RepositoryMessageCode {
const val REPOSITORY_NO_SUPPORT_OAUTH = "2115045" // ({0})类型代码库暂不支持OAUTH授权

const val USER_NOT_PERMISSIONS_OPERATE_REPOSITORY = "2115046" // 用户({0})无权限在工程({1})下{2}流水线{3}
const val FAIL_TO_GET_OPEN_COPILOT_TOKEN = "2115048" // 获取open copilot token 失败, 失败详情: {0}

const val BK_REQUEST_FILE_SIZE_LIMIT = "bkRequestFileSizeLimit" // 请求文件不能超过1M
const val OPERATION_ADD_CHECK_RUNS = "OperationAddCheckRuns" // 添加检测任务
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ package com.tencent.devops.repository.pojo.enums

enum class TokenTypeEnum(val type: Int) {
OAUTH(0), // oauth认证
PRIVATE_KEY(1); // privateKey认证
PRIVATE_KEY(1), // oauth认证
COPILOT_TOKEN(2); // copilot token

companion object {
fun getTokenType(type: Int): String {
return when (type) {
0 -> OAUTH.name
1 -> PRIVATE_KEY.name
2 -> COPILOT_TOKEN.name
else -> OAUTH.name
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ import java.time.LocalDateTime

@Repository
class GitTokenDao {
fun getAccessToken(dslContext: DSLContext, userId: String): TRepositoryGitTokenRecord? {
fun getAccessToken(
dslContext: DSLContext,
userId: String,
tokenType: String = DEFAULT_TOKEN_TYPE
): TRepositoryGitTokenRecord? {
with(TRepositoryGitToken.T_REPOSITORY_GIT_TOKEN) {
return dslContext.selectFrom(this)
.where(USER_ID.eq(userId))
.where(USER_ID.eq(userId).and(TOKEN_TYPE.eq(tokenType)))
.fetchOne()
}
}
Expand Down Expand Up @@ -73,11 +77,20 @@ class GitTokenDao {
}
}

fun deleteToken(dslContext: DSLContext, userId: String): Int {
fun deleteToken(
dslContext: DSLContext,
userId: String,
tokenType: String = DEFAULT_TOKEN_TYPE
): Int {
with(TRepositoryGitToken.T_REPOSITORY_GIT_TOKEN) {
return dslContext.deleteFrom(this)
.where(USER_ID.eq(userId))
.where(USER_ID.eq(userId).and(TOKEN_TYPE.eq(tokenType)))
.execute()
}
}

companion object {
// oauth授权后的默认token类型
const val DEFAULT_TOKEN_TYPE = "bearer"
}
}
1 change: 1 addition & 0 deletions support-files/i18n/repository/message_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
2115044=User [{0}] has not authorized Github Oauth yet. Please authorize first
2115045=({0}) type of code repository does not currently support OAUTH authorization
2100054=User ({0}) does not have permission to {2} repository {3} under project ({1}).
2115048=Failed to get open copilot token, failure details: {0}
bkRequestFileSizeLimit=The request file cannot exceed 1m
OperationAddCheckRuns=Add a detection task
OperationUpdateCheckRuns=Update the detection task
Expand Down
1 change: 1 addition & 0 deletions support-files/i18n/repository/message_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
2115044=用户[{0}]尚未进行GITHUB OAUTH授权,请先授权
2115045=({0})类型代码库暂不支持OAUTH授权
2115046=用户({0})无权限在工程({1})下{2}代码库{3}
2115048=获取open copilot token 失败, 失败详情: {0}
bkRequestFileSizeLimit=请求文件不能超过1M
OperationAddCheckRuns=添加检测任务
OperationUpdateCheckRuns=更新检测任务
Expand Down

0 comments on commit cf21239

Please sign in to comment.