github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/api/v1beta2/funcs.go (about)

     1  package v1beta2
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/caos/orbos/internal/operator/boom/api/latest/monitoring"
     8  	"github.com/caos/orbos/internal/operator/boom/api/latest/reconciling"
     9  	"github.com/caos/orbos/pkg/secret"
    10  	"github.com/caos/orbos/pkg/tree"
    11  )
    12  
    13  func ParseToolset(desiredTree *tree.Tree) (*Toolset, error) {
    14  	desiredKind := &Toolset{}
    15  	if err := desiredTree.Original.Decode(desiredKind); err != nil {
    16  		return nil, fmt.Errorf("parsing desired state failed: %w", err)
    17  	}
    18  	desiredTree.Parsed = desiredKind
    19  
    20  	return desiredKind, nil
    21  }
    22  
    23  func GetSecretsMap(desiredKind *Toolset) map[string]*secret.Secret {
    24  	ret := make(map[string]*secret.Secret, 0)
    25  
    26  	if desiredKind.Spec.Monitoring == nil {
    27  		desiredKind.Spec.Monitoring = &monitoring.Monitoring{}
    28  	}
    29  	grafanaSpec := desiredKind.Spec.Monitoring
    30  	grafanaSpec.InitSecrets()
    31  
    32  	ret["grafana.admin.username"] = grafanaSpec.Admin.Username
    33  	ret["grafana.admin.password"] = grafanaSpec.Admin.Password
    34  	ret["grafana.sso.oauth.clientid"] = grafanaSpec.Auth.GenericOAuth.ClientID
    35  	ret["grafana.sso.oauth.clientsecret"] = grafanaSpec.Auth.GenericOAuth.ClientSecret
    36  	ret["grafana.sso.google.clientid"] = grafanaSpec.Auth.Google.ClientID
    37  	ret["grafana.sso.google.clientsecret"] = grafanaSpec.Auth.Google.ClientSecret
    38  	ret["grafana.sso.github.clientid"] = grafanaSpec.Auth.Github.ClientID
    39  	ret["grafana.sso.github.clientsecret"] = grafanaSpec.Auth.Github.ClientSecret
    40  	ret["grafana.sso.gitlab.clientid"] = grafanaSpec.Auth.Gitlab.ClientID
    41  	ret["grafana.sso.gitlab.clientsecret"] = grafanaSpec.Auth.Gitlab.ClientSecret
    42  
    43  	if desiredKind.Spec.Reconciling == nil {
    44  		desiredKind.Spec.Reconciling = &reconciling.Reconciling{}
    45  	}
    46  	argocdSpec := desiredKind.Spec.Reconciling
    47  	argocdSpec.InitSecrets()
    48  
    49  	ret["argocd.sso.google.clientid"] = argocdSpec.Auth.GoogleConnector.Config.ClientID
    50  	ret["argocd.sso.google.clientsecret"] = argocdSpec.Auth.GoogleConnector.Config.ClientSecret
    51  	ret["argocd.sso.google.serviceaccountjson"] = argocdSpec.Auth.GoogleConnector.Config.ServiceAccountJSON
    52  	ret["argocd.sso.gitlab.clientid"] = argocdSpec.Auth.GitlabConnector.Config.ClientID
    53  	ret["argocd.sso.gitlab.clientsecret"] = argocdSpec.Auth.GitlabConnector.Config.ClientSecret
    54  	ret["argocd.sso.github.clientid"] = argocdSpec.Auth.GithubConnector.Config.ClientID
    55  	ret["argocd.sso.github.clientsecret"] = argocdSpec.Auth.GithubConnector.Config.ClientSecret
    56  	ret["argocd.sso.oidc.clientid"] = argocdSpec.Auth.OIDC.ClientID
    57  	ret["argocd.sso.oidc.clientsecret"] = argocdSpec.Auth.OIDC.ClientSecret
    58  
    59  	if argocdSpec.Credentials != nil {
    60  		for _, value := range argocdSpec.Credentials {
    61  			base := strings.Join([]string{"argocd", "credential", value.Name}, ".")
    62  
    63  			key := strings.Join([]string{base, "username"}, ".")
    64  			if value.Username == nil {
    65  				value.Username = &secret.Secret{}
    66  			}
    67  			ret[key] = value.Username
    68  
    69  			key = strings.Join([]string{base, "password"}, ".")
    70  			if value.Password == nil {
    71  				value.Password = &secret.Secret{}
    72  			}
    73  			ret[key] = value.Password
    74  
    75  			key = strings.Join([]string{base, "certificate"}, ".")
    76  			if value.Certificate == nil {
    77  				value.Certificate = &secret.Secret{}
    78  			}
    79  			ret[key] = value.Certificate
    80  		}
    81  	}
    82  	if argocdSpec.Repositories != nil {
    83  		for _, value := range argocdSpec.Repositories {
    84  			base := strings.Join([]string{"argocd", "repository", value.Name}, ".")
    85  
    86  			key := strings.Join([]string{base, "username"}, ".")
    87  			if value.Username == nil {
    88  				value.Username = &secret.Secret{}
    89  			}
    90  			ret[key] = value.Username
    91  
    92  			key = strings.Join([]string{base, "password"}, ".")
    93  			if value.Password == nil {
    94  				value.Password = &secret.Secret{}
    95  			}
    96  			ret[key] = value.Password
    97  
    98  			key = strings.Join([]string{base, "certificate"}, ".")
    99  			if value.Certificate == nil {
   100  				value.Certificate = &secret.Secret{}
   101  			}
   102  			ret[key] = value.Certificate
   103  		}
   104  	}
   105  
   106  	if argocdSpec.CustomImage != nil && argocdSpec.CustomImage.GopassStores != nil {
   107  		for _, value := range argocdSpec.CustomImage.GopassStores {
   108  			base := strings.Join([]string{"argocd", "gopass", value.StoreName}, ".")
   109  
   110  			key := strings.Join([]string{base, "ssh"}, ".")
   111  			if value.SSHKey == nil {
   112  				value.SSHKey = &secret.Secret{}
   113  			}
   114  			ret[key] = value.SSHKey
   115  
   116  			key = strings.Join([]string{base, "gpg"}, ".")
   117  			if value.GPGKey == nil {
   118  				value.GPGKey = &secret.Secret{}
   119  			}
   120  			ret[key] = value.GPGKey
   121  		}
   122  	}
   123  
   124  	return ret
   125  }