Skip to content

Commit

Permalink
DUPLO-13529 call non-admin API GetTenantFeatures to validate
Browse files Browse the repository at this point in the history
  • Loading branch information
duplodavid committed Dec 20, 2023
1 parent 8980fe4 commit 5d3463f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
28 changes: 25 additions & 3 deletions duplocloud/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ type DuploInfrastructure struct {
ProvisioningStatus string `json:"ProvisioningStatus,omitempty"`
}

// DuploTenantFeatures represents configured features for the tenant
type DuploTenantFeatures struct {
Region string `json:"Region,omitempty"`
IsKubernetesEnabled bool `json:"IsKubernetesEnabled"`
UseLbIndex bool `json:"UseLbIndex"`
}

// DuploPlanK8ClusterConfig represents a k8s system configuration
type DuploPlanK8ClusterConfig struct {
Name string `json:"Name,omitempty"`
Expand Down Expand Up @@ -147,16 +154,31 @@ func (c *Client) ListTenantsForUser() (*[]UserTenant, ClientError) {
}

func (c *Client) AdminGetInfrastructure(infraName string) (*DuploInfrastructure, ClientError) {
config := DuploInfrastructure{}
infra := DuploInfrastructure{}
err := c.getAPI(
fmt.Sprintf("AdminGetInfrastructure(%s)", infraName),
fmt.Sprintf("v3/admin/infrastructure/%s", infraName),
&config,
&infra,
)
if err != nil {
return nil, err
}

return &infra, nil
}

func (c *Client) GetTenantFeatures(tenantId string) (*DuploTenantFeatures, ClientError) {
features := DuploTenantFeatures{}
err := c.getAPI(
fmt.Sprintf("GetTenantFeatures(%s)", tenantId),
fmt.Sprintf("v3/features/tenant/%s", tenantId),
&features,
)
if err != nil {
return nil, err
}
return &config, nil

return &features, nil
}

// GetTenantByNameForUser retrieves a single tenant by name for the current user via the Duplo API.
Expand Down
11 changes: 8 additions & 3 deletions internal/duplo.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ func PingDuploCreds(creds *DuploCredsOutput, host string) error {
return err
}

_, cerr := client.AdminGetInfrastructure("default")
if cerr != nil && cerr.Status() != 404 {
return cerr
tenant, terr := client.GetTenantByNameForUser("default")
if terr != nil {
return err
}

_, ferr := client.GetTenantFeatures(tenant.TenantID)
if ferr != nil {
return ferr
}

return nil
Expand Down

0 comments on commit 5d3463f

Please sign in to comment.