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

Implement Harvester API handlers #154

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3fe0e0b
Implement Harvester API Get Relationships
maxlambrecht May 11, 2023
e80e810
Fix return value. Fix lint errors.
maxlambrecht May 11, 2023
00261eb
Reduce duplication in tests
maxlambrecht May 11, 2023
a845be4
Reduce duplication in tests
maxlambrecht May 11, 2023
c5e3791
Exclude tests files from sonar analysis
maxlambrecht May 11, 2023
4bdc356
Add blank line
maxlambrecht May 11, 2023
f1f3197
Add test for invalid consent status
maxlambrecht May 11, 2023
882f6d1
Remove redundant if
maxlambrecht May 11, 2023
7aa5f3c
Make consent status optional. Simplify test method. Add comment
maxlambrecht May 12, 2023
4be18fa
Add test for auth trust domain and parameter mismatch
maxlambrecht May 12, 2023
41ca921
Minor change
maxlambrecht May 12, 2023
8fdd7d0
Refactor handleErrorAndLog method
maxlambrecht May 12, 2023
291ae3f
Add Harvester API handler 'Post Bundle'
maxlambrecht May 12, 2023
f614a07
Add BundleSync handler
maxlambrecht May 14, 2023
c22145b
Fix lint error
maxlambrecht May 14, 2023
0707d54
Fix lint error
maxlambrecht May 14, 2023
a73bf60
Remove duplicated tests
maxlambrecht May 14, 2023
426037f
Add more test covering more consent status
maxlambrecht May 14, 2023
eba0cac
Make function more readable
maxlambrecht May 15, 2023
2cc301e
Change Consent 'denied' status to 'disable' status
maxlambrecht May 15, 2023
39b7935
Implement PathRelationship
maxlambrecht May 15, 2023
fa40827
Refactor trust domain from context
maxlambrecht May 15, 2023
7cc382d
Address PR comments
maxlambrecht May 15, 2023
fc34cf2
Address PR comments
maxlambrecht May 15, 2023
a004a68
Address PR comments
maxlambrecht May 16, 2023
7449160
Fix return error
maxlambrecht May 16, 2023
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
3 changes: 2 additions & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sonar.exclusions=**/*.gen.go, **/*.sql.go, pkg/server/datastore/datastore_test.go
sonar.exclusions=**/*.gen.go, **/*.sql.go
sonar.cpd.exclusions=**/*_test.go
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,13 @@ help:
### Code generation ####
.PHONY: generate-sqlc-server generete-spec

# Run sqlc to generate sql code
generate-sqlc-server: install-sqlc run-sqlc-server

run-sqlc-server:
$(sqlc_bin) generate --file $(server_sqlc_config_file)

# Run oapi-codegen to generate api code
generate-spec:
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v$(oapi_codegen_version)
cd ./pkg/common/api; $(GOPATH)/bin/oapi-codegen -config schemas.cfg.yaml schemas.yaml
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/api/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func RelationshipFromEntity(entity *entity.Relationship) *Relationship {
UpdatedAt: entity.UpdatedAt,
TrustDomainAId: entity.TrustDomainAID,
TrustDomainBId: entity.TrustDomainBID,
TrustDomainBConsent: entity.TrustDomainBConsent,
TrustDomainAConsent: entity.TrustDomainAConsent,
TrustDomainAConsent: ConsentStatus(entity.TrustDomainAConsent),
TrustDomainBConsent: ConsentStatus(entity.TrustDomainBConsent),
}
}
8 changes: 4 additions & 4 deletions pkg/common/api/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func TestRelationshipFromEntity(t *testing.T) {
UpdatedAt: time.Now(),
TrustDomainAID: uuid.New(),
TrustDomainBID: uuid.New(),
TrustDomainAConsent: true,
TrustDomainBConsent: false,
TrustDomainAConsent: entity.ConsentStatusPending,
TrustDomainBConsent: entity.ConsentStatusAccepted,
}

r := RelationshipFromEntity(&eRelationship)
Expand All @@ -118,7 +118,7 @@ func TestRelationshipFromEntity(t *testing.T) {
assert.Equal(t, eRelationship.UpdatedAt, r.UpdatedAt)
assert.Equal(t, eRelationship.TrustDomainAID, r.TrustDomainAId)
assert.Equal(t, eRelationship.TrustDomainBID, r.TrustDomainBId)
assert.Equal(t, eRelationship.TrustDomainAConsent, r.TrustDomainAConsent)
assert.Equal(t, eRelationship.TrustDomainBConsent, r.TrustDomainBConsent)
assert.Equal(t, string(eRelationship.TrustDomainAConsent), string(r.TrustDomainAConsent))
assert.Equal(t, string(eRelationship.TrustDomainBConsent), string(r.TrustDomainBConsent))
})
}
137 changes: 74 additions & 63 deletions pkg/common/api/schemas.gen.go

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

15 changes: 11 additions & 4 deletions pkg/common/api/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ components:
example: "trust.domain.com"
BundleDigest:
type: string
description: base64 encoded SHA-256 digest of the bundle
example: f0456d7aed088e791e4610c3c2ad63afe46e2e777988fdbc9270f15ec9711b42
TrustBundle:
$ref: '#/components/schemas/Certificate'
Expand Down Expand Up @@ -79,11 +80,11 @@ components:
trust_domain_b_id:
$ref: '#/components/schemas/UUID'
trust_domain_a_consent:
type: boolean
default: false
$ref: '#/components/schemas/ConsentStatus'
default: pending
trust_domain_b_consent:
type: boolean
default: false
$ref: '#/components/schemas/ConsentStatus'
default: pending
created_at:
type: string
format: date-time
Expand All @@ -94,6 +95,12 @@ components:
format: date-time
maxLength: 21
example: "2021-01-30T08:30:00Z"
ConsentStatus:
type: string
enum:
- accepted
- denied
- pending
JoinToken:
$ref: '#/components/schemas/UUID'
SPIFFEID:
Expand Down
12 changes: 9 additions & 3 deletions pkg/common/entity/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import (
"github.com/spiffe/go-spiffe/v2/spiffeid"
)

// TODO: these entities will be defined by the OpenAPI specs and autogenerated.
type ConsentStatus string

const (
ConsentStatusAccepted ConsentStatus = "accepted"
ConsentStatusDenied ConsentStatus = "denied"
ConsentStatusPending ConsentStatus = "pending"
)

type TrustDomain struct {
ID uuid.NullUUID
Expand All @@ -25,8 +31,8 @@ type Relationship struct {
TrustDomainBID uuid.UUID
TrustDomainAName spiffeid.TrustDomain
TrustDomainBName spiffeid.TrustDomain
TrustDomainAConsent bool
TrustDomainBConsent bool
TrustDomainAConsent ConsentStatus
TrustDomainBConsent ConsentStatus
CreatedAt time.Time
UpdatedAt time.Time
}
Expand Down
48 changes: 24 additions & 24 deletions pkg/server/api/admin/admin.gen.go

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

Loading