Skip to content

Commit

Permalink
chore: handle google cloud flows (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored Nov 18, 2024
1 parent 8a7ae32 commit cb0e181
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 36 deletions.
15 changes: 10 additions & 5 deletions api/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (cloud CloudProvider) GetHost(tenantID string) string {
}

type Config struct {
DefaultCloud string `json:"default_cloud" yaml:"default_cloud"`
DefaultCloud CloudProvider `json:"default_cloud" yaml:"default_cloud"`
Git *GitopsAPISpec `json:"git" yaml:"git"`
AWS *AWSConfig `json:"aws" yaml:"aws"`
Azure *AzureConfig `json:"azure" yaml:"azure"`
Expand All @@ -64,10 +64,7 @@ type AzureConfig struct {
}

type GCPConfig struct {
TenantID string `json:"tenant_id" yaml:"tenant_id"`
ClientID string `json:"client_id" yaml:"client_id"`
ClientSecret string `json:"client_secret" yaml:"client_secret"`
VaultURI string `json:"vault_uri" yaml:"vault_url"`
KMS string `json:"kms" yaml:"kms"`
TenantCluster string `json:"tenant_cluster" yaml:"tenant_cluster"`
TenantHostFormat string `json:"tenant_host_fmt" yaml:"tenant_host_fmt"`
}
Expand All @@ -77,3 +74,11 @@ type ClerkConfig struct {
JWKSURL string `json:"jwks_url" yaml:"jwks_url"`
WebhookSecret string `json:"webhook_secret" yaml:"webhook_secret"`
}

func (c Config) GetClusterName() string {
return c.DefaultCloud.GetClusterName()
}

func (c Config) GetHost(tenantID string) string {
return c.DefaultCloud.GetHost(tenantID)
}
8 changes: 8 additions & 0 deletions pkg/secrets/gcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package secrets

type GCPSealedSecret struct{}

func (s GCPSealedSecret) GenerateSealedSecret(params SealedSecretParams) ([]byte, error) {
// We setup SQLUser and database via CRDs
return nil, nil
}
34 changes: 3 additions & 31 deletions pkg/tenant/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ const (
)

func NewTenant(req v1.TenantRequestBody) (v1.Tenant, error) {
cloud := v1.CloudProvider(v1.GlobalConfig.DefaultCloud)

kPath, err := utils.Template(v1.GlobalConfig.Git.KustomizationPath, map[string]any{
"cluster": cloud.GetClusterName(),
"cluster": v1.GlobalConfig.GetClusterName(),
})
if err != nil {
return v1.Tenant{}, err
Expand All @@ -45,42 +43,16 @@ func NewTenant(req v1.TenantRequestBody) (v1.Tenant, error) {
ID: id,
Name: req.Data.Name,
OrgID: orgID,
Cloud: cloud,
Cloud: v1.GlobalConfig.DefaultCloud,
Slug: slug,
KustomizationPath: kPath,
ContentPath: path.Join(path.Dir(kPath), id),
Host: cloud.GetHost(id),
Host: v1.GlobalConfig.GetHost(id),
DBUsername: strings.ToLower(orgID),
DBPassword: utils.RandomString(16),
}, nil
}

func getClusterName(cloud v1.CloudProvider) string {
// TODO: Take this from config
switch cloud {
case v1.Azure:
return v1.GlobalConfig.Azure.TenantCluster
case v1.AWS:
return v1.GlobalConfig.AWS.TenantCluster
case v1.GCP:
return v1.GlobalConfig.GCP.TenantCluster
}
return ""
}

func getHost(cloud v1.CloudProvider, tenantID string) string {
switch cloud {
case v1.Azure:
return fmt.Sprintf(v1.GlobalConfig.Azure.TenantHostFormat, tenantID)
case v1.AWS:
return fmt.Sprintf(v1.GlobalConfig.AWS.TenantHostFormat, tenantID)
case v1.GCP:
return fmt.Sprintf(v1.GlobalConfig.GCP.TenantHostFormat, tenantID)
default:
return ""
}
}

func updateParamsOnClerk(tenant v1.Tenant) error {
client, err := clerk.NewClient(v1.GlobalConfig.Clerk.SecretKey)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/tenant/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func GetSecretControllerFromCloud(cloud v1.CloudProvider) secrets.Secrets {
switch cloud {
case v1.Azure:
return &secrets.AzureSealedSecret{}
case v1.GCP:
return &secrets.GCPSealedSecret{}
}
return nil
}

0 comments on commit cb0e181

Please sign in to comment.