Skip to content

Commit

Permalink
Merge pull request #4482 from irwinsun/issue_4475
Browse files Browse the repository at this point in the history
Issue 4475
  • Loading branch information
irwinsun authored Jun 23, 2021
2 parents 4c1afbc + 4fe3dc0 commit d04dff7
Show file tree
Hide file tree
Showing 58 changed files with 590 additions and 905 deletions.
23 changes: 18 additions & 5 deletions src/backend/ci/boot-assembly/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,40 @@ dependencies {
testImplementation("junit:junit")
testImplementation("org.springframework.boot:spring-boot-starter-test")

implementation(project(":core:common:common-auth:common-auth-mock"))
implementation(project(":core:common:common-auth:common-auth-blueking"))
implementation(project(":core:common:common-auth:common-auth-v3"))
implementation(project(":core:common:common-archive"))

implementation(project(":core:artifactory:biz-artifactory-store"))
implementation(project(":core:artifactory:biz-artifactory-sample"))
implementation(project(":core:auth:biz-auth-blueking"))
implementation(project(":core:dispatch:biz-dispatch"))
implementation(project(":core:dispatch-docker:biz-dispatch-docker"))
implementation(project(":core:dispatch-docker:biz-dispatch-docker-sample"))
implementation(project(":core:environment:biz-environment-sample"))
implementation(project(":core:image:biz-image"))
implementation(project(":core:log:biz-log"))
implementation(project(":core:misc:biz-misc"))
implementation(project(":core:log:biz-log-sample"))
implementation(project(":core:misc:biz-misc-sample"))
implementation(project(":core:notify:biz-notify-blueking"))
implementation(project(":core:openapi:biz-openapi"))
implementation(project(":core:plugin:biz-plugin"))
implementation(project(":core:process:plugin-load"))
implementation(project(":core:process:plugin-trigger"))
implementation(project(":core:process:biz-engine"))
implementation(project(":core:process:biz-process-sample"))
implementation(project(":core:project:biz-project-sample"))
implementation(project(":core:quality:biz-quality"))
implementation(project(":core:quality:biz-quality-sample"))
implementation(project(":core:repository:biz-repository-sample"))
implementation(project(":core:store:biz-store-sample"))
implementation(project(":core:store:biz-store-image-sample"))
implementation(project(":core:ticket:biz-ticket-sample"))
implementation(project(":core:websocket:biz-websocket"))
implementation(project(":core:websocket:biz-websocket-blueking"))
}

plugins {
`task-spring-boot-package`
}

