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

feat: servicedata #71

Merged
merged 25 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c3e2ad
feat: user service data to serve metadata
ishanarya0 Jun 11, 2024
12cde75
fix: should not return error if user email is missing
ishanarya0 Jun 11, 2024
0b50f68
Merge branch 'main' into servicedata-for-metadata
ishanarya0 Jun 11, 2024
01b2c34
chore: remove unwanted imports
ishanarya0 Jun 11, 2024
8c67023
feat: get group metadata from servicedata
ishanarya0 Jun 11, 2024
9c0db8b
feat: update APIs to use servicedata (#74)
ishanarya0 Jun 18, 2024
354e510
Merge branch 'main' into servicedata-for-metadata
ishanarya0 Jun 18, 2024
3e8af74
fix: field name
ishanarya0 Jun 18, 2024
455e4c7
lint: format
ishanarya0 Jun 18, 2024
6e0bdb8
fix: check permission on keys before create/update
ishanarya0 Jun 19, 2024
b9bc243
lint: formatting
ishanarya0 Jun 19, 2024
3215c13
fix: check permission on keys before create/update
ishanarya0 Jun 19, 2024
ce3fca3
refactor: change field name
ishanarya0 Jun 21, 2024
c09e507
fix: add consistency to lookup resource
ishanarya0 Jun 24, 2024
78426bf
feat: make servicedata key public (#86)
ishanarya0 Jul 10, 2024
03c372b
Merge branch 'main' into servicedata-for-metadata
ishanarya0 Jul 10, 2024
ed2baea
test: fix
ishanarya0 Jul 10, 2024
4d9f17e
test: fix
ishanarya0 Jul 10, 2024
1c30d4b
test: fix
ishanarya0 Jul 10, 2024
8d51441
test: fix wrong response
ishanarya0 Jul 10, 2024
7f4f8b2
fix: self API
ishanarya0 Jul 11, 2024
6cddb8d
test
ishanarya0 Jul 18, 2024
7316920
test
ishanarya0 Jul 18, 2024
45b9046
test: update create group test
ishanarya0 Jul 18, 2024
9b70dd8
test: update update group test
ishanarya0 Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GOVERSION := $(shell go version | cut -d ' ' -f 3 | cut -d '.' -f 2)

.PHONY: build check fmt lint test test-race vet test-cover-html help install proto
.DEFAULT_GOAL := build
PROTON_COMMIT := "e8a584e192f23f999844b027d17bd738c3981973"
PROTON_COMMIT := "6ee59f2d0cbeedf1d5fe48adee5e5e41f54f081e"

install:
@echo "Clean up imports..."
Expand Down
4 changes: 3 additions & 1 deletion core/group/filter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package group

type Filter struct {
OrganizationID string
OrganizationID string
ProjectID string
ServicedataKeyResourceIDs []string
}
7 changes: 4 additions & 3 deletions core/servicedata/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/goto/shield/core/user"
"github.com/goto/shield/internal/schema"
"github.com/goto/shield/pkg/db"
"github.com/goto/shield/pkg/errors"
)

const (
Expand Down Expand Up @@ -75,7 +76,7 @@ func NewService(logger log.Logger, repository Repository, resourceService Resour

func (s Service) CreateKey(ctx context.Context, key Key) (Key, error) {
// check if key contains ':'
if key.Key == "" {
if key.Name == "" {
return Key{}, ErrInvalidDetail
}

Expand Down Expand Up @@ -160,7 +161,7 @@ func (s Service) CreateKey(ctx context.Context, key Key) (Key, error) {
}

func (s Service) Upsert(ctx context.Context, sd ServiceData) (ServiceData, error) {
if sd.Key.Key == "" {
if sd.Key.Name == "" {
return ServiceData{}, ErrInvalidDetail
}

Expand Down Expand Up @@ -188,7 +189,7 @@ func (s Service) Upsert(ctx context.Context, sd ServiceData) (ServiceData, error
return ServiceData{}, err
}
if !permission {
return ServiceData{}, user.ErrInvalidEmail
return ServiceData{}, errors.ErrForbidden
}

returnedServiceData, err := s.repository.Upsert(ctx, sd)
Expand Down
18 changes: 10 additions & 8 deletions core/servicedata/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"github.com/goto/shield/core/servicedata/mocks"
"github.com/goto/shield/core/user"
"github.com/goto/shield/internal/schema"
errorsPkg "github.com/goto/shield/pkg/errors"
"github.com/goto/shield/pkg/logger"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
Expand All @@ -30,21 +32,21 @@ var (
testProjectSlug = "test-project-slug"
testKey = servicedata.Key{
ProjectID: "test-project-slug",
Key: "test-key",
Name: "test-key",
Description: "test key no 01",
}
testCreateKey = servicedata.Key{
URN: "test-project-slug:servicedata_key:test-key",
ProjectID: testProjectID,
ProjectSlug: testProjectSlug,
Key: "test-key",
Name: "test-key",
Description: "test key no 01",
ResourceID: testResourceID,
}
testCreatedKey = servicedata.Key{
URN: "test-project-slug:servicedata_key:test-key",
ProjectID: testProjectID,
Key: "test-key",
Name: "test-key",
Description: "test key no 01",
ResourceID: testResourceID,
}
Expand Down Expand Up @@ -131,7 +133,7 @@ func TestService_CreateKey(t *testing.T) {
name: "CreateKeyEmpty",
key: servicedata.Key{
ProjectID: testKey.ProjectID,
Key: "",
Name: "",
Description: testKey.Description,
},
setup: func(t *testing.T) *servicedata.Service {
Expand Down Expand Up @@ -183,7 +185,7 @@ func TestService_CreateKey(t *testing.T) {
name: "CreateKeyInvalidProjectID",
key: servicedata.Key{
ProjectID: "invalid-test-project-slug",
Key: testKey.Key,
Name: testKey.Name,
Description: testKey.Description,
},
email: "[email protected]",
Expand Down Expand Up @@ -366,7 +368,7 @@ func TestService_Upsert(t *testing.T) {
name: "UpsertKeyEmpty",
data: servicedata.ServiceData{
Key: servicedata.Key{
Key: "",
Name: "",
},
},
setup: func(t *testing.T) *servicedata.Service {
Expand Down Expand Up @@ -402,7 +404,7 @@ func TestService_Upsert(t *testing.T) {
name: "UpsertInvalidProjectID",
data: servicedata.ServiceData{
Key: servicedata.Key{
Key: testKey.Key,
Name: testKey.Name,
ProjectID: "invalid-test-project-slug",
},
},
Expand Down Expand Up @@ -480,7 +482,7 @@ func TestService_Upsert(t *testing.T) {
testResourceID, action.Action{ID: "edit"}).Return(false, nil)
return servicedata.NewService(testLogger, repository, resourceService, relationService, projectService, userService, activityService)
},
wantErr: user.ErrInvalidEmail,
wantErr: errorsPkg.ErrForbidden,
},
{
name: "UpsertErr",
Expand Down
8 changes: 4 additions & 4 deletions core/servicedata/servicedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Key struct {
URN string
ProjectID string
ProjectSlug string
Key string
Name string
Description string
ResourceID string
}
Expand All @@ -36,7 +36,7 @@ type ServiceData struct {
NamespaceID string
EntityID string
Key Key
Value string
Value any
}

type KeyLogData struct {
Expand All @@ -56,15 +56,15 @@ type Filter struct {
}

func (key Key) CreateURN() string {
return fmt.Sprintf("%s:servicedata_key:%s", key.ProjectSlug, key.Key)
return fmt.Sprintf("%s:servicedata_key:%s", key.ProjectSlug, key.Name)
}

func (key Key) ToKeyLogData() KeyLogData {
return KeyLogData{
Entity: auditEntityServiceDataKey,
URN: key.URN,
ProjectSlug: key.ProjectSlug,
Key: key.Key,
Key: key.Name,
Description: key.Description,
}
}
8 changes: 5 additions & 3 deletions core/user/filter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package user

type Filter struct {
Limit int32
Page int32
Keyword string
Limit int32
Page int32
Keyword string
ProjectID string
ServiceDataKeyResourceIds []string
}
Loading
Loading