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 Galadriel Server Admin CLI - GLCP-39474 #164

Merged
merged 21 commits into from
May 22, 2023

Conversation

mgbcaio
Copy link
Collaborator

@mgbcaio mgbcaio commented May 18, 2023

Pull request check list

  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality
Galadriel Server CLI: generate token, create trustdomain and create relationship

Description of change
The galadriel Server CLI now uses the Admin API, through the admin.Client, to perform the requests regarding Trust Domains, Relationships and Join Tokens.

WIP: List trust domains and relationships.

Renaming management.go and management_test.go -> admin.go and admin_test.go

Some changes to admin.yaml that were kinda of when implementing the CLI to use the generated code

Some bug fixing regarding the CLI usage and output of the functions.

Which issue this pull requests fixes

GLCP-39474

Copy link
Contributor

@maxlambrecht maxlambrecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, left some comments.

return nil, fmt.Errorf(errReadResponseBody, err)
}

if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be at the beginning of the function and return early if the statuscode is not success.

return relationship, nil
}

func readBodyAndStatusCode(res *http.Response) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to readResponse

if err != nil {
return err
}
// Use: "trustdomains",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove all the commented code

@@ -288,7 +291,7 @@ func (h *AdminAPIHandlers) GetJoinToken(echoCtx echo.Context, trustDomainName ap
}

if td == nil {
errMsg := fmt.Errorf("trust domain exists: %q", trustDomainName)
errMsg := fmt.Errorf("trust domain '%s' does not exists", trustDomainName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use %q for quoted strings

@@ -483,7 +483,7 @@ func TestUDSGetJoinToken(t *testing.T) {
echoHttpErr := err.(*echo.HTTPError)
assert.Equal(t, http.StatusBadRequest, echoHttpErr.Code)

expectedMsg := fmt.Errorf("trust domain exists: %q", td1)
expectedMsg := fmt.Errorf("trust domain '%s' does not exists", td1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use %q for quoted strings

if err != nil {
msg := errors.New("error looking up trust domain")
errMsg := fmt.Errorf("%s: %w", msg, err)
return nil, h.handleAndLog(errMsg, http.StatusInternalServerError)
}

if td == nil {
errMsg := fmt.Errorf("trust domain exists: %q", trustDomainID)
errMsg := fmt.Errorf("trust domain does not exists")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errMsg := fmt.Errorf("trust domain does not exists")
errMsg := fmt.Errorf("trust domain %q does not exists", tdName.String())

func (h *AdminAPIHandlers) lookupTrustDomain(ctx context.Context, trustDomainID uuid.UUID, code int) (*entity.TrustDomain, error) {
td, err := h.Datastore.FindTrustDomainByID(ctx, trustDomainID)
func (h *AdminAPIHandlers) lookupTrustDomain(ctx context.Context, trustDomainName api.TrustDomainName, code int) (*entity.TrustDomain, error) {
tdName := spiffeid.RequireTrustDomainFromString(trustDomainName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use RequireTrustDomainFromString, it's a method for testing, it panics instead of returning an error.

@@ -9,8 +9,8 @@ import (

func (r RelationshipRequest) ToEntity() *entity.Relationship {
return &entity.Relationship{
TrustDomainAID: r.TrustDomainAId,
TrustDomainBID: r.TrustDomainBId,
TrustDomainAName: spiffeid.RequireTrustDomainFromString(r.TrustDomainAName),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use RequireTrustDomainFromString

TrustDomainAID: r.TrustDomainAId,
TrustDomainBID: r.TrustDomainBId,
TrustDomainAName: spiffeid.RequireTrustDomainFromString(r.TrustDomainAName),
TrustDomainBName: spiffeid.RequireTrustDomainFromString(r.TrustDomainBName),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@maxlambrecht maxlambrecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mgbcaio!
The rest of the tests and the CLI implementation will be added in a separate PR.

Approving.

@maxlambrecht maxlambrecht merged commit 75289b5 into HewlettPackard:main May 22, 2023
@maxlambrecht maxlambrecht changed the title [WIP] - Implement Galadriel Server Admin CLI - GLCP-39474 Implement Galadriel Server Admin CLI - GLCP-39474 Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants