diff --git a/duplocloud/api.go b/duplocloud/api.go index 63269c9..de25c9c 100644 --- a/duplocloud/api.go +++ b/duplocloud/api.go @@ -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"` @@ -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. diff --git a/internal/duplo.go b/internal/duplo.go index a54c852..e5eb124 100644 --- a/internal/duplo.go +++ b/internal/duplo.go @@ -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