github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/api/migrate/argocd/v1beta1tov1beta2.go (about) 1 package argocd 2 3 import ( 4 "github.com/caos/orbos/internal/operator/boom/api/latest/reconciling" 5 "github.com/caos/orbos/internal/operator/boom/api/latest/reconciling/auth" 6 "github.com/caos/orbos/internal/operator/boom/api/latest/reconciling/auth/github" 7 "github.com/caos/orbos/internal/operator/boom/api/latest/reconciling/auth/gitlab" 8 "github.com/caos/orbos/internal/operator/boom/api/latest/reconciling/auth/google" 9 "github.com/caos/orbos/internal/operator/boom/api/latest/reconciling/auth/oidc" 10 "github.com/caos/orbos/internal/operator/boom/api/latest/reconciling/repository" 11 "github.com/caos/orbos/internal/operator/boom/api/migrate/network" 12 "github.com/caos/orbos/internal/operator/boom/api/v1beta1/argocd" 13 ) 14 15 func V1beta1Tov1beta2(old *argocd.Argocd) *reconciling.Reconciling { 16 new := &reconciling.Reconciling{ 17 Deploy: old.Deploy, 18 NodeSelector: old.NodeSelector, 19 } 20 if old.Network != nil { 21 new.Network = network.V1beta1Tov1beta2(old.Network) 22 } 23 if old.Rbac != nil { 24 new.Rbac = &reconciling.Rbac{ 25 Csv: old.Rbac.Csv, 26 Default: old.Rbac.Default, 27 } 28 if old.Rbac.Scopes != nil { 29 scopes := make([]string, 0) 30 for _, v := range old.Rbac.Scopes { 31 scopes = append(scopes, v) 32 } 33 new.Rbac.Scopes = scopes 34 } 35 } 36 if old.CustomImage != nil { 37 new.CustomImage = &reconciling.CustomImage{ 38 Enabled: old.CustomImage.Enabled, 39 } 40 if old.CustomImage.GopassStores != nil { 41 stores := make([]*reconciling.GopassStore, 0) 42 for _, v := range old.CustomImage.GopassStores { 43 stores = append(stores, &reconciling.GopassStore{ 44 SSHKey: v.SSHKey, 45 ExistingSSHKeySecret: v.ExistingSSHKeySecret, 46 GPGKey: v.GPGKey, 47 ExistingGPGKeySecret: v.ExistingGPGKeySecret, 48 Directory: v.Directory, 49 StoreName: v.StoreName, 50 }) 51 } 52 new.CustomImage.GopassStores = stores 53 } 54 } 55 if old.Repositories != nil { 56 repos := make([]*repository.Repository, 0) 57 for _, v := range old.Repositories { 58 repos = append(repos, &repository.Repository{ 59 Name: v.Name, 60 URL: v.URL, 61 Username: v.Username, 62 ExistingUsernameSecret: v.ExistingUsernameSecret, 63 Password: v.Password, 64 ExistingPasswordSecret: v.ExistingPasswordSecret, 65 Certificate: v.Certificate, 66 ExistingCertificateSecret: v.ExistingCertificateSecret, 67 }) 68 } 69 new.Repositories = repos 70 } 71 if old.Credentials != nil { 72 creds := make([]*repository.Repository, 0) 73 for _, v := range old.Credentials { 74 creds = append(creds, &repository.Repository{ 75 Name: v.Name, 76 URL: v.URL, 77 Username: v.Username, 78 ExistingUsernameSecret: v.ExistingUsernameSecret, 79 Password: v.Password, 80 ExistingPasswordSecret: v.ExistingPasswordSecret, 81 Certificate: v.Certificate, 82 ExistingCertificateSecret: v.ExistingCertificateSecret, 83 }) 84 } 85 new.Credentials = creds 86 } 87 if old.KnownHosts != nil { 88 hosts := make([]string, 0) 89 for _, v := range old.KnownHosts { 90 hosts = append(hosts, v) 91 } 92 new.KnownHosts = hosts 93 } 94 95 if old.Auth != nil { 96 oldAuth := old.Auth 97 newAuth := auth.Auth{} 98 if oldAuth.GoogleConnector != nil { 99 conn := &google.Connector{ 100 ID: oldAuth.GoogleConnector.ID, 101 Name: oldAuth.GoogleConnector.Name, 102 } 103 if oldAuth.GoogleConnector.Config != nil { 104 oldConf := oldAuth.GoogleConnector.Config 105 newConf := &google.Config{ 106 ClientID: oldConf.ClientID, 107 ExistingClientIDSecret: oldConf.ExistingClientIDSecret, 108 ClientSecret: oldConf.ClientSecret, 109 ExistingClientSecretSecret: oldConf.ExistingClientSecretSecret, 110 ServiceAccountJSON: oldConf.ServiceAccountJSON, 111 ExistingServiceAccountJSONSecret: oldConf.ExistingServiceAccountJSONSecret, 112 ServiceAccountFilePath: oldConf.ServiceAccountFilePath, 113 AdminEmail: oldConf.AdminEmail, 114 } 115 if oldConf.HostedDomains != nil { 116 domains := make([]string, 0) 117 for _, v := range oldConf.HostedDomains { 118 domains = append(domains, v) 119 } 120 oldConf.HostedDomains = domains 121 } 122 if oldConf.Groups != nil { 123 groups := make([]string, 0) 124 for _, v := range oldConf.Groups { 125 groups = append(groups, v) 126 } 127 newConf.Groups = groups 128 } 129 conn.Config = newConf 130 } 131 newAuth.GoogleConnector = conn 132 } 133 if oldAuth.GithubConnector != nil { 134 conn := &github.Connector{ 135 ID: oldAuth.GithubConnector.ID, 136 Name: oldAuth.GithubConnector.Name, 137 } 138 if oldAuth.GithubConnector.Config != nil { 139 oldConf := oldAuth.GithubConnector.Config 140 newConf := &github.Config{ 141 ClientID: oldConf.ClientID, 142 ExistingClientIDSecret: oldConf.ExistingClientIDSecret, 143 ClientSecret: oldConf.ClientSecret, 144 ExistingClientSecretSecret: oldConf.ExistingClientSecretSecret, 145 LoadAllGroups: oldConf.LoadAllGroups, 146 TeamNameField: oldConf.TeamNameField, 147 UseLoginAsID: oldConf.UseLoginAsID, 148 } 149 if oldConf.Orgs != nil { 150 orgs := make([]*github.Org, 0) 151 for _, v := range oldConf.Orgs { 152 org := &github.Org{ 153 Name: v.Name, 154 Teams: nil, 155 } 156 if v.Teams != nil { 157 ts := make([]string, 0) 158 for _, t := range v.Teams { 159 ts = append(ts, t) 160 } 161 } 162 orgs = append(orgs, org) 163 } 164 newConf.Orgs = orgs 165 } 166 conn.Config = newConf 167 } 168 newAuth.GithubConnector = conn 169 } 170 171 if oldAuth.GitlabConnector != nil { 172 conn := &gitlab.Connector{ 173 ID: oldAuth.GitlabConnector.ID, 174 Name: oldAuth.GitlabConnector.Name, 175 } 176 if oldAuth.GitlabConnector.Config != nil { 177 oldConf := oldAuth.GitlabConnector.Config 178 newConf := &gitlab.Config{ 179 ClientID: oldConf.ClientID, 180 ExistingClientIDSecret: oldConf.ExistingClientIDSecret, 181 ClientSecret: oldConf.ClientSecret, 182 ExistingClientSecretSecret: oldConf.ExistingClientSecretSecret, 183 UseLoginAsID: oldConf.UseLoginAsID, 184 BaseURL: oldConf.BaseURL, 185 } 186 if oldConf.Groups != nil { 187 groups := make([]string, 0) 188 for _, v := range oldConf.Groups { 189 groups = append(groups, v) 190 } 191 newConf.Groups = groups 192 } 193 conn.Config = newConf 194 } 195 newAuth.GitlabConnector = conn 196 } 197 if oldAuth.OIDC != nil { 198 conn := &oidc.OIDC{ 199 Name: oldAuth.OIDC.Name, 200 Issuer: oldAuth.OIDC.Issuer, 201 ClientID: oldAuth.OIDC.ClientID, 202 ExistingClientIDSecret: oldAuth.OIDC.ExistingClientIDSecret, 203 ClientSecret: oldAuth.OIDC.ClientSecret, 204 ExistingClientSecretSecret: oldAuth.OIDC.ExistingClientSecretSecret, 205 RequestedIDTokenClaims: nil, 206 } 207 if oldAuth.OIDC.RequestedScopes != nil { 208 scopes := make([]string, 0) 209 for _, v := range oldAuth.OIDC.RequestedScopes { 210 scopes = append(scopes, v) 211 } 212 conn.RequestedScopes = scopes 213 } 214 if oldAuth.OIDC.RequestedIDTokenClaims != nil { 215 claims := make(map[string]oidc.Claim, 0) 216 for k, v := range oldAuth.OIDC.RequestedIDTokenClaims { 217 claim := oidc.Claim{ 218 Essential: v.Essential, 219 } 220 if v.Values != nil { 221 values := make([]string, 0) 222 for _, value := range v.Values { 223 values = append(values, value) 224 } 225 claim.Values = values 226 } 227 claims[k] = claim 228 } 229 conn.RequestedIDTokenClaims = claims 230 } 231 newAuth.OIDC = conn 232 } 233 new.Auth = &newAuth 234 } 235 236 return new 237 }