Skip to content

Commit

Permalink
feat: v1-rc1
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Holm <[email protected]>
Co-authored-by: Jye Cusch <[email protected]>
Co-authored-by: Ryan Cartwright 
<[email protected]>
Co-authored-by: David Moore <[email protected]>
  • Loading branch information
4 people committed Jan 10, 2024
1 parent 4c00476 commit 0626eaf
Show file tree
Hide file tree
Showing 290 changed files with 17,142 additions and 45,340 deletions.
8 changes: 6 additions & 2 deletions cloud/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ test-coverage: generate-mocks
@echo Running unit tests
@go run github.com/onsi/ginkgo/ginkgo -cover -outputdir=./ -coverprofile=all.coverprofile ./runtime/...

generate-mocks:

clean-mocks:
@rm -rf ./mocks

generate-mocks: clean-mocks
@echo Generating Mock Clients
@mkdir -p mocks/secrets_manager
@mkdir -p mocks/s3
Expand All @@ -76,6 +80,6 @@ generate-mocks:
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/ifaces/secretsmanageriface SecretsManagerAPI > mocks/secrets_manager/mock.go
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/ifaces/s3iface S3API,PreSignAPI > mocks/s3/mock.go
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/ifaces/sqsiface SQSAPI > mocks/sqs/mock.go
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/runtime/core AwsProvider > mocks/provider/aws.go
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/runtime/resource AwsResourceProvider > mocks/provider/aws.go

generate-sources: generate-mocks
22 changes: 10 additions & 12 deletions cloud/aws/deploy/bucket/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ import (
"fmt"

"github.com/nitrictech/nitric/cloud/aws/deploy/exec"
deploy "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
v1 "github.com/nitrictech/nitric/core/pkg/api/nitric/v1"
deploypb "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
storagepb "github.com/nitrictech/nitric/core/pkg/proto/storage/v1"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lambda"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/s3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/samber/lo"
)

func eventTypeToStorageEventType(eventType *v1.BucketNotificationType) []string {
func eventTypeToStorageEventType(eventType *storagepb.BlobEventType) []string {
switch *eventType {
case v1.BucketNotificationType_All:
return []string{"s3:ObjectCreated:*", "s3:ObjectRemoved:*"}
case v1.BucketNotificationType_Created:
case storagepb.BlobEventType_Created:
return []string{"s3:ObjectCreated:*"}
case v1.BucketNotificationType_Deleted:
case storagepb.BlobEventType_Deleted:
return []string{"s3:ObjectRemoved:*"}
default:
return []string{}
Expand All @@ -51,7 +49,7 @@ type S3NotificationArgs struct {
StackID string

Bucket *S3Bucket
Notification []*deploy.BucketNotificationTarget
Notification []*deploypb.BucketNotificationTarget
Functions map[string]*exec.LambdaExecUnit
}

Expand Down Expand Up @@ -90,17 +88,17 @@ func NewS3Notification(ctx *pulumi.Context, name string, args *S3NotificationArg
invokePerms[funcName] = perm
}

if notification.Config.NotificationPrefixFilter == "*" {
notification.Config.NotificationPrefixFilter = ""
if notification.Config.KeyPrefixFilter == "*" {
notification.Config.KeyPrefixFilter = ""
}

// Append notification
bucketNotifications = append(bucketNotifications, s3.BucketNotificationLambdaFunctionArgs{
LambdaFunctionArn: unit.Function.Arn,
Events: pulumi.ToStringArray(
eventTypeToStorageEventType(&notification.Config.NotificationType),
eventTypeToStorageEventType(&notification.Config.BlobEventType),
),
FilterPrefix: pulumi.String(notification.Config.NotificationPrefixFilter),
FilterPrefix: pulumi.String(notification.Config.KeyPrefixFilter),
}.ToBucketNotificationLambdaFunctionOutput())
}

Expand Down
2 changes: 1 addition & 1 deletion cloud/aws/deploy/bucket/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package bucket
import (
"github.com/nitrictech/nitric/cloud/common/deploy/resources"
common "github.com/nitrictech/nitric/cloud/common/deploy/tags"
v1 "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
v1 "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
"github.com/pkg/errors"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/s3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
Expand Down
2 changes: 1 addition & 1 deletion cloud/aws/deploy/collection/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package collection
import (
"github.com/nitrictech/nitric/cloud/common/deploy/resources"
"github.com/nitrictech/nitric/cloud/common/deploy/tags"
v1 "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
v1 "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/dynamodb"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
Expand Down
11 changes: 9 additions & 2 deletions cloud/aws/deploy/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ import (
"github.com/nitrictech/nitric/cloud/common/deploy/output/interactive"
"github.com/nitrictech/nitric/cloud/common/deploy/output/noninteractive"
pulumiutils "github.com/nitrictech/nitric/cloud/common/deploy/pulumi"
deploy "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
deploy "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
deploymentspb "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/auto/events"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (d *DeployServer) Down(request *deploy.DeployDownRequest, stream deploy.DeployService_DownServer) error {
func (d *DeployServer) Down(request *deploy.DeployDownRequest, stream deploy.Deploy_DownServer) error {
details, err := commonDeploy.CommonStackDetailsFromAttributes(request.Attributes.AsMap())
if err != nil {
return status.Errorf(codes.InvalidArgument, err.Error())
Expand Down Expand Up @@ -77,5 +78,11 @@ func (d *DeployServer) Down(request *deploy.DeployDownRequest, stream deploy.Dep
return err
}

stream.Send(&deploymentspb.DeployDownEvent{
Content: &deploymentspb.DeployDownEvent_Result{
Result: &deploymentspb.DeployDownEventResult{},
},
})

return nil
}
2 changes: 1 addition & 1 deletion cloud/aws/deploy/exec/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/nitrictech/nitric/cloud/aws/deploy/config"
"github.com/nitrictech/nitric/cloud/common/deploy/image"
common "github.com/nitrictech/nitric/cloud/common/deploy/tags"
v1 "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
v1 "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
)

type LambdaExecUnitArgs struct {
Expand Down
26 changes: 2 additions & 24 deletions cloud/aws/deploy/policy/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ import (

"github.com/nitrictech/nitric/cloud/aws/deploy/bucket"
"github.com/nitrictech/nitric/cloud/aws/deploy/collection"
"github.com/nitrictech/nitric/cloud/aws/deploy/queue"
"github.com/nitrictech/nitric/cloud/aws/deploy/secret"
"github.com/nitrictech/nitric/cloud/aws/deploy/topic"
"github.com/nitrictech/nitric/cloud/aws/deploy/websocket"
deploy "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
v1 "github.com/nitrictech/nitric/core/pkg/api/nitric/v1"
deploy "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
v1 "github.com/nitrictech/nitric/core/pkg/proto/resources/v1"
)

func md5Hash(b []byte) string {
Expand All @@ -51,7 +50,6 @@ type Policy struct {

type StackResources struct {
Topics map[string]*topic.SNSTopic
Queues map[string]*queue.SQSQueue
Buckets map[string]*bucket.S3Bucket
Collections map[string]*collection.DynamodbCollection
Secrets map[string]*secret.SecretsManagerSecret
Expand Down Expand Up @@ -93,22 +91,6 @@ var awsActionsMap map[v1.Action][]string = map[v1.Action][]string{
"states:StartExecution",
"states:StateSyncExecution",
},
v1.Action_QueueSend: {
"sqs:SendMessage",
},
v1.Action_QueueReceive: {
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
},
// XXX: Cannot be applied to single resources
// v1.Action_QueueList: {
// "sqs:ListQueues",
// },
v1.Action_QueueDetail: {
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
"sqs:ListQueueTags",
},
v1.Action_CollectionDocumentRead: {
"dynamodb:GetItem",
"dynamodb:BatchGetItem",
Expand Down Expand Up @@ -160,10 +142,6 @@ func arnForResource(resource *deploy.Resource, resources *StackResources) ([]int
if t, ok := resources.Topics[resource.Name]; ok {
return []interface{}{t.Sns.Arn, t.Sfn.Arn}, nil
}
case v1.ResourceType_Queue:
if q, ok := resources.Queues[resource.Name]; ok {
return []interface{}{q.Sqs.Arn}, nil
}
case v1.ResourceType_Collection:
if c, ok := resources.Collections[resource.Name]; ok {
return []interface{}{c.Table.Arn}, nil
Expand Down
22 changes: 2 additions & 20 deletions cloud/aws/deploy/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/nitrictech/nitric/cloud/aws/deploy/config"
"github.com/nitrictech/nitric/cloud/aws/deploy/exec"
"github.com/nitrictech/nitric/cloud/aws/deploy/policy"
"github.com/nitrictech/nitric/cloud/aws/deploy/queue"
"github.com/nitrictech/nitric/cloud/aws/deploy/schedule"
"github.com/nitrictech/nitric/cloud/aws/deploy/secret"
"github.com/nitrictech/nitric/cloud/aws/deploy/stack"
Expand All @@ -42,8 +41,8 @@ import (
"github.com/nitrictech/nitric/cloud/common/deploy/resources"
common "github.com/nitrictech/nitric/cloud/common/deploy/tags"
"github.com/nitrictech/nitric/cloud/common/deploy/telemetry"
deploy "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
v1 "github.com/nitrictech/nitric/core/pkg/api/nitric/v1"
deploy "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
v1 "github.com/nitrictech/nitric/core/pkg/proto/resources/v1"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecr"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/iam"
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
Expand Down Expand Up @@ -126,22 +125,6 @@ func NewUpProgram(ctx context.Context, details *commonDeploy.CommonStackDetails,
}
}

// Deploy all queues
queues := map[string]*queue.SQSQueue{}
for _, res := range spec.Resources {
switch q := res.Config.(type) {
case *deploy.Resource_Queue:
queues[res.Name], err = queue.NewSQSQueue(ctx, res.Name, &queue.SQSQueueArgs{
// TODO: Calculate stack ID
StackID: stackID,
Queue: q.Queue,
})
if err != nil {
return err
}
}
}

authToken, err := ecr.GetAuthorizationToken(ctx, &ecr.GetAuthorizationTokenArgs{})
if err != nil {
return err
Expand Down Expand Up @@ -379,7 +362,6 @@ func NewUpProgram(ctx context.Context, details *commonDeploy.CommonStackDetails,
Resources: &policy.StackResources{
Buckets: buckets,
Topics: topics,
Queues: queues,
Collections: collections,
Secrets: secrets,
Websockets: websockets,
Expand Down
56 changes: 0 additions & 56 deletions cloud/aws/deploy/queue/sqs.go

This file was deleted.

2 changes: 1 addition & 1 deletion cloud/aws/deploy/secret/secretsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
"github.com/nitrictech/nitric/cloud/common/deploy/resources"
common "github.com/nitrictech/nitric/cloud/common/deploy/tags"
v1 "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
v1 "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/secretsmanager"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
Expand Down
4 changes: 2 additions & 2 deletions cloud/aws/deploy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package deploy
import (
_ "embed"

deploy "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
deploy "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
)

type DeployServer struct {
deploy.UnimplementedDeployServiceServer
deploy.UnimplementedDeployServer
}

// Embeds the runtime directly into the deploytime binary
Expand Down
2 changes: 1 addition & 1 deletion cloud/aws/deploy/topic/sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

"github.com/nitrictech/nitric/cloud/aws/deploy/exec"
common "github.com/nitrictech/nitric/cloud/common/deploy/tags"
v1 "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
v1 "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
)

type SNSTopic struct {
Expand Down
4 changes: 2 additions & 2 deletions cloud/aws/deploy/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/nitrictech/nitric/cloud/common/deploy/output/interactive"
"github.com/nitrictech/nitric/cloud/common/deploy/output/noninteractive"
pulumiutils "github.com/nitrictech/nitric/cloud/common/deploy/pulumi"
deploy "github.com/nitrictech/nitric/core/pkg/api/nitric/deploy/v1"
deploy "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/auto/events"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optup"
Expand All @@ -36,7 +36,7 @@ import (
)

// Up - Deploy requested infrastructure for a stack
func (d *DeployServer) Up(request *deploy.DeployUpRequest, stream deploy.DeployService_UpServer) (err error) {
func (d *DeployServer) Up(request *deploy.DeployUpRequest, stream deploy.Deploy_UpServer) (err error) {
defer func() {
if r := recover(); r != nil {
stack := string(debug.Stack())
Expand Down
Loading

0 comments on commit 0626eaf

Please sign in to comment.