Skip to content

Commit

Permalink
feat:用户个人视角 权限管理优化 #11138
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Dec 23, 2024
1 parent f572404 commit 7d74189
Showing 1 changed file with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ class BkRepoClient constructor(

fun enableProject(userId: String, projectId: String, enabled: Boolean): Boolean {
logger.info("enableProject, userId: $userId, projectId: $projectId, enabled: $enabled")
val requestData = BKRepoProjectUpdateRequest(metadata = listOf(ProjectMetadata(key = "enabled", value = enabled)))
val requestData = BKRepoProjectUpdateRequest(
metadata = listOf(ProjectMetadata(key = "enabled", value = enabled))
)
val request = Request.Builder()
.url("${getGatewayUrl()}/bkrepo/api/service/repository/api/project/$projectId")
.headers(getCommonHeaders(SYSTEM_USER, projectId).toHeaders())
Expand Down Expand Up @@ -214,7 +216,7 @@ class BkRepoClient constructor(
fun setMetadata(userId: String, projectId: String, repoName: String, path: String, metadata: Map<String, String>) {
logger.info(
"setMetadata, userId: $userId, projectId: $projectId, repoName: $repoName, path: $path," +
" metadata: $metadata"
" metadata: $metadata"
)
val url = "${getGatewayUrl()}/bkrepo/api/service/repository/api/metadata/$projectId/$repoName/$path"
val requestData = UserMetadataSaveRequest(
Expand Down Expand Up @@ -249,10 +251,10 @@ class BkRepoClient constructor(
): List<FileInfo> {
logger.info(
"listFile, userId: $userId, projectId: $projectId, repoName: $repoName, path: $path," +
" includeFolders: $includeFolders, deep: $deep"
" includeFolders: $includeFolders, deep: $deep"
)
val url = "${getGatewayUrl()}/bkrepo/api/service/generic/list/$projectId/$repoName/$path" +
"?deep=$deep&includeFolder=$includeFolders"
"?deep=$deep&includeFolder=$includeFolders"
val request = Request.Builder()
.url(url)
.headers(getCommonHeaders(userId, projectId).toHeaders())
Expand All @@ -274,12 +276,12 @@ class BkRepoClient constructor(
): Page<NodeInfo> {
logger.info(
"listFilePage, userId: $userId, projectId: $projectId, repoName: $repoName, path: $path," +
" includeFolders: $includeFolders, deep: $deep, page: $page, pageSize: $pageSize"
" includeFolders: $includeFolders, deep: $deep, page: $page, pageSize: $pageSize"
)
val direction = if (modifiedTimeDesc) Direction.DESC.name else Direction.ASC.name
val url = "${getGatewayUrl()}/bkrepo/api/service/repository/api/node/page/$projectId/$repoName/$path" +
"?deep=$deep&includeFolder=$includeFolders&includeMetadata=true&pageNumber=$page&pageSize=$pageSize" +
"&sortProperty=lastModifiedDate&direction=$direction"
"?deep=$deep&includeFolder=$includeFolders&includeMetadata=true&pageNumber=$page&pageSize=$pageSize" +
"&sortProperty=lastModifiedDate&direction=$direction"
val request = Request.Builder()
.url(url)
.headers(getCommonHeaders(userId, projectId).toHeaders())
Expand All @@ -300,7 +302,7 @@ class BkRepoClient constructor(
) {
logger.info(
"uploadFile, userId: $userId, projectId: $projectId, repoName: $repoName, path: $path," +
" fileSizeLimitInMB: $fileSizeLimitInMB"
" fileSizeLimitInMB: $fileSizeLimitInMB"
)
if (PathUtil.isFolder(path)) {
throw ErrorCodeException(errorCode = INVALID_CUSTOM_ARTIFACTORY_PATH)
Expand Down Expand Up @@ -353,7 +355,7 @@ class BkRepoClient constructor(
fun uploadLocalFile(userId: String, projectId: String, repoName: String, path: String, file: File) {
logger.info(
"uploadLocalFile, userId: $userId, projectId: $projectId, repoName: $repoName, path: $path," +
" localFile: ${file.canonicalPath}"
" localFile: ${file.canonicalPath}"
)
uploadLocalFile(
userId = userId,
Expand All @@ -380,7 +382,7 @@ class BkRepoClient constructor(
) {
logger.info(
"uploadLocalFile, projectId: $projectId, repoName: $repoName, path: $path," +
" localFile: ${file.canonicalPath}"
" localFile: ${file.canonicalPath}"
)
val gateway = gatewayUrl ?: getGatewayUrl()
val repoUrlPrefix = if (gatewayFlag) "$gateway/bkrepo/api/service/generic" else bkrepoApiUrl
Expand Down Expand Up @@ -436,7 +438,7 @@ class BkRepoClient constructor(
fun move(userId: String, projectId: String, repoName: String, fromPath: String, toPath: String) {
logger.info(
"move, userId: $userId, projectId: $projectId, repoName: $repoName, fromPath: $fromPath," +
" toPath: $toPath"
" toPath: $toPath"
)
val url = "${getGatewayUrl()}/bkrepo/api/service/repository/api/node/move"
val requestData = UserNodeMoveCopyRequest(
Expand Down Expand Up @@ -468,7 +470,7 @@ class BkRepoClient constructor(
) {
logger.info(
"copy, userId: $userId, fromProject: $fromProject, fromRepo: $fromRepo, fromPath: $fromPath," +
" toProject: $toProject, toRepo: $toRepo, toPath: $toPath"
" toProject: $toProject, toRepo: $toRepo, toPath: $toPath"
)
val url = "${getGatewayUrl()}/bkrepo/api/service/repository/api/node/copy"
val requestData = UserNodeMoveCopyRequest(
Expand All @@ -493,7 +495,7 @@ class BkRepoClient constructor(
fun rename(userId: String, projectId: String, repoName: String, fromPath: String, toPath: String) {
logger.info(
"rename, userId: $userId, projectId: $projectId, repoName: $repoName, fromPath: $fromPath," +
" toPath: $toPath"
" toPath: $toPath"
)
val url = "${getGatewayUrl()}/bkrepo/api/service/repository/api/node/rename"
val requestData = UserNodeRenameRequest(projectId, repoName, fromPath, toPath)
Expand Down Expand Up @@ -542,7 +544,7 @@ class BkRepoClient constructor(
): List<BkRepoFile> {
logger.info(
"matchBkRepoFile, userId: $userId, srcPath: $srcPath, projectId: $projectId," +
" pipelineId: $pipelineId, buildId: $buildId, isCustom: $isCustom"
" pipelineId: $pipelineId, buildId: $buildId, isCustom: $isCustom"
)
val repoName: String
val filePath: String
Expand Down Expand Up @@ -639,7 +641,7 @@ class BkRepoClient constructor(
): List<FileInfo> {
logger.info(
"listFileByPattern, userId: $userId, projectId: $projectId, pipelineId: $pipelineId," +
" buildId: $buildId, repoName: $repoName, pathPattern: $pathPattern"
" buildId: $buildId, repoName: $repoName, pathPattern: $pathPattern"
)
return if (pathPattern.endsWith("/")) {
val path = if (repoName == "pipeline") {
Expand Down Expand Up @@ -682,7 +684,7 @@ class BkRepoClient constructor(
): List<File> {
logger.info(
"downloadFileByPattern, userId: $userId, projectId: $projectId, pipelineId: $pipelineId," +
" buildId: $buildId, repoName: $repoName, pathPattern: $pathPattern, destPath: $destPath"
" buildId: $buildId, repoName: $repoName, pathPattern: $pathPattern, destPath: $destPath"
)
val fileList = listFileByPattern(
userId,
Expand Down Expand Up @@ -718,8 +720,8 @@ class BkRepoClient constructor(
): String {
logger.info(
"createShareUri, creatorId: $creatorId, projectId: $projectId, repoName: $repoName, " +
"fullPath: $fullPath, downloadUsers: $downloadUsers, downloadIps: $downloadIps, " +
"timeoutInSeconds: $timeoutInSeconds"
"fullPath: $fullPath, downloadUsers: $downloadUsers, downloadIps: $downloadIps, " +
"timeoutInSeconds: $timeoutInSeconds"
)
val repoUrlPrefix = if (bkrepoPrefixUrl.isNullOrBlank()) {
"${getGatewayUrl()}/bkrepo/api/service"
Expand Down Expand Up @@ -778,7 +780,7 @@ class BkRepoClient constructor(
): ApkDefenderTasks {
logger.info(
"apkDefender , projectId: $projectId , repoName: $repoName , fullPath: $fullPath , " +
"userIds: $userIds, batchSize: $batchSize"
"userIds: $userIds, batchSize: $batchSize"
)
val url = "${getGatewayUrl()}/bkrepo/api/external/analyst/api/ext/apk/defender"
val apkDefenderRequest = ApkDefenderRequest(
Expand Down Expand Up @@ -844,8 +846,8 @@ class BkRepoClient constructor(
): List<String> {
logger.info(
"createTemporaryAccessUrl, userId: $userId, projectId: $projectId, repoName: $repoName, " +
"fullPathSet: $fullPathSet, downloadUsersSet: $downloadUsersSet, downloadIps: $downloadIpsSet," +
" timeoutInSeconds: $timeoutInSeconds"
"fullPathSet: $fullPathSet, downloadUsersSet: $downloadUsersSet, downloadIps: $downloadIpsSet," +
" timeoutInSeconds: $timeoutInSeconds"
)
val url = "${getGatewayUrl()}/bkrepo/api/service/generic/temporary/url/create"
val requestData = TemporaryTokenCreateRequest(
Expand Down Expand Up @@ -878,7 +880,7 @@ class BkRepoClient constructor(
): QueryData {
logger.info(
"queryByRepoAndMetadata, userId: $userId, projectId: $projectId, repoNames: $repoNames," +
" fileNames: $fileNames, metadata: $metadata, page: $page, pageSize: $pageSize"
" fileNames: $fileNames, metadata: $metadata, page: $page, pageSize: $pageSize"
)
val projectRule = Rule.QueryRule("projectId", projectId, OperationType.EQ)
val ruleList = mutableListOf<Rule>(projectRule, Rule.QueryRule("folder", false, OperationType.EQ))
Expand Down Expand Up @@ -915,8 +917,8 @@ class BkRepoClient constructor(
): QueryData {
logger.info(
"queryByPathEqOrNameMatchOrMetadataEqAnd, userId: $userId, projectId: $projectId," +
" repoNames: $repoNames, filePaths: $filePaths, fileNames: $fileNames, metadata: $metadata," +
" page: $page, pageSize: $pageSize"
" repoNames: $repoNames, filePaths: $filePaths, fileNames: $fileNames, metadata: $metadata," +
" page: $page, pageSize: $pageSize"
)
val projectRule = Rule.QueryRule("projectId", projectId, OperationType.EQ)
val repoRule = Rule.QueryRule("repoName", repoNames, OperationType.IN)
Expand Down Expand Up @@ -963,8 +965,8 @@ class BkRepoClient constructor(
): QueryData {
logger.info(
"queryByPathNamePairOrMetadataEqAnd, userId: $userId, projectId: $projectId," +
" repoNames: $repoNames, pathNamePairs: $pathNamePairs, metadata: $metadata," +
" page: $page, pageSize: $pageSize"
" repoNames: $repoNames, pathNamePairs: $pathNamePairs, metadata: $metadata," +
" page: $page, pageSize: $pageSize"
)
val projectRule = Rule.QueryRule("projectId", projectId, OperationType.EQ)
val repoRule = Rule.QueryRule("repoName", repoNames, OperationType.IN)
Expand Down Expand Up @@ -1000,7 +1002,7 @@ class BkRepoClient constructor(
): QueryData {
logger.info(
"queryByPattern, userId: $userId, projectId: $projectId, repoNames: $repoNames," +
" fullPathPatterns: $fullPathPatterns, metadata: $metadata"
" fullPathPatterns: $fullPathPatterns, metadata: $metadata"
)
val projectRule = Rule.QueryRule("projectId", projectId, OperationType.EQ)
val repoRule = Rule.QueryRule("repoName", repoNames, OperationType.IN)
Expand Down Expand Up @@ -1033,7 +1035,7 @@ class BkRepoClient constructor(
): QueryData {
logger.info(
"listFileByQuery, userId: $userId, projectId: $projectId, repoName: $repoName," +
" path: $path, includeFolders: $includeFolders"
" path: $path, includeFolders: $includeFolders"
)
val projectRule = Rule.QueryRule("projectId", projectId, OperationType.EQ)
val repoRule = Rule.QueryRule("repoName", repoName, OperationType.EQ)
Expand Down Expand Up @@ -1082,7 +1084,7 @@ class BkRepoClient constructor(
metadata: Map<String, String>? = null
): PackageVersionInfo {
val url = "${getGatewayUrl()}/bkrepo/api/service/docker/ext/version/detail/$projectId/$repoName" +
"?packageKey=$packageKey&version=$version"
"?packageKey=$packageKey&version=$version"
val request = Request.Builder().url(url).headers(getCommonHeaders(userId, projectId).toHeaders()).get().build()
return doRequest(request).resolveResponse<Response<PackageVersionInfo>>()!!.data!!
}
Expand Down

0 comments on commit 7d74189

Please sign in to comment.