Skip to content

Commit 4925e41

Browse files
HomelessDinosaurtjholm
authored andcommitted
feat: Add secret collection to codeconfig
1 parent 1fd5d71 commit 4925e41

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/moby/buildkit v0.9.3 // indirect
2626
github.com/moby/moby v20.10.12+incompatible
2727
github.com/nitrictech/boxygen v0.0.1-rc.7.0.20211212231606-62c668408f91
28-
github.com/nitrictech/nitric v0.13.0-rc.17
28+
github.com/nitrictech/nitric v0.14.0-rc.4
2929
github.com/pkg/errors v0.9.1
3030
github.com/pterm/pterm v0.12.34
3131
github.com/pulumi/pulumi-aws/sdk/v4 v4.33.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,8 @@ github.com/nishanths/predeclared v0.2.1 h1:1TXtjmy4f3YCFjTxRd8zcFHOmoUir+gp0ESzj
12871287
github.com/nishanths/predeclared v0.2.1/go.mod h1:HvkGJcA3naj4lOwnFXFDkFxVtSqQMB9sbB1usJ+xjQE=
12881288
github.com/nitrictech/boxygen v0.0.1-rc.7.0.20211212231606-62c668408f91 h1:gtZZJc7l5pML1eRsqyXe0U7NdQxSa7u/cbyEvnGLBpc=
12891289
github.com/nitrictech/boxygen v0.0.1-rc.7.0.20211212231606-62c668408f91/go.mod h1:2XXi1xEwqitH4/gus1bHyG/IQe8WOniK+pybGTz2y/Y=
1290-
github.com/nitrictech/nitric v0.13.0-rc.17 h1:Pv6aGNP/+kHNVt87QfT06bqpbKIy2s3SYcqYXDIRKE4=
1291-
github.com/nitrictech/nitric v0.13.0-rc.17/go.mod h1:XC6DG1/NrMc59Jzq/1h6SLn6L4foSS67pCqyTpauT3o=
1290+
github.com/nitrictech/nitric v0.14.0-rc.4 h1:x3Ng7TTUSqj/ulKRnEdwHDz9gax5+Hrq1rsoBJ6j/9s=
1291+
github.com/nitrictech/nitric v0.14.0-rc.4/go.mod h1:XC6DG1/NrMc59Jzq/1h6SLn6L4foSS67pCqyTpauT3o=
12921292
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
12931293
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
12941294
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=

pkg/codeconfig/codeconfig.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ func (c *codeConfig) ToStack() (*stack.Stack, error) {
372372
for k := range f.queues {
373373
s.Queues[k] = stack.Queue{}
374374
}
375+
for k := range f.secrets {
376+
s.Secrets[k] = stack.Secret{}
377+
}
375378

376379
// Add policies
377380
s.Policies = append(s.Policies, f.policies...)

pkg/codeconfig/function.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type FunctionDependencies struct {
9090
collections map[string]*pb.CollectionResource
9191
queues map[string]*pb.QueueResource
9292
policies []*pb.PolicyResource
93+
secrets map[string]*pb.SecretResource
9394
lock sync.RWMutex
9495
}
9596

@@ -174,6 +175,12 @@ func (a *FunctionDependencies) AddQueue(name string, q *pb.QueueResource) {
174175
a.queues[name] = q
175176
}
176177

178+
func (a *FunctionDependencies) AddSecret(name string, s *pb.SecretResource) {
179+
a.lock.Lock()
180+
defer a.lock.Unlock()
181+
a.secrets[name] = s
182+
}
183+
177184
// NewFunction - creates a new Nitric Function, ready to register handlers and dependencies.
178185
func NewFunction(name string) *FunctionDependencies {
179186
return &FunctionDependencies{
@@ -185,6 +192,7 @@ func NewFunction(name string) *FunctionDependencies {
185192
topics: make(map[string]*pb.TopicResource),
186193
collections: make(map[string]*pb.CollectionResource),
187194
queues: make(map[string]*pb.QueueResource),
195+
secrets: make(map[string]*pb.SecretResource),
188196
policies: make([]*pb.PolicyResource, 0),
189197
}
190198
}

pkg/codeconfig/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func (s *Server) Declare(ctx context.Context, req *pb.ResourceDeclareRequest) (*
7979
s.function.AddTopic(req.Resource.Name, req.GetTopic())
8080
case pb.ResourceType_Policy:
8181
s.function.AddPolicy(req.GetPolicy())
82+
case pb.ResourceType_Secret:
83+
s.function.AddSecret(req.Resource.Name, req.GetSecret())
8284
}
8385

8486
return &pb.ResourceDeclareResponse{}, nil

pkg/stack/types.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ type Topic struct{}
9797

9898
type Queue struct{}
9999

100+
type Secret struct{}
101+
100102
type Stack struct {
101103
Dir string `yaml:"-"`
102104
Name string `yaml:"name"`
@@ -115,6 +117,7 @@ type Stack struct {
115117
// repetition/redefinition
116118
// NOTE: if we want to use the proto definition here we would need support for yaml parsing to use customisable tags
117119
Policies []*v1.PolicyResource `yaml:"-"`
120+
Secrets map[string]Secret `yaml:"secrets,omitempty"`
118121
}
119122

120123
func New(name, dir string) *Stack {
@@ -131,6 +134,7 @@ func New(name, dir string) *Stack {
131134
Apis: map[string]string{},
132135
ApiDocs: map[string]*openapi3.T{},
133136
Policies: make([]*v1.PolicyResource, 0),
137+
Secrets: map[string]Secret{},
134138
}
135139
}
136140

@@ -223,6 +227,23 @@ func calculateDefaultPolicies(s *Stack) []*v1.PolicyResource {
223227
Resources: collectionResources,
224228
})
225229

230+
secretResources := make([]*v1.Resource, 0, len(s.Secrets))
231+
for name := range s.Secrets {
232+
secretResources = append(secretResources, &v1.Resource{
233+
Name: name,
234+
Type: v1.ResourceType_Secret,
235+
})
236+
}
237+
238+
policies = append(policies, &v1.PolicyResource{
239+
Principals: principals,
240+
Actions: []v1.Action{
241+
v1.Action_SecretAccess,
242+
v1.Action_SecretPut,
243+
},
244+
Resources: secretResources,
245+
})
246+
226247
// TODO: Calculate policies for stacks loaded from a file
227248
return policies
228249
}

0 commit comments

Comments
 (0)