-
Notifications
You must be signed in to change notification settings - Fork 16
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
Implementing Galadriel Server Management Handlers API #150
Implementing Galadriel Server Management Handlers API #150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rename this to admin.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm modifying the same file, can we postpone the renaming for now?
…ving get relationship uni tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good for me, lets see what others think. Thanks for putting this together, Victor! amazing work.
tdUUID1 := NewNullableID() | ||
tdUUID2 := NewNullableID() | ||
tdUUID3 := NewNullableID() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we declare this to be reused in the other tests ? something like:
var (
// Relationships ID's
r1ID = NewNullableID()
r2ID = NewNullableID()
r3ID = NewNullableID()
// Trust Domains ID's
tdUUID1 = NewNullableID()
tdUUID2 = NewNullableID()
tdUUID3 = NewNullableID()
)
pkg/server/endpoints/management.go
Outdated
} | ||
|
||
return nil | ||
} | ||
|
||
// GetRelationshipsRelationshipID retrieve a specific relationship based on its id - (GET /relationships/{relationshipID}) | ||
func (h AdminAPIHandlers) GetRelationshipsRelationshipID(ctx echo.Context, relationshipID api.UUID) error { | ||
func (h AdminAPIHandlers) GetRelationshipsRelationshipID(echoCtx echo.Context, relationshipID api.UUID) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the spec adding the operation ID=GetRelationshipByID
to avoid having this awful name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense
pkg/server/endpoints/management.go
Outdated
} | ||
|
||
return nil | ||
} | ||
|
||
// GetTrustDomainTrustDomainName retrieve a specific trust domain by its name - (GET /trust-domain/{trustDomainName}) | ||
func (h AdminAPIHandlers) GetTrustDomainTrustDomainName(ctx echo.Context, trustDomainName api.TrustDomainName) error { | ||
func (h AdminAPIHandlers) GetTrustDomainTrustDomainName(echoCtx echo.Context, trustDomainName api.TrustDomainName) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, change the open api spec to generate a better name: GetTrustDomainByName
pkg/server/endpoints/management.go
Outdated
return nil | ||
} | ||
|
||
// PutTrustDomainTrustDomainName updates the trust domain - (PUT /trust-domain/{trustDomainName}) | ||
func (h AdminAPIHandlers) PutTrustDomainTrustDomainName(ctx echo.Context, trustDomainName api.UUID) error { | ||
func (h AdminAPIHandlers) PutTrustDomainTrustDomainName(echoCtx echo.Context, trustDomainID api.UUID) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
pkg/server/endpoints/management.go
Outdated
return td, nil | ||
} | ||
|
||
func (h *AdminAPIHandlers) filterRelationshipsByStatus( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need your changes to simplify that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can copy my function and then once one of the PRs is merged refactor to remove the duplication.
Here is a new version more readable:
func filterRelationshipsByConsentStatus(trustDomain uuid.UUID, relationships []*entity.Relationship, status api.ConsentStatus) []*entity.Relationship {
filtered := make([]*entity.Relationship, 0)
for _, relationship := range relationships {
trustDomainA := relationship.TrustDomainAID
trustDomainB := relationship.TrustDomainBID
trustDomainAConsent := api.ConsentStatus(relationship.TrustDomainAConsent)
trustDomainBConsent := api.ConsentStatus(relationship.TrustDomainBConsent)
isConsentStatusMatch := (trustDomainA == trustDomain && trustDomainAConsent == status) ||
(trustDomainB == trustDomain && trustDomainBConsent == status)
if isConsentStatusMatch {
filtered = append(filtered, relationship)
}
}
return filtered
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not wrong, I think you changed the database models to support that. So functions like api.ConsenStatus
does not exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we can push your PR first. Since is already on review
pkg/server/endpoints/management.go
Outdated
eRelationship := reqBody.ToEntity() | ||
rel, err := h.Datastore.CreateOrUpdateRelationship(gctx, eRelationship) | ||
|
||
if err := h.checkTrustDomains(ctx, http.StatusBadRequest, eRelationship.TrustDomainAID, eRelationship.TrustDomainBID); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be removed and it would be better handled at the datastore layer, the CreateOrUpdateRelationship
will fail if one of the trust domain doesn't exist because a DB constraint will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, agreed that the database can handle that, the point of checking before is to properly identify the problem. I mean, it was a bad request from the user rather than an internal server error. We could do that by checking the error message instead but this will also make us couple with the specific database. Let me know what you think. Can we handle that in a different way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do it this way:
tdA, err := h.lookupTrustDomain(ctx, eRelationship.TrustDomainAID)
if err != nil {
return err
}
tdB, err := h.lookupTrustDomain(ctx, eRelationship.TrustDomainBID)
if err != nil {
return err
}
...
func (h *HarvesterAPIHandlers) lookupTrustDomain(ctx context.Context, trustDomainID uuid.UUID) (*entity.TrustDomain, error) {
td, err := h.Datastore.FindBundleByTrustDomainID(ctx, trustDomainID)
if err != nil {
msg := "error looking up trust domain"
errMsg := fmt.Errorf("%s: %w", errorMsg, err)
return nil, h.handleErrorAndLog(errMsg, msg, http.StatusInternalServerError)
}
if td == nil {
errMsg := fmt.Sprintf("trust domain not found: %q", trustDomainID)
return nil, h.handleErrorAndLog(errors.New(errMsg), errMsg, http.StatusBadRequest)
}
return td, nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated my comment here ☝️
Co-authored-by: Max Lambrecht <[email protected]> Signed-off-by: Victor Vieira Barros Leal da Silveira <[email protected]>
Co-authored-by: Max Lambrecht <[email protected]> Signed-off-by: Victor Vieira Barros Leal da Silveira <[email protected]>
pkg/server/endpoints/const_test.go
Outdated
@@ -1,5 +1,7 @@ | |||
package endpoints | |||
|
|||
const ( | |||
testTrustDomain = "test.com" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to create a separate file for constants used in tests.
pkg/server/endpoints/auth_test.go
Outdated
@@ -46,8 +46,8 @@ func SetupMiddleware() *AuthNTestSetup { | |||
} | |||
} | |||
|
|||
func SetupToken(t *testing.T, ds datastore.Datastore, token string, tdID uuid.UUID) *entity.JoinToken { | |||
td, err := spiffeid.TrustDomainFromString(testTrustDomain) | |||
func SetupToken(t *testing.T, ds datastore.Datastore, tdID uuid.UUID, token, tdName string) *entity.JoinToken { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't exist anymore.
It would be a good idea to rebase your branch before continuing making changes. |
// BodylessResponse wraps error echo body-less responses. | ||
func BodylessResponse(ctx echo.Context) error { | ||
// BodilessResponse wraps error echo body-less responses. | ||
func BodilessResponse(ctx echo.Context, code int) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why add this parameter that is not used?
Name suggestions for this function: NoContentResponse
or EmptyResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misstype
pkg/common/http/http_test.go
Outdated
@@ -34,21 +34,22 @@ func Setup() *HTTPSetup { | |||
func TestWriteResponse(t *testing.T) { | |||
t.Run("Error when nil body is passed", func(t *testing.T) { | |||
setup := Setup() | |||
err := WriteResponse(setup.EchoContext, nil) | |||
err := WriteResponse(setup.EchoContext, 0, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is 0
a valid http status code?
@@ -25,6 +26,23 @@ import ( | |||
const ( | |||
jwtPath = "/jwt" | |||
onboardPath = "/onboard" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes shouldn't be part of this PR, it should be focused on the management
and management_test
. I'm working on the Harvester API and making changes to this file, so it will be very hard to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just add const, but I will move to another file.
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Victorblsilveira!
Implementing Galadriel Server Management Handlers API (#150) Signed-off-by: Max Lambrecht <[email protected]>
Pull request check list
Affected functionality
All endpoints of the Server Management API.
Description of change
Implementing some endpoints from de UDS OpenAPI specifications.
Unit Tests included.
Which issue this pull requests fixes