Skip to content

Commit

Permalink
DUPLO-13529 add AdminGetInfrastructure api
Browse files Browse the repository at this point in the history
  • Loading branch information
duplodavid committed Dec 19, 2023
1 parent 9cc2b8d commit 8980fe4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/duplo-aws-credential-process/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func main() {
// Otherwise, get the credentials from Duplo.
if creds == nil {
client := mustDuploClient(*host, *token, *interactive, true)
result, err := client.AdminGetJITAwsCredentials()
result, err := client.AdminGetJitAwsCredentials()
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertAwsCreds(result)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func main() {
}

// Tenant: Get the JIT AWS credentials
result, err := client.TenantGetJITAwsCredentials(*tenantID)
result, err := client.TenantGetJitAwsCredentials(*tenantID)
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertAwsCreds(result)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/duplo-jit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func main() {
// Otherwise, get the credentials from Duplo.
if creds == nil {
client, _ := internal.MustDuploClient(*host, *token, *interactive, true)
result, err := client.AdminGetJITAwsCredentials()
result, err := client.AdminGetJitAwsCredentials()
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertAwsCreds(result)
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func main() {
// Otherwise, get the credentials from Duplo.
if creds == nil {
// Tenant: Get the JIT AWS credentials
result, err := client.TenantGetJITAwsCredentials(*tenantID)
result, err := client.TenantGetJitAwsCredentials(*tenantID)
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertAwsCreds(result)
}
Expand Down
29 changes: 26 additions & 3 deletions duplocloud/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ type DuploSystemFeatures struct {
TenantNameMaxLength int `json:"TenantNameMaxLength"`
}

// DuploInfrastructureConfig represents an infrastructure configuration
type DuploInfrastructure struct {
Name string `json:"Name,omitempty"`
Region string `json:"Region,omitempty"`
EnableK8Cluster bool `json:"EnableK8Cluster,omitempty"`
EnableECSCluster bool `json:"EnableECSCluster,omitempty"`
EnableContainerInsights bool `json:"EnableContainerInsights,omitempty"`
ProvisioningStatus string `json:"ProvisioningStatus,omitempty"`
}

// DuploPlanK8ClusterConfig represents a k8s system configuration
type DuploPlanK8ClusterConfig struct {
Name string `json:"Name,omitempty"`
Expand Down Expand Up @@ -94,15 +104,15 @@ func (c *Client) AdminGetK8sJitAccess(plan string) (*DuploPlanK8ClusterConfig, C
}

// AdminGetJITAwsCredentials retrieves just-in-time admin AWS credentials via the Duplo API.
func (c *Client) AdminGetJITAwsCredentials() (*AwsJitCredentials, ClientError) {
func (c *Client) AdminGetJitAwsCredentials() (*AwsJitCredentials, ClientError) {
return c.AdminAwsGetJitAccess("admin")
}

// TenantGetJITAwsCredentials retrieves just-in-time AWS credentials for a tenant via the Duplo API.
func (c *Client) TenantGetJITAwsCredentials(tenantID string) (*AwsJitCredentials, ClientError) {
func (c *Client) TenantGetJitAwsCredentials(tenantID string) (*AwsJitCredentials, ClientError) {
creds := AwsJitCredentials{}
err := c.getAPI(
fmt.Sprintf("TenantGetAwsCredentials(%s)", tenantID),
fmt.Sprintf("TenantGetJitAwsCredentials(%s)", tenantID),
fmt.Sprintf("subscriptions/%s/GetAwsConsoleTokenUrl", tenantID),
&creds,
)
Expand Down Expand Up @@ -136,6 +146,19 @@ func (c *Client) ListTenantsForUser() (*[]UserTenant, ClientError) {
return &list, nil
}

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

// GetTenantByNameForUser retrieves a single tenant by name for the current user via the Duplo API.
func (c *Client) GetTenantByNameForUser(name string) (*UserTenant, ClientError) {
// Get all tenants.
Expand Down

0 comments on commit 8980fe4

Please sign in to comment.