Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
owenlxu committed Jun 24, 2024
2 parents 8e2ba77 + c258dde commit ff6c348
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class AuthInterceptor(
}

private fun checkUserFromBasic(request: HttpServletRequest, authHeader: String): Boolean {
val userAccess = userAccessApiSet.any { request.requestURI.startsWith(it) }
val userAccess = userAccessApiSet.any { request.requestURI.contains(it) }
val encodedCredentials = authHeader.removePrefix(BASIC_AUTH_HEADER_PREFIX)
val decodedHeader = String(Base64.getDecoder().decode(encodedCredentials))
val parts = decodedHeader.split(COLON)
Expand Down Expand Up @@ -188,8 +188,8 @@ class AuthInterceptor(
}

private fun setAuthAttribute(userId: String, appId: String, request: HttpServletRequest) {
val userAccess = userAccessApiSet.any { request.requestURI.startsWith(it) }
val anonymousAccess = anonymousAccessApiSet.any { request.requestURI.startsWith(it) }
val userAccess = userAccessApiSet.any { request.requestURI.contains(it) }
val anonymousAccess = anonymousAccessApiSet.any { request.requestURI.contains(it) }
val userInfo = userService.getUserInfoById(userId)
val isAdmin: Boolean = userInfo?.admin ?: false
if (userId.isNotEmpty() && userInfo == null && userId != ANONYMOUS_USER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ open class CIPermissionManager(
buildId: String?,
taskId: String? = null
): PipelineBuildStatus {
if (!ciPermissionProperties.enabled) {
if (!ciPermissionProperties.enabled || whiteListRequest()) {
return PipelineBuildStatus(SecurityUtils.getUserId(), false, "RUNNING")
}
var url = "${ciPermissionProperties.host}/ms/process/api/open/service/pipeline/get_build_status?" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.tencent.bkrepo.common.storage.core.AbstractEncryptorFileStorage
import com.tencent.bkrepo.common.storage.credentials.InnerCosCredentials
import com.tencent.bkrepo.common.storage.innercos.client.CosClient
import com.tencent.bkrepo.common.storage.innercos.request.CheckObjectExistRequest
import com.tencent.bkrepo.common.storage.innercos.request.CopyObjectRequest
import com.tencent.bkrepo.common.storage.innercos.request.DeleteObjectRequest
import com.tencent.bkrepo.common.storage.innercos.request.GetObjectRequest
import com.tencent.bkrepo.common.storage.innercos.request.MigrateObjectRequest
Expand Down Expand Up @@ -88,15 +87,7 @@ open class InnerCosFileStorage : AbstractEncryptorFileStorage<InnerCosCredential
}

override fun copy(path: String, name: String, fromClient: CosClient, toClient: CosClient) {
val sameCos = fromClient.credentials.region == toClient.credentials.region &&
fromClient.credentials.secretId == toClient.credentials.secretId &&
fromClient.credentials.secretKey == toClient.credentials.secretKey &&
fromClient.credentials.encrypt == toClient.credentials.encrypt
if (sameCos) {
toClient.copyObject(CopyObjectRequest(fromClient.credentials.bucket, name, name))
} else {
toClient.migrateObject(MigrateObjectRequest(fromClient, name))
}
toClient.migrateObject(MigrateObjectRequest(fromClient, name))
}

override fun checkRestore(path: String, name: String, client: CosClient): Boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const val RECORD_RESERVE_DAYS = "recordReserveDays"
const val REPLICA_TYPE = "replicaType"
const val NAME = "name"
const val SIZE = "size"
const val NODE_NUM = "nodeNum"


/**
* 缓存类型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import java.time.Duration
@Component
@EnableConfigurationProperties(ActiveProjectEmptyFolderCleanupJobProperties::class)
class ActiveProjectEmptyFolderCleanupJob(
properties: ActiveProjectEmptyFolderCleanupJobProperties,
private val properties: ActiveProjectEmptyFolderCleanupJobProperties,
executor: ThreadPoolTaskExecutor,
private val activeProjectService: ActiveProjectService,
private val mongoTemplate: MongoTemplate,
Expand Down Expand Up @@ -104,7 +104,7 @@ class ActiveProjectEmptyFolderCleanupJob(
override fun onRunProjectFinished(collection: String, projectId: String, context: JobContext) {
require(context is EmptyFolderCleanupJobContext)
logger.info("will filter empty folder in project $projectId")
emptyFolderCleanup.emptyFolderHandler(collection, context, projectId)
emptyFolderCleanup.emptyFolderHandler(collection, context, properties.deletedEmptyFolder, projectId)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import com.tencent.bkrepo.job.DELETED_DATE
import com.tencent.bkrepo.job.FOLDER
import com.tencent.bkrepo.job.FULL_PATH
import com.tencent.bkrepo.job.LAST_MODIFIED_DATE
import com.tencent.bkrepo.job.NODE_NUM
import com.tencent.bkrepo.job.PROJECT
import com.tencent.bkrepo.job.REPO
import com.tencent.bkrepo.job.SIZE
import com.tencent.bkrepo.job.batch.context.EmptyFolderCleanupJobContext
import com.tencent.bkrepo.job.batch.utils.FolderUtils
import com.tencent.bkrepo.job.batch.utils.FolderUtils.extractFolderInfoFromCacheKey
Expand Down Expand Up @@ -108,6 +110,7 @@ class EmptyFolderCleanup(
fun emptyFolderHandler(
collection: String,
context: EmptyFolderCleanupJobContext,
deletedEmptyFolder: Boolean,
projectId: String = StringPool.EMPTY,
runCollection: Boolean = false,
) {
Expand All @@ -128,9 +131,10 @@ class EmptyFolderCleanup(
)) {
logger.info(
"will delete empty folder ${folderInfo.fullPath}" +
" in repo ${folderInfo.projectId}|${folderInfo.repoName}"
" in repo ${folderInfo.projectId}|${folderInfo.repoName} " +
"with config deletedEmptyFolder: $deletedEmptyFolder"
)
doEmptyFolderDelete(entry.value.id, collection)
doEmptyFolderDelete(entry.value.id, collection, deletedEmptyFolder)
context.totalDeletedNum.increment()
}
}
Expand Down Expand Up @@ -163,17 +167,21 @@ class EmptyFolderCleanup(
*/
private fun doEmptyFolderDelete(
objectId: String?,
collectionName: String
collectionName: String,
deletedEmptyFolder: Boolean,
) {
if (objectId.isNullOrEmpty()) return
val query = Query(
Criteria.where(ID).isEqualTo(ObjectId(objectId))
.and(FOLDER).isEqualTo(true)
)
val deleteTime = LocalDateTime.now()
val update = Update()
.set(LAST_MODIFIED_DATE, deleteTime)
.set(DELETED_DATE, deleteTime)
val update = Update().set(LAST_MODIFIED_DATE, deleteTime)
if (deletedEmptyFolder) {
update.set(DELETED_DATE, deleteTime)
} else {
update.set(SIZE, 0).set(NODE_NUM, 0)
}
mongoTemplate.updateFirst(query, update, collectionName)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ class InactiveProjectEmptyFolderCleanupJob(
require(context is EmptyFolderCleanupJobContext)
super.onRunCollectionFinished(collectionName, context)
logger.info("will filter empty folder in $collectionName")
emptyFolderCleanup.emptyFolderHandler(collectionName, context, runCollection = true)
emptyFolderCleanup.emptyFolderHandler(
collectionName, context,
properties.deletedEmptyFolder, runCollection = true,
)
}

data class Node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties
class ActiveProjectEmptyFolderCleanupJobProperties(
override var enabled: Boolean = true,
override var cron: String = "0 0/30 * * * ?",
var deletedEmptyFolder: Boolean = false,
) : StatJobProperties()
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties
class InactiveProjectEmptyFolderCleanupJobProperties(
override var enabled: Boolean = true,
override var cron: String = "0 0 0/12 * * ?",
) : StatJobProperties()
var deletedEmptyFolder: Boolean = false,
) : StatJobProperties()
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class PypiLocalRepository(
val pypiPackagePojo = try {
artifactInfo.getArtifactFullPath().toPypiPackagePojo()
} catch (e: Exception) {
logger.error("parse pypi package failed", e)
logger.info("parse path[${artifactInfo.getArtifactFullPath()}] to pypi package version failed: ", e)
null
} ?: return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ open class NodeRestoreSupport(
override fun getDeletedNodeDetail(artifact: ArtifactInfo): List<NodeDetail> {
with(artifact) {
val query = nodeDeletedPointListQuery(projectId, repoName, getArtifactFullPath())
return nodeDao.find(query).map { convertToDetail(it)!! }
val deletedNode = nodeDao.findOne(query)
return if (deletedNode == null) {
emptyList()
} else {
listOf(convertToDetail(deletedNode)!!)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</template>
<bk-table-column :label="$t('status')" width="100">
<template #default="{ row }">
<div class="status-sign" :class="row.status" :data-name="row.status === 'HEALTHY' ? $t('normal') : $t('normal')"></div>
<div class="status-sign" :class="row.status" :data-name="row.status === 'HEALTHY' ? $t('normal') : $t('abnormal')"></div>
</template>
</bk-table-column>
<bk-table-column :label="$t('nodeName')" prop="name" width="250" show-overflow-tooltip></bk-table-column>
Expand Down

0 comments on commit ff6c348

Please sign in to comment.