2021-08-31 21:23:21 +00:00
|
|
|
package jwt
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GenerateTokenForKubeconfig generates a new JWT token for Kubeconfig
|
|
|
|
func (service *Service) GenerateTokenForKubeconfig(data *portainer.TokenData) (string, error) {
|
|
|
|
settings, err := service.dataStore.Settings().Settings()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
expiryDuration, err := time.ParseDuration(settings.KubeconfigExpiry)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
expiryAt := time.Now().Add(expiryDuration).Unix()
|
|
|
|
if expiryDuration == time.Duration(0) {
|
|
|
|
expiryAt = 0
|
|
|
|
}
|
|
|
|
|
2021-11-15 21:45:20 +00:00
|
|
|
return service.generateSignedToken(data, expiryAt, kubeConfigScope)
|
2021-08-31 21:23:21 +00:00
|
|
|
}
|