-
Notifications
You must be signed in to change notification settings - Fork 0
/
privateimagehubs_handler.go
65 lines (55 loc) · 2.07 KB
/
privateimagehubs_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package privateimagehubs
import (
"github.com/equinor/radix-api/api/privateimagehubs/models"
"github.com/equinor/radix-api/api/utils"
sharedModels "github.com/equinor/radix-api/models"
)
// PrivateImageHubHandler Instance variables
type PrivateImageHubHandler struct {
userAccount sharedModels.Account
serviceAccount sharedModels.Account
}
// Init Constructor
func Init(accounts sharedModels.Accounts) PrivateImageHubHandler {
return PrivateImageHubHandler{
userAccount: accounts.UserAccount,
serviceAccount: accounts.ServiceAccount}
}
// GetPrivateImageHubs returns all private image hubs defined for app
func (ph PrivateImageHubHandler) GetPrivateImageHubs(appName string) ([]models.ImageHubSecret, error) {
var imageHubSecrets []models.ImageHubSecret
application, err := utils.CreateApplicationConfig(ph.userAccount.Client, ph.userAccount.RadixClient, ph.userAccount.SecretProviderClient, appName)
if err != nil {
return []models.ImageHubSecret{}, nil
}
pendingImageHubSecrets, err := application.GetPendingPrivateImageHubSecrets()
if err != nil {
return nil, err
}
radixApp := application.GetRadixApplicationConfig()
for server, config := range radixApp.Spec.PrivateImageHubs {
imageHubSecrets = append(imageHubSecrets, models.ImageHubSecret{
Server: server,
Username: config.Username,
Email: config.Email,
Status: getImageHubSecretStatus(pendingImageHubSecrets, server),
})
}
return imageHubSecrets, nil
}
// UpdatePrivateImageHubValue updates the private image hub value with new password
func (ph PrivateImageHubHandler) UpdatePrivateImageHubValue(appName, server, password string) error {
application, err := utils.CreateApplicationConfig(ph.userAccount.Client, ph.userAccount.RadixClient, ph.userAccount.SecretProviderClient, appName)
if err != nil {
return err
}
return application.UpdatePrivateImageHubsSecretsPassword(server, password)
}
func getImageHubSecretStatus(pendingImageHubSecrets []string, server string) string {
for _, val := range pendingImageHubSecrets {
if val == server {
return "Pending"
}
}
return "Consistent"
}