mirror of https://github.com/portainer/portainer
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package registryutils
|
|
|
|
import (
|
|
portainer "github.com/portainer/portainer/api"
|
|
)
|
|
|
|
func isRegistryAssignedToNamespace(registry portainer.Registry, endpointID portainer.EndpointID, namespace string) (in bool){
|
|
for _, ns := range registry.RegistryAccesses[endpointID].Namespaces {
|
|
if ns == namespace {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func RefreshEcrSecret(cli portainer.KubeClient, endpoint *portainer.Endpoint, dataStore portainer.DataStore, namespace string) (err error) {
|
|
registries, err := dataStore.Registry().Registries()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for _, registry := range registries {
|
|
if registry.Type != portainer.EcrRegistry {
|
|
continue
|
|
}
|
|
|
|
if !isRegistryAssignedToNamespace(registry, endpoint.ID, namespace) {
|
|
continue
|
|
}
|
|
|
|
err = EnsureRegTokenValid(dataStore, ®istry)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = cli.DeleteRegistrySecret(®istry, namespace)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = cli.CreateRegistrySecret(®istry, namespace)
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|