Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal(v1): Documents -> KV #549

Merged
merged 13 commits into from
Jan 24, 2024
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/cmd/runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"syscall"

"github.com/nitrictech/nitric/cloud/aws/runtime/api"
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 @@ -58,7 +58,7 @@ func main() {

membraneOpts.ApiPlugin = api.NewAwsApiGatewayProvider(provider)
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
4 changes: 2 additions & 2 deletions cloud/aws/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ type NitricAwsPulumiProvider struct {
buckets map[string]*s3.Bucket
bucketNotifications map[string]*s3.BucketNotification
topics map[string]*topic
collections map[string]*dynamodb.Table
websockets map[string]*apigatewayv2.Api
keyValueStores map[string]*dynamodb.Table

provider.NitricDefaultOrder

Expand Down Expand Up @@ -179,8 +179,8 @@ func NewNitricAwsProvider() *NitricAwsPulumiProvider {
secrets: make(map[string]*secretsmanager.Secret),
buckets: make(map[string]*s3.Bucket),
bucketNotifications: make(map[string]*s3.BucketNotification),
collections: make(map[string]*dynamodb.Table),
websockets: make(map[string]*apigatewayv2.Api),
topics: make(map[string]*topic),
keyValueStores: make(map[string]*dynamodb.Table),
}
}
93 changes: 93 additions & 0 deletions cloud/aws/deploy/keyvalue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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 deploy

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

type DynamodbKeyValueStore struct {
pulumi.ResourceState

Table *dynamodb.Table
Name string
}

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

func (n *NitricAwsPulumiProvider) KeyValueStore(ctx *pulumi.Context, parent pulumi.Resource, name string, keyvalue *deploymentspb.KeyValueStore) error {
var err error
opts := []pulumi.ResourceOption{pulumi.Parent(parent)}

n.keyValueStores[name], 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(n.stackId, name, resources.Collection)),
}, opts...)

return err
}

// 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
// }
23 changes: 5 additions & 18 deletions cloud/aws/deploy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,17 @@ var awsActionsMap map[resourcespb.Action][]string = map[resourcespb.Action][]str
"states:StartExecution",
"states:StateSyncExecution",
},
resourcespb.Action_CollectionDocumentRead: {
resourcespb.Action_KeyValueStoreRead: {
"dynamodb:GetItem",
"dynamodb:BatchGetItem",
},
resourcespb.Action_CollectionDocumentWrite: {
resourcespb.Action_KeyValueStoreWrite: {
"dynamodb:UpdateItem",
"dynamodb:PutItem",
},
resourcespb.Action_CollectionDocumentDelete: {
resourcespb.Action_KeyValueStoreDelete: {
"dynamodb:DeleteItem",
},
resourcespb.Action_CollectionQuery: {
"dynamodb:Query",
"dynamodb:Scan",
},
// XXX: Cannot be applied to single resources
// v1.Action_CollectionList: {
// "dynamodb:ListTables",
Expand Down Expand Up @@ -113,8 +109,8 @@ func (a *NitricAwsPulumiProvider) arnForResource(resource *deploymentspb.Resourc
if t, ok := a.topics[resource.Id.Name]; ok {
return []interface{}{t.sns.Arn, t.sfn.Arn}, nil
}
case resourcespb.ResourceType_Collection:
if c, ok := a.collections[resource.Id.Name]; ok {
case resourcespb.ResourceType_KeyValueStore:
if c, ok := a.keyValueStores[resource.Id.Name]; ok {
return []interface{}{c.Arn}, nil
}
case resourcespb.ResourceType_Secret:
Expand Down Expand Up @@ -149,13 +145,6 @@ func (a *NitricAwsPulumiProvider) roleForPrincipal(resource *deploymentspb.Resou
func (a *NitricAwsPulumiProvider) Policy(ctx *pulumi.Context, parent pulumi.Resource, name string, config *deploymentspb.Policy) error {
opts := []pulumi.ResourceOption{pulumi.Parent(parent)}

// res := &Policy{Name: name, RolePolicies: make([]*iam.RolePolicy, 0)}

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

// Get Actions
actions := actionsToAwsActions(config.Actions)

Expand Down Expand Up @@ -231,8 +220,6 @@ func (a *NitricAwsPulumiProvider) Policy(ctx *pulumi.Context, parent pulumi.Reso
if err != nil {
return err
}

// res.RolePolicies = append(res.RolePolicies, rolePol)
}

return nil
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
Loading