Skip to content

Commit

Permalink
Implement Harvester API handlers (#154)
Browse files Browse the repository at this point in the history
* Implement Harvester API Get Relationships

Signed-off-by: Max Lambrecht <[email protected]>
  • Loading branch information
Max Lambrecht authored May 16, 2023
1 parent edc5fd8 commit 558818e
Show file tree
Hide file tree
Showing 21 changed files with 1,184 additions and 431 deletions.
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

0 comments on commit 558818e

Please sign in to comment.