Skip to content

Commit

Permalink
feat: added policy title and creator
Browse files Browse the repository at this point in the history
- user email can be fetched from frontier jwt using
email claim with the use of custom email header to identify
the user

Signed-off-by: Kush Sharma <thekushsharma@gmail.com>
  • Loading branch information
kushsharma committed Nov 14, 2023
1 parent bcbbde8 commit 426cbbb
Show file tree
Hide file tree
Showing 20 changed files with 4,357 additions and 2,408 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
- name: Login to DockerHub
uses: docker/login-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.20"
go-version: "1.21"
- name: Login to DockerHub
uses: docker/login-action@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: "1.20"
go-version: "1.21"
- uses: actions/checkout@v2
with:
fetch-depth: 0
Expand All @@ -20,7 +20,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ COMMIT := $(shell git rev-parse --short HEAD)
TAG := "$(shell git rev-list --tags --max-count=1)"
VERSION := "$(shell git describe --tags ${TAG})-next"
BUILD_DIR=dist
PROTON_COMMIT := "17305c2660e06ff9c82c1b6130799a703e4e543b"
PROTON_COMMIT := "0568961fb6571a7a9889d5f16eb896e371e39b8e"

.PHONY: all build clean test tidy vet proto setup format generate

Expand Down Expand Up @@ -75,7 +75,7 @@ proto: ## Generate the protobuf files
setup: ## Install all the dependencies
@echo "Installing dependencies..."
go mod tidy
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0
go install github.com/golang/protobuf/proto@v1.5.2
go install github.com/golang/protobuf/protoc-gen-go@v1.5.2
go install google.golang.org/grpc@v1.40.0
Expand Down
6 changes: 5 additions & 1 deletion api/handler/v1beta1/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,14 @@ func (a *adapter) ToRole(role *domain.Role) (*guardianv1beta1.Role, error) {
return roleProto, nil
}

func (a *adapter) FromPolicyProto(p *guardianv1beta1.Policy) *domain.Policy {
func (a *adapter) FromPolicyProto(p *guardianv1beta1.Policy, createdBy string) *domain.Policy {
policy := &domain.Policy{
ID: p.GetId(),
Title: p.GetTitle(),
Version: uint(p.GetVersion()),
Description: p.GetDescription(),
Labels: p.GetLabels(),
CreatedBy: createdBy,
}

if p.GetSteps() != nil {
Expand Down Expand Up @@ -352,8 +354,10 @@ func (a *adapter) ToPolicyProto(p *domain.Policy) (*guardianv1beta1.Policy, erro
policyProto := &guardianv1beta1.Policy{
Id: p.ID,
Version: uint32(p.Version),
Title: p.Title,
Description: p.Description,
Labels: p.Labels,
CreatedBy: p.CreatedBy,
}

if p.Steps != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/handler/v1beta1/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ProtoAdapter interface {
ToProviderTypeProto(domain.ProviderType) *guardianv1beta1.ProviderType
ToRole(*domain.Role) (*guardianv1beta1.Role, error)

FromPolicyProto(*guardianv1beta1.Policy) *domain.Policy
FromPolicyProto(*guardianv1beta1.Policy, string) *domain.Policy
ToPolicyProto(*domain.Policy) (*guardianv1beta1.Policy, error)

ToPolicyAppealConfigProto(policy *domain.Policy) *guardianv1beta1.PolicyAppealConfig
Expand Down
13 changes: 11 additions & 2 deletions api/handler/v1beta1/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ func (s *GRPCServer) CreatePolicy(ctx context.Context, req *guardianv1beta1.Crea
ctx = policy.WithDryRun(ctx)
}

p := s.adapter.FromPolicyProto(req.GetPolicy())
authenticatedUser, err := s.getUser(ctx)
if err != nil {
return nil, status.Error(codes.Unauthenticated, err.Error())
}

p := s.adapter.FromPolicyProto(req.GetPolicy(), authenticatedUser)

if err := s.policyService.Create(ctx, p); err != nil {
return nil, status.Errorf(codes.Internal, "failed to create policy: %v", err)
Expand All @@ -76,7 +81,11 @@ func (s *GRPCServer) UpdatePolicy(ctx context.Context, req *guardianv1beta1.Upda
if req.GetDryRun() {
ctx = policy.WithDryRun(ctx)
}
p := s.adapter.FromPolicyProto(req.GetPolicy())
authenticatedUser, err := s.getUser(ctx)
if err != nil {
return nil, status.Error(codes.Unauthenticated, err.Error())
}
p := s.adapter.FromPolicyProto(req.GetPolicy(), authenticatedUser)

p.ID = req.GetId()
if err := s.policyService.Update(ctx, p); err != nil {
Expand Down
3,528 changes: 2,077 additions & 1,451 deletions api/proto/raystack/guardian/v1beta1/guardian.pb.go

Large diffs are not rendered by default.

996 changes: 416 additions & 580 deletions api/proto/raystack/guardian/v1beta1/guardian.pb.gw.go

Large diffs are not rendered by default.

Loading

0 comments on commit 426cbbb

Please sign in to comment.