configurations.all {
exclude(group = "javax.ws.rs", module = "jsr311-api")
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,28 @@ package com.tencent.devops

import com.tencent.devops.common.service.MicroService
import com.tencent.devops.common.service.MicroServiceApplication
import org.jooq.SQLDialect
import org.jooq.impl.DefaultConfiguration
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import javax.sql.DataSource

@MicroService
@ComponentScan("com.tencent.devops")
class AssemblyApplication
class AssemblyApplication {

@Bean
fun defaultJooqConfiguration(
@Qualifier("dataSource")
dataSource: DataSource
): DefaultConfiguration {
val configuration = DefaultConfiguration()
configuration.set(SQLDialect.MYSQL)
configuration.set(dataSource)
return configuration
}
}

fun main(args: Array<String>) {
MicroServiceApplication.run(AssemblyApplication::class, args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
spring:
main:
allow-bean-definition-overriding: true
application:
name: bk-ci
name: bk-ci${service-suffix}
desc: DevOps BK-CI Service
version: 0.0.1
packageName: com.tencent.devops
cloud:
consul:
discovery:
service-name: bk-ci # single service 合并后的单体服务
service-name: bk-ci${service-suffix} # single service 合并后的单体服务
file:
allowUploadFileTypes: jpg,png,gif,swf,txt,doc,docx,xls,xlsx,ppt,pptx,pdf,svg,mp4,wmv,rm,rmvb,3gp,mov,m4v,avi,dat,mkv,flv,vob
maxUploadFileSize: 52428800
Expand All @@ -17,4 +19,4 @@ aes:
aesMock: "******"

server:
port: 21900
port: 21900
2 changes: 1 addition & 1 deletion src/backend/ci/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ allprojects {
group = "com.tencent.bk.devops.ci"

// 版本
version = "1.6.0"
version = "1.5.5"
val devopsVersion = System.getProperty("ci_version")
if (devopsVersion != null) {
version = devopsVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import org.springframework.stereotype.Service
@Service
class IamService @Autowired constructor(
val iamEsbService: IamEsbService,
val iamConfiguration: IamConfiguration
@Autowired(required = false) // v3 才会有
val iamConfiguration: IamConfiguration?
) {
fun getPermissionUrl(permissionUrlDTO: List<PermissionUrlDTO>): Result<String?> {
logger.info("get permissionUrl permissionUrlDTO: $permissionUrlDTO")
Expand All @@ -60,42 +61,42 @@ class IamService @Autowired constructor(

if (instanceList == null || instanceList.isEmpty()) {
relatedResourceTypes.add(RelatedResourceTypes(
system = iamConfiguration.systemId,
type = relatedResourceType,
instances = emptyList()
system = iamConfiguration!!.systemId,
type = relatedResourceType,
instances = emptyList()
))
} else {
relatedResourceTypes.add(RelatedResourceTypes(
system = iamConfiguration.systemId,
type = relatedResourceType,
instances = listOf(instanceList))
system = iamConfiguration!!.systemId,
type = relatedResourceType,
instances = listOf(instanceList))
)
}

// 创建项目需特殊处理,无需关联任务资源
if (it.resourceId == AuthResourceType.PROJECT && it.actionId == AuthPermission.CREATE) {
logger.info("projectCreate ${it.actionId} |${it.instanceId}| ${it.resourceId}")
actions.add(
Action(
id = resourceType,
related_resource_types = emptyList()
)
Action(
id = resourceType,
related_resource_types = emptyList()
)
)
} else {
actions.add(
Action(
id = resourceType,
related_resource_types = relatedResourceTypes
)
Action(
id = resourceType,
related_resource_types = relatedResourceTypes
)
)
}
}
val iamEsbReq = IamPermissionUrlReq(
system = iamConfiguration.systemId,
actions = actions,
bk_app_code = "",
bk_app_secret = "",
bk_username = "admin"
system = iamConfiguration!!.systemId,
actions = actions,
bk_app_code = "",
bk_app_secret = "",
bk_username = "admin"
)
logger.info("get permissionUrl iamEsbReq: $iamEsbReq")
return Result(iamEsbService.getPermissionUrl(iamEsbReq))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.tencent.devops.common.auth.api.BkAuthProjectApi
import com.tencent.devops.common.auth.api.BkAuthProperties
import com.tencent.devops.common.auth.api.BkAuthResourceApi
import com.tencent.devops.common.auth.api.BkAuthTokenApi
import com.tencent.devops.common.auth.api.BkAuthUserApi
import com.tencent.devops.common.auth.api.utils.AuthUtils
import com.tencent.devops.common.auth.code.BkArtifactoryAuthServiceCode
import com.tencent.devops.common.auth.code.BkBcsAuthServiceCode
Expand Down Expand Up @@ -75,6 +76,10 @@ class BkAuthAutoConfiguration {
authProperties.bkloginUrl
)

@Bean
@Primary
fun bkAuthUserApi(objectMapper: ObjectMapper, authUtils: AuthUtils) = BkAuthUserApi(objectMapper, authUtils)

@Bean
@Primary
fun bkAuthTokenApi(bkAuthProperties: BkAuthProperties, objectMapper: ObjectMapper, redisOperation: RedisOperation) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ import com.tencent.devops.common.auth.api.utils.AuthUtils
import org.json.JSONObject
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component@Suppress("ALL")
@Suppress("ALL", "UNUSED")
class BkAuthUserApi @Autowired constructor(
private val objectMapper: ObjectMapper,
private val authUtils: AuthUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@ import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.io.IOException
import java.util.Comparator
import java.util.TreeMap

@Component
class AuthUtils constructor(
xBkAuthProperties: BkAuthProperties
) {
class AuthUtils constructor(xBkAuthProperties: BkAuthProperties) {
private val logger = LoggerFactory.getLogger(AuthUtils::class.java)
private val host = xBkAuthProperties.url!!

Expand All @@ -54,15 +49,15 @@ class AuthUtils constructor(
*/
fun doAuthGetRequest(uri: String, params: Map<String, Any>?, xBkAppCode: String, xBkAppSecret: String): JSONObject {
val url = this.getAuthRequestUrl(uri, params)
logger.debug("bkiam get request: $url")
logger.debug("bkiam get url: {}", url)

val request = Request.Builder()
.url(url)
.addHeader("X-BK-APP-CODE", xBkAppCode)
.addHeader("X-BK-APP-SECRET", xBkAppSecret)
.build()
val result = this.doRequest(request)
logger.debug("bkiam get request result: $result")
logger.debug("bkiam get request result: {}", result)
return result
}

Expand All @@ -72,8 +67,7 @@ class AuthUtils constructor(
fun doAuthPostRequest(uri: String, jsonbody: JSONObject, bkAppCode: String, bkAppSecret: String): JSONObject {
val body = RequestBody.create(MediaType.parse("application/json"), jsonbody.toString())
val url = this.getAuthRequestUrl(uri, null)
logger.debug("bkiam post url: $url")
logger.debug("bkiam post body: $jsonbody")
logger.debug("bkiam post url: {}, body: {}", url, jsonbody)

val request = Request.Builder()
.url(url)
Expand All @@ -82,7 +76,7 @@ class AuthUtils constructor(
.addHeader("X-BK-APP-SECRET", bkAppSecret)
.build()
val result = this.doRequest(request)
logger.debug("bkiam post request result: $result")
logger.debug("bkiam post request result: {}", result)
return result
}

Expand All @@ -92,8 +86,7 @@ class AuthUtils constructor(
fun doAuthPutRequest(uri: String, jsonbody: JSONObject, xBkAppCode: String, xBkAppSecret: String): JSONObject {
val body = RequestBody.create(MediaType.parse("application/json"), jsonbody.toString())
val url = this.getAuthRequestUrl(uri, null)
logger.debug("bkiam put url: $url")
logger.debug("bkiam put body: $jsonbody")
logger.debug("bkiam put url: {}, body: {}", url, jsonbody)

val request = Request.Builder()
.url(url)
Expand All @@ -102,7 +95,7 @@ class AuthUtils constructor(
.addHeader("X-BK-APP-SECRET", xBkAppSecret)
.build()
val result = this.doRequest(request)
logger.debug("bkiam put request result: $result")
logger.debug("bkiam put request result: {}", result)
return result
}

Expand All @@ -112,7 +105,7 @@ class AuthUtils constructor(
fun doAuthDeleteRequest(uri: String, jsonbody: JSONObject, xBkAppCode: String, xBkAppSecret: String): JSONObject {
val body = RequestBody.create(MediaType.parse("application/json"), jsonbody.toString())
val url = this.getAuthRequestUrl(uri, null)
logger.debug("bkiam delete request: $url")
logger.debug("bkiam delete url: {}", url)

val request = Request.Builder()
.url(url)
Expand All @@ -121,7 +114,7 @@ class AuthUtils constructor(
.addHeader("X-BK-APP-SECRET", xBkAppSecret)
.build()
val result = this.doRequest(request)
logger.debug("bkiam delete request result: $result")
logger.debug("bkiam delete request result: {}", result)
return result
}

Expand Down Expand Up @@ -151,12 +144,11 @@ class AuthUtils constructor(
val msg = jsonObject.getString("message")
jsonObject.put("message", msg)
jsonObject.put("code", responseCode)
logger.error("bkiam failed , message: $msg")
} catch (e: IOException) {
e.printStackTrace()
jsonObject.put("msg", "IO exception, network not ok")
} catch (e: JSONException) {
jsonObject.put("msg", "json parse error, bkiam response json format failed")
logger.warn("bkiam failed , message: $msg")
} catch (ioe: IOException) {
jsonObject.put("msg", "IO exception, network not ok: ${ioe.message}")
} catch (je: JSONException) {
jsonObject.put("msg", "json parse error, bkiam response json format failed: ${je.message}")
}
return jsonObject
}
Expand All @@ -181,7 +173,7 @@ class AuthUtils constructor(
} else {
notfirst = true
}
sb.append(String.format("%s=%s", key, value.toString()))
sb.append("$key=$value")
}
return host + sb.toString()
}
Expand Down
4 changes: 3 additions & 1 deletion src/backend/ci/core/common/common-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
dependencies {
api(project(":core:common:common-service"))
api(project(":core:common:common-api"))
api("io.github.openfeign:feign-jaxrs")
api("io.github.openfeign:feign-jaxrs") {
exclude(group = "javax.ws.rs", module = "jsr311-api")
}
api("io.github.openfeign:feign-okhttp")
api("io.github.openfeign:feign-jackson")
api("io.github.openfeign.form:feign-form")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

package com.tencent.devops.common.db

import com.mysql.jdbc.Driver
import com.mysql.cj.jdbc.Driver
import com.zaxxer.hikari.HikariDataSource
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.AutoConfigureBefore
Expand Down
Loading

0 comments on commit d04dff7

Please sign in to comment.