Skip to content

Commit

Permalink
Merge pull request #16 from smallstep/herman/policy
Browse files Browse the repository at this point in the history
Policy
  • Loading branch information
hslatman authored Apr 11, 2022
2 parents 0b29d9f + 810e61a commit c478deb
Show file tree
Hide file tree
Showing 11 changed files with 1,422 additions and 593 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
all: generate

generate:
protoc --proto_path=. --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative provisioners.proto admin.proto config.proto eab.proto majordomo.proto
protoc --proto_path=. --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative provisioners.proto admin.proto config.proto eab.proto majordomo.proto policy.proto

.PHONY: all generate
652 changes: 333 additions & 319 deletions config.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ option go_package = "go.step.sm/linkedca";

import "admin.proto";
import "provisioners.proto";
import "policy.proto";
import "google/protobuf/struct.proto";

// Configuration is the proto representation of a ca.json. Root keys and SSH
Expand Down Expand Up @@ -69,6 +70,7 @@ message Authority {
bool disable_issued_at_check = 12;
string backdate = 13;
string deployment_type = 14;
linkedca.Policy policy = 15;
}

message DistinguishedName {
Expand Down
13 changes: 13 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
_ contextKeyType = iota
adminContextKey
provisionerContextKey
externalAccountKeyContextKey
)

// NewContextWithAdmin returns a copy of ctx which carries an Admin.
Expand All @@ -33,3 +34,15 @@ func NewContextWithProvisioner(ctx context.Context, provisioner *Provisioner) co
func ProvisionerFromContext(ctx context.Context) *Provisioner {
return ctx.Value(provisionerContextKey).(*Provisioner)
}

// NewContextWithExternalAccountKey returns a copy of ctx which carries an EABKey.
func NewContextWithExternalAccountKey(ctx context.Context, k *EABKey) context.Context {
return context.WithValue(ctx, externalAccountKeyContextKey, k)
}

// ExternalAccountKeyFromContext returns the EABKey ctx carries.
//
// ExternalAccountKeyFromContext panics in case ctx carries no EABKey.
func ExternalAccountKeyFromContext(ctx context.Context) *EABKey {
return ctx.Value(externalAccountKeyContextKey).(*EABKey)
}
15 changes: 15 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ func TestProvisionerFromContextPanics(t *testing.T) {

assert.Panics(t, func() { ProvisionerFromContext(context.Background()) })
}

func TestExternalAccountKeyFromContext(t *testing.T) {
t.Parallel()

exp := new(EABKey)

got := ExternalAccountKeyFromContext(NewContextWithExternalAccountKey(context.Background(), exp))
assert.Same(t, exp, got)
}

func TestExternalAccountKeyFromContextPanics(t *testing.T) {
t.Parallel()

assert.Panics(t, func() { ExternalAccountKeyFromContext(context.Background()) })
}
62 changes: 38 additions & 24 deletions eab.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions eab.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package eab;
option go_package = "go.step.sm/linkedca";

import "google/protobuf/timestamp.proto";
import "policy.proto";

message EABKey {
string id = 1; // the KeyID
Expand All @@ -14,4 +15,5 @@ message EABKey {
string account = 5; // account the key is bound to
google.protobuf.Timestamp created_at = 6; // time the key was created_at
google.protobuf.Timestamp bound_at = 7; // time the key was bound to an account
linkedca.Policy policy = 8;
}
Loading

0 comments on commit c478deb

Please sign in to comment.