-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11250 from hejieehe/feat_10995
feat:支持管理我的 OAUTH #10995
- Loading branch information
Showing
38 changed files
with
1,245 additions
and
32 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
.../ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/enums/ScmCode.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,45 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 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.devops.common.api.enums | ||
|
||
/** | ||
* 代码库类型 | ||
*/ | ||
enum class ScmCode(val scmName: String, val value: String) { | ||
TGIT("GIT", "TGIT"), // 内部工蜂 | ||
GITHUB("GITHUB", "GITHUB"), // github | ||
TGIT_CO("TGIT_CO", "TGIT-CO"); // github | ||
|
||
fun convertScmType(): ScmType { | ||
return when (this) { | ||
TGIT -> ScmType.CODE_GIT | ||
GITHUB -> ScmType.GITHUB | ||
TGIT_CO -> ScmType.CODE_TGIT | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwRepositoryOauthResourceV4.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,72 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 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.devops.openapi.api.apigw.v4 | ||
|
||
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE | ||
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE | ||
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_USER_ID | ||
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_USER_ID_DEFAULT_VALUE | ||
import com.tencent.devops.common.api.pojo.Result | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import javax.ws.rs.Consumes | ||
import javax.ws.rs.GET | ||
import javax.ws.rs.HeaderParam | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.PathParam | ||
import javax.ws.rs.Produces | ||
import javax.ws.rs.QueryParam | ||
import javax.ws.rs.core.MediaType | ||
|
||
@Tag(name = "OPEN_API_REPOSITORY_V4", description = "OPEN-API-代码库OAUTH授权") | ||
@Path("/{apigwType:apigw-user|apigw-app|apigw}/v4/repositories/oauth") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@SuppressWarnings("All") | ||
interface ApigwRepositoryOauthResourceV4 { | ||
@Operation( | ||
summary = "校验用户是否已经OAUTH授权", | ||
tags = ["v4_app_oauth_isOauth", "v4_user_oauth_isOauth"] | ||
) | ||
@GET | ||
@Path("/isOauth") | ||
fun isOauth( | ||
@Parameter(description = "appCode", required = true, example = AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE) | ||
@HeaderParam(AUTH_HEADER_DEVOPS_APP_CODE) | ||
appCode: String?, | ||
@Parameter(description = "apigw Type", required = true) | ||
@PathParam("apigwType") | ||
apigwType: String?, | ||
@Parameter(description = "用户ID", required = true, example = AUTH_HEADER_DEVOPS_USER_ID_DEFAULT_VALUE) | ||
@HeaderParam(AUTH_HEADER_DEVOPS_USER_ID) | ||
userId: String, | ||
@Parameter(description = "代码库类型", required = true) | ||
@QueryParam("scmCode") | ||
scmCode: String | ||
): Result<Boolean> | ||
} |
73 changes: 73 additions & 0 deletions
73
...src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwOauthResourceV4Impl.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,73 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 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.devops.openapi.resources.apigw.v4 | ||
|
||
import com.tencent.devops.common.api.enums.ScmCode | ||
import com.tencent.devops.common.api.pojo.Result | ||
import com.tencent.devops.common.client.Client | ||
import com.tencent.devops.common.web.RestResource | ||
import com.tencent.devops.openapi.api.apigw.v4.ApigwRepositoryOauthResourceV4 | ||
import com.tencent.devops.repository.api.ServiceOauthResource | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
@RestResource | ||
class ApigwOauthResourceV4Impl @Autowired constructor(private val client: Client) : ApigwRepositoryOauthResourceV4 { | ||
override fun isOauth( | ||
appCode: String?, | ||
apigwType: String?, | ||
userId: String, | ||
scmCode: String | ||
): Result<Boolean> { | ||
logger.info("OPENAPI_OAUTH_V4|$userId|verify if $scmCode oauth authorization has been performed") | ||
val result = when (scmCode) { | ||
ScmCode.TGIT.name -> { | ||
client.get(ServiceOauthResource::class).isOAuth( | ||
userId = userId, | ||
redirectUrl = null, | ||
redirectUrlType = null | ||
).data?.status | ||
} | ||
|
||
ScmCode.GITHUB.name -> { | ||
client.get(ServiceOauthResource::class).githubOAuth( | ||
userId = userId | ||
).data?.status | ||
} | ||
|
||
else -> { | ||
null | ||
} | ||
} | ||
return Result(result == AUTHORIZED_STATUS) | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(ApigwOauthResourceV4Impl::class.java) | ||
private const val AUTHORIZED_STATUS = 200 | ||
} | ||
} |
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
108 changes: 108 additions & 0 deletions
108
...ory/api-repository/src/main/kotlin/com/tencent/devops/repository/api/UserOauthResource.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,108 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 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.devops.repository.api | ||
|
||
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID | ||
import com.tencent.devops.common.api.pojo.Page | ||
import com.tencent.devops.common.api.pojo.Result | ||
import com.tencent.devops.repository.pojo.OauthResetUrl | ||
import com.tencent.devops.repository.pojo.RepoOauthRefVo | ||
import com.tencent.devops.repository.pojo.UserOauthRepositoryInfo | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import javax.ws.rs.Consumes | ||
import javax.ws.rs.DELETE | ||
import javax.ws.rs.GET | ||
import javax.ws.rs.HeaderParam | ||
import javax.ws.rs.POST | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.Produces | ||
import javax.ws.rs.QueryParam | ||
import javax.ws.rs.core.MediaType | ||
|
||
@Tag(name = "AUTH_RESOURCE", description = "用户态-iam资源映射") | ||
@Path("/user/repositories/oauth/") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
interface UserOauthResource { | ||
@GET | ||
@Path("/") | ||
@Operation(summary = "获取用户OAuth授权列表") | ||
fun list( | ||
@Parameter(description = "用户名", required = true) | ||
@HeaderParam(AUTH_HEADER_USER_ID) | ||
userId: String | ||
): Result<List<UserOauthRepositoryInfo>> | ||
|
||
@GET | ||
@Path("/relSource") | ||
@Operation(summary = "获取授权关联的资源列表") | ||
fun relSource( | ||
@Parameter(description = "用户名", required = true) | ||
@HeaderParam(AUTH_HEADER_USER_ID) | ||
userId: String, | ||
@Parameter(description = "授权类型", required = true) | ||
@QueryParam("scmCode") | ||
scmCode: String, | ||
@Parameter(description = "第几页", required = false, example = "1") | ||
@QueryParam("page") | ||
page: Int? = null, | ||
@Parameter(description = "每页多少条", required = false, example = "20") | ||
@QueryParam("pageSize") | ||
pageSize: Int? = null | ||
): Result<Page<RepoOauthRefVo>> | ||
|
||
@DELETE | ||
@Path("/delete") | ||
@Operation(summary = "删除oauth授权") | ||
fun delete( | ||
@Parameter(description = "用户名", required = true) | ||
@HeaderParam(AUTH_HEADER_USER_ID) | ||
userId: String, | ||
@Parameter(description = "授权类型", required = true) | ||
@QueryParam("scmCode") | ||
scmCode: String | ||
): Result<Boolean> | ||
|
||
@POST | ||
@Path("/reset") | ||
@Operation(summary = "重置授权") | ||
fun reset( | ||
@Parameter(description = "用户名", required = true) | ||
@HeaderParam(AUTH_HEADER_USER_ID) | ||
userId: String, | ||
@Parameter(description = "授权类型", required = true) | ||
@QueryParam("scmCode") | ||
scmCode: String, | ||
@Parameter(description = "回调链接(授权完以后的链接地址)", required = true) | ||
@QueryParam("redirectUrl") | ||
redirectUrl: String | ||
): Result<OauthResetUrl> | ||
} |
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
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
8 changes: 8 additions & 0 deletions
8
...sitory/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/OauthResetUrl.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,8 @@ | ||
package com.tencent.devops.repository.pojo | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(title = "重置Oauth授权信息") | ||
data class OauthResetUrl( | ||
val url: String | ||
) |
15 changes: 15 additions & 0 deletions
15
...itory/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoOauthRefVo.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,15 @@ | ||
package com.tencent.devops.repository.pojo | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(title = "用户关联的仓库") | ||
data class RepoOauthRefVo( | ||
@get:Schema(title = "仓库别名", required = true) | ||
val aliasName: String, | ||
@get:Schema(title = "仓库源URL", required = true) | ||
val url: String, | ||
@get:Schema(title = "蓝盾项目ID", required = true) | ||
val projectId: String, | ||
@get:Schema(title = "代码库HashId", required = true) | ||
val hashId: String | ||
) |
Oops, something went wrong.