Skip to content

Commit

Permalink
fix: Add descriptions to aws api gateways. (#672)
Browse files Browse the repository at this point in the history
* fix: Add descriptions to aws api gateways.

* add azure and gcp description config

---------

Co-authored-by: Ryan Cartwright <[email protected]>
  • Loading branch information
tjholm and HomelessDinosaur authored Sep 6, 2024
1 parent 0f8b656 commit 005bf9b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cloud/aws/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/nitrictech/nitric/cloud/common/deploy/config"
)

type ApiConfig struct {
type AwsApiConfig struct {
Domains []string
}

Expand All @@ -35,7 +35,7 @@ type AwsConfig struct {
ScheduleTimezone string `mapstructure:"schedule-timezone,omitempty"`
Import AwsImports
Refresh bool
Apis map[string]*ApiConfig
Apis map[string]*AwsApiConfig
config.AbstractConfig[*AwsConfigItem] `mapstructure:"config,squash"`
}

Expand Down Expand Up @@ -87,7 +87,7 @@ func ConfigFromAttributes(attributes map[string]interface{}) (*AwsConfig, error)
}

if awsConfig.Apis == nil {
awsConfig.Apis = map[string]*ApiConfig{}
awsConfig.Apis = map[string]*AwsApiConfig{}
}

if awsConfig.Config == nil {
Expand Down
16 changes: 14 additions & 2 deletions cloud/aws/deploy/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc

nameArnPairs := make([]interface{}, 0, len(a.Lambdas))

additionalApiConfig := a.AwsConfig.Apis[name]

if config.GetOpenapi() == "" {
return fmt.Errorf("aws provider can only deploy OpenAPI specs")
}
Expand Down Expand Up @@ -133,6 +135,15 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
}))
}

// get description
description := fmt.Sprintf("Nitric API Gateway for %s", a.StackId)

if additionalApiConfig != nil && additionalApiConfig.Description != "" {
description = additionalApiConfig.Description
}

openapiDoc.Info.Description = description

apiGatewayTags := tags.Tags(a.StackId, name, resources.API)

doc := pulumi.All(nameArnPairs...).ApplyT(func(pairs []interface{}) (string, error) {
Expand Down Expand Up @@ -176,7 +187,8 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
}).(pulumi.StringOutput)

a.Apis[name], err = apigatewayv2.NewApi(ctx, name, &apigatewayv2.ApiArgs{
Body: doc,
Body: doc,
Description: pulumi.String(description),
// Name fixed to title in the spec, if these mismatch the name will change on the second deployment.
Name: pulumi.String(openapiDoc.Info.Title),
ProtocolType: pulumi.String("HTTP"),
Expand Down Expand Up @@ -214,7 +226,7 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
return ep
}).(pulumi.StringInput)

if a.AwsConfig.Apis[name] != nil {
if additionalApiConfig != nil {
// For each specified domain name
for _, domainName := range a.AwsConfig.Apis[name].Domains {
_, err := newDomainName(ctx, name, domainNameArgs{
Expand Down
3 changes: 2 additions & 1 deletion cloud/aws/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
)

type ApiConfig struct {
Domains []string
Description string
Domains []string
}

// AwsImports - Import configuration for AWS, maps nitric names of resources to the ARNs of existing AWS resources.
Expand Down
11 changes: 11 additions & 0 deletions cloud/azure/deploy/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func setSecurityRequirements(secReq *openapi3.SecurityRequirements, secDef map[s
func (p *NitricAzurePulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resource, name string, config *deploymentspb.Api) error {
opts := []pulumi.ResourceOption{pulumi.Parent(parent)}

additionalApiConfig := p.AzureConfig.Apis[name]

openapiDoc := &openapi3.T{}
err := openapiDoc.UnmarshalJSON([]byte(config.GetOpenapi()))
if err != nil {
Expand Down Expand Up @@ -116,12 +118,21 @@ func (p *NitricAzurePulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resou
displayName = openapiDoc.Info.Title
}

description := fmt.Sprintf("Nitric API Gateway for %s", p.StackId)

if additionalApiConfig != nil && additionalApiConfig.Description != "" {
description = additionalApiConfig.Description
}

openapiDoc.Info.Description = description

b, err := marshalOpenAPISpec(openapiDoc)
if err != nil {
return err
}

api, err := apimanagement.NewApi(ctx, ResourceName(ctx, name, ApiRT), &apimanagement.ApiArgs{
Description: pulumi.String(description),
DisplayName: pulumi.String(displayName),
Protocols: pulumi.StringArray{pulumi.String("https")},
ApiId: pulumi.String(name),
Expand Down
9 changes: 9 additions & 0 deletions cloud/azure/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ type AzureContainerAppsConfig struct {
MaxReplicas int `mapstructure:"max-replicas"`
}

type AzureApiConfig struct {
Description string
}

type AzureConfig struct {
Refresh bool
ResourceGroup string `mapstructure:"resource-group"`
Org string `mapstructure:"org"`
AdminEmail string `mapstructure:"adminemail"`
Apis map[string]*AzureApiConfig
config.AbstractConfig[*AzureConfigItem] `mapstructure:"config,squash"`
}

Expand Down Expand Up @@ -74,6 +79,10 @@ func ConfigFromAttributes(attributes map[string]interface{}) (*AzureConfig, erro
azureConfig.Org = "unknown"
}

if azureConfig.Apis == nil {
azureConfig.Apis = map[string]*AzureApiConfig{}
}

if azureConfig.Config == nil {
azureConfig.Config = map[string]*AzureConfigItem{}
}
Expand Down
9 changes: 9 additions & 0 deletions cloud/gcp/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ type GcpCloudRunConfig struct {
Concurrency int
}

type GcpApiConfig struct {
Description string
}

type GcpConfig struct {
config.AbstractConfig[*GcpConfigItem] `mapstructure:"config,squash"`
Apis map[string]*GcpApiConfig
Import GcpImports
ScheduleTimezone string `mapstructure:"schedule-timezone"`
ProjectId string `mapstructure:"gcp-project-id"`
Expand Down Expand Up @@ -79,6 +84,10 @@ func ConfigFromAttributes(attributes map[string]interface{}) (*GcpConfig, error)
gcpConfig.ScheduleTimezone = "UTC"
}

if gcpConfig.Apis == nil {
gcpConfig.Apis = map[string]*GcpApiConfig{}
}

if gcpConfig.Config == nil {
gcpConfig.Config = map[string]*GcpConfigItem{}
}
Expand Down
10 changes: 10 additions & 0 deletions cloud/gcp/deploy/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type nameUrlPair struct {
func (p *NitricGcpPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resource, name string, apiConfig *deploymentspb.Api) error {
opts := append([]pulumi.ResourceOption{}, pulumi.Parent(parent))

additionalApiConfig := p.GcpConfig.Apis[name]

if apiConfig.GetOpenapi() == "" {
return fmt.Errorf("gcp provider can only deploy OpenAPI specs")
}
Expand Down Expand Up @@ -148,6 +150,14 @@ func (p *NitricGcpPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
}))
}

description := fmt.Sprintf("Nitric API Gateway for %s", p.StackId)

if additionalApiConfig != nil && additionalApiConfig.Description != "" {
description = additionalApiConfig.Description
}

openapiDoc.Info.Description = description

// Now we need to create the document provided and interpolate the deployed service targets
// i.e. their Urls...
// Replace Nitric API Extensions with google api gateway extensions
Expand Down

0 comments on commit 005bf9b

Please sign in to comment.