All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tencent.devops.common.client.ClientTokenService.kt Maven / Gradle / Ivy

There is a newer version: 3.1.0-rc.4
Show newest version
package com.tencent.devops.common.client

import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.common.service.BkTag
import org.springframework.beans.factory.annotation.Value

class ClientTokenService constructor(
    val redisOperation: RedisOperation,
    val bkTag: BkTag
) {
    @Value("\${auth.token:#{null}}")
    private val systemToken: String? = ""

    fun getSystemToken(appCode: String?): String? {
        return redisOperation.get(getTokenRedisKey(appCode ?: DEFAULT_APP))
    }

    fun setSystemToken(appCode: String?) {
        redisOperation.set(getTokenRedisKey(appCode ?: DEFAULT_APP), systemToken!!)
    }

    fun checkToken(appCode: String?, token: String): Boolean {
        val systemToken = getSystemToken(appCode)
        return systemToken == token
    }

    private fun getTokenRedisKey(appCode: String): String {
        return "BK:AUTH:TOKEN:${bkTag.getLocalTag()}:$appCode:"
    }

    companion object {
        const val DEFAULT_APP = "ci"
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy