Skip to content

Commit

Permalink
KV Proposal.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Jan 18, 2024
1 parent e2cb744 commit 836f0b0
Show file tree
Hide file tree
Showing 49 changed files with 2,091 additions and 7,037 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,3 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: ./cloud/azure/all.coverprofile
flags: azure # optional


# Run integration tests
test-integration:
runs-on: ubuntu-latest
env:
GOPATH: /home/runner/go
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.21.6
- name: Setup Golang caches
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-
- name: Run Integration Tests
run: make test-integration
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ lint: $(all)
$(MAKE) lint -C $$dir || exit 1; \
done

test-integration:
@echo Running integration tests
@cd ./e2e && make

test: $(all)
for dir in $(all); do \
$(MAKE) test -C $$dir || exit 1; \
Expand Down
4 changes: 2 additions & 2 deletions cloud/aws/deploy/collection/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type DynamodbCollection struct {
}

type DynamodbCollectionArgs struct {
StackID string
Collection *v1.Collection
StackID string
KeyValueStore *v1.KeyValueStore
}

func NewDynamodbCollection(ctx *pulumi.Context, name string, args *DynamodbCollectionArgs, opts ...pulumi.ResourceOption) (*DynamodbCollection, error) {
Expand Down
68 changes: 68 additions & 0 deletions cloud/aws/deploy/keyvalue/dynamodb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright Nitric Pty Ltd.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package keyvalue

import (
"github.com/nitrictech/nitric/cloud/common/deploy/resources"
"github.com/nitrictech/nitric/cloud/common/deploy/tags"
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"
)

type DynamodbKeyValueStore struct {
pulumi.ResourceState

Table *dynamodb.Table
Name string
}

type DynamodbKeyValueStoreArgs struct {
StackID string
KeyValueStore *v1.KeyValueStore
}

func NewDynamodbKeyValueStore(ctx *pulumi.Context, name string, args *DynamodbKeyValueStoreArgs, opts ...pulumi.ResourceOption) (*DynamodbKeyValueStore, error) {
res := &DynamodbKeyValueStore{Name: name}

err := ctx.RegisterComponentResource("nitric:keyvalue:Dynamodb", name, res, opts...)
if err != nil {
return nil, err
}

res.Table, err = dynamodb.NewTable(ctx, name, &dynamodb.TableArgs{
Attributes: dynamodb.TableAttributeArray{
&dynamodb.TableAttributeArgs{
Name: pulumi.String("_pk"),
Type: pulumi.String("S"),
},
&dynamodb.TableAttributeArgs{
Name: pulumi.String("_sk"),
Type: pulumi.String("S"),
},
},
HashKey: pulumi.String("_pk"),
RangeKey: pulumi.String("_sk"),
BillingMode: pulumi.String("PAY_PER_REQUEST"),
Tags: pulumi.ToStringMap(tags.Tags(args.StackID, name, resources.Collection)),
})
if err != nil {
return nil, err
}

return res, nil
}
34 changes: 11 additions & 23 deletions cloud/aws/deploy/policy/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"

"github.com/nitrictech/nitric/cloud/aws/deploy/bucket"
"github.com/nitrictech/nitric/cloud/aws/deploy/collection"
"github.com/nitrictech/nitric/cloud/aws/deploy/keyvalue"
"github.com/nitrictech/nitric/cloud/aws/deploy/secret"
"github.com/nitrictech/nitric/cloud/aws/deploy/topic"
"github.com/nitrictech/nitric/cloud/aws/deploy/websocket"
Expand All @@ -49,11 +49,11 @@ type Policy struct {
}

type StackResources struct {
Topics map[string]*topic.SNSTopic
Buckets map[string]*bucket.S3Bucket
Collections map[string]*collection.DynamodbCollection
Secrets map[string]*secret.SecretsManagerSecret
Websockets map[string]*websocket.AwsWebsocketApiGateway
Topics map[string]*topic.SNSTopic
Buckets map[string]*bucket.S3Bucket
KeyValueStores map[string]*keyvalue.DynamodbKeyValueStore
Secrets map[string]*secret.SecretsManagerSecret
Websockets map[string]*websocket.AwsWebsocketApiGateway
}

type PrincipalMap = map[v1.ResourceType]map[string]*iam.Role
Expand All @@ -79,10 +79,6 @@ var awsActionsMap map[v1.Action][]string = map[v1.Action][]string{
v1.Action_BucketFileDelete: {
"s3:DeleteObject",
},
// XXX: Cannot be applied to single resources
// v1.Action_TopicList: {
// "sns:ListTopics",
// },
v1.Action_TopicDetail: {
"sns:GetTopicAttributes",
},
Expand All @@ -91,25 +87,17 @@ var awsActionsMap map[v1.Action][]string = map[v1.Action][]string{
"states:StartExecution",
"states:StateSyncExecution",
},
v1.Action_CollectionDocumentRead: {
v1.Action_KeyValueStoreRead: {
"dynamodb:GetItem",
"dynamodb:BatchGetItem",
},
v1.Action_CollectionDocumentWrite: {
v1.Action_KeyValueStoreWrite: {
"dynamodb:UpdateItem",
"dynamodb:PutItem",
},
v1.Action_CollectionDocumentDelete: {
v1.Action_KeyValueStoreDelete: {
"dynamodb:DeleteItem",
},
v1.Action_CollectionQuery: {
"dynamodb:Query",
"dynamodb:Scan",
},
// XXX: Cannot be applied to single resources
// v1.Action_CollectionList: {
// "dynamodb:ListTables",
// },
v1.Action_SecretAccess: {
"secretsmanager:GetSecretValue",
},
Expand Down Expand Up @@ -142,8 +130,8 @@ 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_Collection:
if c, ok := resources.Collections[resource.Name]; ok {
case v1.ResourceType_KeyValueStore:
if c, ok := resources.KeyValueStores[resource.Name]; ok {
return []interface{}{c.Table.Arn}, nil
}
case v1.ResourceType_Secret:
Expand Down
24 changes: 12 additions & 12 deletions cloud/aws/deploy/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/nitrictech/nitric/cloud/aws/deploy/api"
"github.com/nitrictech/nitric/cloud/aws/deploy/bucket"
"github.com/nitrictech/nitric/cloud/aws/deploy/collection"
"github.com/nitrictech/nitric/cloud/aws/deploy/config"
"github.com/nitrictech/nitric/cloud/aws/deploy/exec"
"github.com/nitrictech/nitric/cloud/aws/deploy/keyvalue"
"github.com/nitrictech/nitric/cloud/aws/deploy/policy"
"github.com/nitrictech/nitric/cloud/aws/deploy/schedule"
"github.com/nitrictech/nitric/cloud/aws/deploy/secret"
Expand Down Expand Up @@ -110,14 +110,14 @@ func NewUpProgram(ctx context.Context, details *commonDeploy.CommonStackDetails,
}
}

// Deploy all collections
collections := map[string]*collection.DynamodbCollection{}
// Deploy all keyvalueStores
keyvalueStores := map[string]*keyvalue.DynamodbKeyValueStore{}
for _, res := range spec.Resources {
switch c := res.Config.(type) {
case *deploy.Resource_Collection:
collections[res.Name], err = collection.NewDynamodbCollection(ctx, res.Name, &collection.DynamodbCollectionArgs{
StackID: stackID,
Collection: c.Collection,
case *deploy.Resource_KeyValueStore:
keyvalueStores[res.Name], err = keyvalue.NewDynamodbKeyValueStore(ctx, res.Name, &keyvalue.DynamodbKeyValueStoreArgs{
StackID: stackID,
KeyValueStore: c.KeyValueStore,
})
if err != nil {
return err
Expand Down Expand Up @@ -360,11 +360,11 @@ func NewUpProgram(ctx context.Context, details *commonDeploy.CommonStackDetails,
_, err = policy.NewIAMPolicy(ctx, res.Name, &policy.PolicyArgs{
Policy: t.Policy,
Resources: &policy.StackResources{
Buckets: buckets,
Topics: topics,
Collections: collections,
Secrets: secrets,
Websockets: websockets,
Buckets: buckets,
Topics: topics,
KeyValueStores: keyvalueStores,
Secrets: secrets,
Websockets: websockets,
},
Principals: principals,
})
Expand Down
4 changes: 2 additions & 2 deletions cloud/aws/runtime/cmd/membrane.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"os/signal"
"syscall"

dynamodb_service "github.com/nitrictech/nitric/cloud/aws/runtime/documents"
"github.com/nitrictech/nitric/cloud/aws/runtime/env"
lambda_service "github.com/nitrictech/nitric/cloud/aws/runtime/gateway"
dynamodb_service "github.com/nitrictech/nitric/cloud/aws/runtime/keyvalue"
"github.com/nitrictech/nitric/cloud/aws/runtime/resource"
secrets_manager_secret_service "github.com/nitrictech/nitric/cloud/aws/runtime/secret"
s3_service "github.com/nitrictech/nitric/cloud/aws/runtime/storage"
Expand Down Expand Up @@ -56,7 +56,7 @@ func main() {
}

membraneOpts.SecretManagerPlugin, _ = secrets_manager_secret_service.New(provider)
membraneOpts.DocumentPlugin, _ = dynamodb_service.New(provider)
membraneOpts.KeyValuePlugin, _ = dynamodb_service.New(provider)
membraneOpts.TopicsPlugin, _ = sns_service.New(provider)
membraneOpts.StoragePlugin, _ = s3_service.New(provider)
membraneOpts.ResourcesPlugin = provider
Expand Down
Loading

0 comments on commit 836f0b0

Please sign in to comment.