diff --git a/cmd/server/cli/create.go b/cmd/server/cli/create.go index 65647296..46a950f9 100644 --- a/cmd/server/cli/create.go +++ b/cmd/server/cli/create.go @@ -1,6 +1,7 @@ package cli import ( + "context" "fmt" "github.com/HewlettPackard/galadriel/cmd/server/util" @@ -10,7 +11,7 @@ import ( ) var createCmd = &cobra.Command{ - Use: "create ", + Use: "create ", Short: "Allows creation of trust domains and relationships", } @@ -20,23 +21,22 @@ var createTrustDomainCmd = &cobra.Command{ Short: "Creates a new trust domain", RunE: func(cmd *cobra.Command, args []string) error { - td, err := cmd.Flags().GetString("trustDomain") + trustDomain, err := cmd.Flags().GetString("trustDomain") if err != nil { return fmt.Errorf("cannot get trust domain flag: %v", err) } - trustDomain, err := spiffeid.TrustDomainFromString(td) + client, err := util.NewServerClient(defaultSocketPath) if err != nil { return err } - c := util.NewServerClient(defaultSocketPath) - - if err := c.CreateTrustDomain(&entity.TrustDomain{Name: trustDomain}); err != nil { + trustDomainRes, err := client.CreateTrustDomain(context.Background(), trustDomain) + if err != nil { return err } - fmt.Printf("Trust Domain created: %q\n", trustDomain.String()) + fmt.Printf("Trust Domain created: %s\n", trustDomainRes.Name.String()) return nil }, @@ -48,7 +48,10 @@ var createRelationshipCmd = &cobra.Command{ Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - c := util.NewServerClient(defaultSocketPath) + client, err := util.NewServerClient(defaultSocketPath) + if err != nil { + return err + } tdA, err := cmd.Flags().GetString("trustDomainA") if err != nil { @@ -57,26 +60,28 @@ var createRelationshipCmd = &cobra.Command{ trustDomain1, err := spiffeid.TrustDomainFromString(tdA) if err != nil { - return err + return fmt.Errorf("failed parsing trust domain: %v", err) } - tdb, err := cmd.Flags().GetString("trustDomainB") + tdB, err := cmd.Flags().GetString("trustDomainB") if err != nil { return fmt.Errorf("cannot get trust domain B flag: %v", err) } - trustDomain2, err := spiffeid.TrustDomainFromString(tdb) + + trustDomain2, err := spiffeid.TrustDomainFromString(tdB) if err != nil { - return err + return fmt.Errorf("failed parsing trust domain: %v", err) } - if err := c.CreateRelationship(&entity.Relationship{ + _, err = client.CreateRelationship(context.Background(), &entity.Relationship{ TrustDomainAName: trustDomain1, TrustDomainBName: trustDomain2, - }); err != nil { + }) + if err != nil { return err } - fmt.Printf("Relationship created between trust domain %q and trust domain %q\n", trustDomain1.String(), trustDomain2.String()) + fmt.Printf("Relationship created between trust domains %s and %s\n", tdA, tdB) return nil }, } diff --git a/cmd/server/cli/generate.go b/cmd/server/cli/generate.go index 6124af6d..fda42b54 100644 --- a/cmd/server/cli/generate.go +++ b/cmd/server/cli/generate.go @@ -1,12 +1,11 @@ package cli import ( + "context" "fmt" - "strings" "github.com/HewlettPackard/galadriel/cmd/server/util" "github.com/spf13/cobra" - "github.com/spiffe/go-spiffe/v2/spiffeid" ) var generateCmd = &cobra.Command{ @@ -18,30 +17,28 @@ var tokenCmd = &cobra.Command{ Args: cobra.ExactArgs(0), Short: "Generates a join token for provided trust domain", RunE: func(cmd *cobra.Command, args []string) error { - c := util.NewServerClient(defaultSocketPath) - - td, err := cmd.Flags().GetString("trustDomain") + trustDomain, err := cmd.Flags().GetString("trustdomain") if err != nil { return fmt.Errorf("cannot get trust domain flag: %v", err) } - trustDomain, err := spiffeid.TrustDomainFromString(td) + client, err := util.NewServerClient(defaultSocketPath) if err != nil { return err } - joinToken, err := c.GenerateJoinToken(trustDomain) + joinToken, err := client.GetJoinToken(context.Background(), trustDomain) if err != nil { return err } - fmt.Printf("Token: %s", strings.ReplaceAll(joinToken, "\"", "")) + fmt.Printf("Token: %s\n", joinToken.Token) return nil }, } func init() { generateCmd.AddCommand(tokenCmd) - tokenCmd.PersistentFlags().StringP("trustDomain", "t", "", "A trust domain which the join token is bound to.") + tokenCmd.PersistentFlags().StringP("trustdomain", "t", "", "A trust domain which the join token is bound to.") RootCmd.AddCommand(generateCmd) } diff --git a/cmd/server/cli/generate_test.go b/cmd/server/cli/generate_test.go new file mode 100644 index 00000000..631e60c7 --- /dev/null +++ b/cmd/server/cli/generate_test.go @@ -0,0 +1,17 @@ +package cli + +import ( + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" +) + +func TestTokenCmd(t *testing.T) { + cmd := &cobra.Command{} + cmd.Flags().String("trustDomain", "test.com", "") + + err := cmd.Execute() + + assert.Nil(t, err) +} diff --git a/cmd/server/cli/list.go b/cmd/server/cli/list.go index 48e646b1..b3d148f8 100644 --- a/cmd/server/cli/list.go +++ b/cmd/server/cli/list.go @@ -1,9 +1,6 @@ package cli import ( - "fmt" - - "github.com/HewlettPackard/galadriel/cmd/server/util" "github.com/spf13/cobra" ) @@ -12,58 +9,10 @@ var listCmd = &cobra.Command{ Short: "Lists trust domains and relationships", } -var listTrustDomainCmd = &cobra.Command{ - Use: "trustdomains", - Args: cobra.ExactArgs(0), - Short: "Lists all the Trust Domains.", - RunE: func(cmd *cobra.Command, args []string) error { - c := util.NewServerClient(defaultSocketPath) - trustDomains, err := c.ListTrustDomains() - if err != nil { - return err - } - - if len(trustDomains) == 0 { - fmt.Println("No trust domains found") - return nil - } - - for _, m := range trustDomains { - fmt.Printf("ID: %s\n", m.ID.UUID) - fmt.Printf("Trust Domain: %s\n", m.Name) - fmt.Println() - } - - return nil - }, -} +// TODO: Implement Get Relationships and Trust Domains +var listTrustDomainCmd = &cobra.Command{} -var listRelationshipsCmd = &cobra.Command{ - Use: "relationships", - Args: cobra.ExactArgs(0), - Short: "Lists all the relationships.", - RunE: func(cmd *cobra.Command, args []string) error { - c := util.NewServerClient(defaultSocketPath) - rels, err := c.ListRelationships() - if err != nil { - return err - } - - if len(rels) == 0 { - fmt.Println("No relationships found") - return nil - } - - for _, r := range rels { - fmt.Printf("ID: %s\n", r.ID.UUID) - fmt.Printf("Trust Domain A: %s\n", r.TrustDomainAName.String()) - fmt.Printf("Trust Domain B: %s\n", r.TrustDomainBName.String()) - fmt.Println() - } - - return nil - }, -} +var listRelationshipsCmd = &cobra.Command{} func init() { listCmd.AddCommand(listTrustDomainCmd) diff --git a/cmd/server/cli/run_test.go b/cmd/server/cli/run_test.go index 7f1e458c..8272b068 100644 --- a/cmd/server/cli/run_test.go +++ b/cmd/server/cli/run_test.go @@ -1 +1,45 @@ package cli + +import ( + "os" + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" +) + +func TestLoadConfig(t *testing.T) { + tempFile, err := os.CreateTemp("", "server.conf") + assert.NoError(t, err) + defer os.Remove(tempFile.Name()) + + _, err = tempFile.WriteString(` + server { + listen_address = "localhost" + listen_port = "8085" + socket_path = "/tmp/galadriel-server/api.sock/" + log_level = "DEBUG" +} + providers { + Datastore "postgres" { + connection_string = "postgresql://postgres:postgres@localhost:5432/galadriel" + } + + X509CA "disk" { + key_file_path = "./conf/server/dummy_root_ca.key" + cert_file_path = "./conf/server/dummy_root_ca.crt" + } + + KeyManager "memory" {} +} + `) + assert.NoError(t, err) + + cmd := &cobra.Command{} + cmd.Flags().String("config", tempFile.Name(), "") + + config, err := LoadConfig(cmd) + + assert.NoError(t, err) + assert.NotNil(t, config) +} diff --git a/cmd/server/util/client.go b/cmd/server/util/client.go index c904fce3..35e96afb 100644 --- a/cmd/server/util/client.go +++ b/cmd/server/util/client.go @@ -1,176 +1,235 @@ package util import ( - "bytes" "context" "encoding/json" - "errors" "fmt" "io" "net" "net/http" + "github.com/HewlettPackard/galadriel/pkg/common/api" "github.com/HewlettPackard/galadriel/pkg/common/entity" - "github.com/spiffe/go-spiffe/v2/spiffeid" + "github.com/HewlettPackard/galadriel/pkg/server/api/admin" + "github.com/google/uuid" ) -// URL pattern to make http calls on local Unix domain socket, -// the Host is required for the URL, but it's not relevant - const ( - localURL = "http://local/%s" - contentType = "application/json" -) - -var ( - createTrustDomainURL = fmt.Sprintf(localURL, "trust-domain") - listTrustDomainsURL = fmt.Sprintf(localURL, "listTrustDomains") - createRelationshipURL = fmt.Sprintf(localURL, "createRelationship") - listRelationshipsURL = fmt.Sprintf(localURL, "listRelationships") - joinTokenURL = fmt.Sprintf(localURL, "trust-domain/%s/join-token") + baseURL = "http://localhost/" + errFailedRequest = "failed to send request: %v" + errReadResponseBody = "failed to read response body: %v" + errStatusCodeMsg = "request returned an error code %d" + errUnmarshalRelationships = "failed to unmarshal relationships: %v" + errUnmarshalTrustDomains = "failed to unmarshal trust domain: %v" + errUnmarshalJoinToken = "failed to unmarshal join token: %v" ) // ServerLocalClient represents a local client of the Galadriel Server. type ServerLocalClient interface { - CreateTrustDomain(m *entity.TrustDomain) error - ListTrustDomains() ([]*entity.TrustDomain, error) - CreateRelationship(r *entity.Relationship) error - ListRelationships() ([]*entity.Relationship, error) - GenerateJoinToken(trustDomain spiffeid.TrustDomain) (string, error) + CreateTrustDomain(ctx context.Context, trustDomain api.TrustDomainName) (*entity.TrustDomain, error) + GetTrustDomainByName(ctx context.Context, trustDomainName api.TrustDomainName) (*entity.TrustDomain, error) + UpdateTrustDomainByName(ctx context.Context, trustDomainName api.TrustDomainName) (*entity.TrustDomain, error) + CreateRelationship(ctx context.Context, r *entity.Relationship) (*entity.Relationship, error) + GetRelationshipByID(ctx context.Context, relID uuid.UUID) (*entity.Relationship, error) + GetRelationships(ctx context.Context, consentStatus api.ConsentStatus, trustDomainName api.TrustDomainName) (*entity.Relationship, error) + GetJoinToken(ctx context.Context, trustDomain api.TrustDomainName) (*entity.JoinToken, error) } -// TODO: improve this adding options for the transport, dialcontext, and http.Client. -func NewServerClient(socketPath string) ServerLocalClient { +func NewServerClient(socketPath string) (ServerLocalClient, error) { + clientOpt := admin.WithBaseURL(baseURL) + + client, err := admin.NewClient(socketPath, clientOpt) + if err != nil { + return nil, fmt.Errorf("failed to instantiate the Admin Client: %q", err) + } + t := &http.Transport{ DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { var d net.Dialer return d.DialContext(ctx, "unix", socketPath) }} - c := &http.Client{ - Transport: t, - } - return serverClient{client: c} + client.Client = &http.Client{Transport: t} + + return &serverClient{client: client}, nil } type serverClient struct { - client *http.Client + client *admin.Client } -func (c serverClient) CreateTrustDomain(m *entity.TrustDomain) error { - trustDomainBytes, err := json.Marshal(m) +func (c *serverClient) GetTrustDomainByName(ctx context.Context, trustDomainName api.TrustDomainName) (*entity.TrustDomain, error) { + res, err := c.client.GetTrustDomainByName(ctx, trustDomainName) if err != nil { - return err + return nil, fmt.Errorf(errFailedRequest, err) } + defer res.Body.Close() - req, err := http.NewRequest(http.MethodPut, createTrustDomainURL, bytes.NewReader(trustDomainBytes)) + body, err := readResponse(res) if err != nil { - return err + return nil, err } - req.Header.Set("Content-Type", "application/json") - r, err := c.client.Do(req) + + trustDomain, err := unmarshalTrustDomain(body) if err != nil { - return err + return nil, err } - defer r.Body.Close() - body, err := io.ReadAll(r.Body) + return trustDomain, nil +} + +func (c *serverClient) UpdateTrustDomainByName(ctx context.Context, trustDomainName api.TrustDomainName) (*entity.TrustDomain, error) { + payload := api.TrustDomain{Name: trustDomainName} + res, err := c.client.PutTrustDomainByName(ctx, trustDomainName, payload) if err != nil { - return err + return nil, fmt.Errorf(errFailedRequest, err) } + defer res.Body.Close() - if r.StatusCode != 200 { - return errors.New(string(body)) + body, err := readResponse(res) + if err != nil { + return nil, err } - return nil + trustDomain, err := unmarshalTrustDomain(body) + if err != nil { + return nil, err + } + + return trustDomain, nil } -func (c serverClient) ListTrustDomains() ([]*entity.TrustDomain, error) { - r, err := c.client.Get(listTrustDomainsURL) +func (c *serverClient) CreateTrustDomain(ctx context.Context, trustDomainName api.TrustDomainName) (*entity.TrustDomain, error) { + payload := admin.PutTrustDomainJSONRequestBody{Name: trustDomainName} + + res, err := c.client.PutTrustDomain(ctx, payload) + if err != nil { + return nil, fmt.Errorf(errFailedRequest, err) + } + defer res.Body.Close() + + body, err := readResponse(res) if err != nil { return nil, err } - defer r.Body.Close() - b, err := io.ReadAll(r.Body) + trustDomain, err := unmarshalTrustDomain(body) if err != nil { return nil, err } - if r.StatusCode != 200 { - return nil, errors.New(string(b)) + return trustDomain, nil +} + +func (c *serverClient) CreateRelationship(ctx context.Context, rel *entity.Relationship) (*entity.Relationship, error) { + payload := admin.PutRelationshipJSONRequestBody{TrustDomainAName: rel.TrustDomainAName.String(), TrustDomainBName: rel.TrustDomainBName.String()} + res, err := c.client.PutRelationship(ctx, payload) + if err != nil { + return nil, fmt.Errorf(errFailedRequest, err) } + defer res.Body.Close() - var trustDomains []*entity.TrustDomain - if err = json.Unmarshal(b, &trustDomains); err != nil { + body, err := readResponse(res) + if err != nil { return nil, err } - return trustDomains, nil + relationship, err := unmarshalRelationship(body) + if err != nil { + return nil, err + } + + return relationship, nil } +func (c *serverClient) GetRelationships(ctx context.Context, consentStatus api.ConsentStatus, trustDomainName api.TrustDomainName) (*entity.Relationship, error) { + payload := &admin.GetRelationshipsParams{Status: (*api.ConsentStatus)(&consentStatus), TrustDomainName: &trustDomainName} -func (c serverClient) CreateRelationship(rel *entity.Relationship) error { - relBytes, err := json.Marshal(rel) + res, err := c.client.GetRelationships(ctx, payload) if err != nil { - return err + return nil, fmt.Errorf(errFailedRequest, err) } + defer res.Body.Close() - r, err := c.client.Post(createRelationshipURL, contentType, bytes.NewReader(relBytes)) + body, err := readResponse(res) if err != nil { - return fmt.Errorf("failed to create relationship: %v", err) + return nil, err } - defer r.Body.Close() - b, err := io.ReadAll(r.Body) + relationship, err := unmarshalRelationship(body) if err != nil { - return err + return nil, err } - if r.StatusCode != 200 { - return errors.New(string(b)) + return relationship, nil +} + +func (c *serverClient) GetRelationshipByID(ctx context.Context, relID uuid.UUID) (*entity.Relationship, error) { + res, err := c.client.GetRelationshipByID(ctx, relID) + if err != nil { + return nil, fmt.Errorf(errFailedRequest, err) } + defer res.Body.Close() - return nil -} + body, err := readResponse(res) + if err != nil { + return nil, err + } -func (c serverClient) ListRelationships() ([]*entity.Relationship, error) { - r, err := c.client.Get(listRelationshipsURL) + relationship, err := unmarshalRelationship(body) if err != nil { return nil, err } - defer r.Body.Close() - b, err := io.ReadAll(r.Body) + return relationship, nil +} +func (c *serverClient) GetJoinToken(ctx context.Context, trustDomainName api.TrustDomainName) (*entity.JoinToken, error) { + res, err := c.client.GetJoinToken(ctx, trustDomainName) + if err != nil { + return nil, fmt.Errorf(errFailedRequest, err) + } + defer res.Body.Close() + + body, err := readResponse(res) if err != nil { return nil, err } - if r.StatusCode != 200 { - return nil, errors.New(string(b)) + var joinToken *entity.JoinToken + if err = json.Unmarshal(body, &joinToken); err != nil { + return nil, fmt.Errorf(errUnmarshalJoinToken, err) } - var rels []*entity.Relationship - if err = json.Unmarshal(b, &rels); err != nil { - return nil, err + return joinToken, nil +} + +func unmarshalTrustDomain(body []byte) (*entity.TrustDomain, error) { + var trustDomain *entity.TrustDomain + if err := json.Unmarshal(body, &trustDomain); err != nil { + return nil, fmt.Errorf(errUnmarshalTrustDomains, err) } - return rels, nil + return trustDomain, nil } -func (c serverClient) GenerateJoinToken(td spiffeid.TrustDomain) (string, error) { - joinTokenURL := fmt.Sprintf(joinTokenURL, td) - r, err := c.client.Get(joinTokenURL) - if err != nil { - return "", err +func unmarshalRelationship(body []byte) (*entity.Relationship, error) { + var relationship *entity.Relationship + if err := json.Unmarshal(body, &relationship); err != nil { + return nil, fmt.Errorf(errUnmarshalRelationships, err) + } + + return relationship, nil +} + +func readResponse(res *http.Response) ([]byte, error) { + if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated { + return nil, fmt.Errorf(errStatusCodeMsg, res.StatusCode) } - defer r.Body.Close() - body, err := io.ReadAll(r.Body) + body, err := io.ReadAll(res.Body) if err != nil { - return "", err + return nil, fmt.Errorf(errReadResponseBody, err) } - return string(body), nil + return body, nil } diff --git a/pkg/server/api/admin/admin.gen.go b/pkg/server/api/admin/admin.gen.go index a3b7ab65..eabefb48 100644 --- a/pkg/server/api/admin/admin.gen.go +++ b/pkg/server/api/admin/admin.gen.go @@ -29,8 +29,8 @@ type JoinTokenResult struct { // RelationshipRequest defines model for RelationshipRequest. type RelationshipRequest struct { - TrustDomainAId externalRef0.UUID `json:"trust_domain_a_id"` - TrustDomainBId externalRef0.UUID `json:"trust_domain_b_id"` + TrustDomainAName externalRef0.TrustDomainName `json:"trust_domain_a_name"` + TrustDomainBName externalRef0.TrustDomainName `json:"trust_domain_b_name"` } // TrustDomainPut defines model for TrustDomainPut. @@ -153,9 +153,9 @@ type ClientInterface interface { GetTrustDomainByName(ctx context.Context, trustDomainName externalRef0.TrustDomainName, reqEditors ...RequestEditorFn) (*http.Response, error) // PutTrustDomainByName request with any body - PutTrustDomainByNameWithBody(ctx context.Context, trustDomainName externalRef0.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + PutTrustDomainByNameWithBody(ctx context.Context, trustDomainName externalRef0.TrustDomainName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - PutTrustDomainByName(ctx context.Context, trustDomainName externalRef0.UUID, body PutTrustDomainByNameJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + PutTrustDomainByName(ctx context.Context, trustDomainName externalRef0.TrustDomainName, body PutTrustDomainByNameJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // GetJoinToken request GetJoinToken(ctx context.Context, trustDomainName externalRef0.TrustDomainName, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -245,7 +245,7 @@ func (c *Client) GetTrustDomainByName(ctx context.Context, trustDomainName exter return c.Client.Do(req) } -func (c *Client) PutTrustDomainByNameWithBody(ctx context.Context, trustDomainName externalRef0.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) PutTrustDomainByNameWithBody(ctx context.Context, trustDomainName externalRef0.TrustDomainName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewPutTrustDomainByNameRequestWithBody(c.Server, trustDomainName, contentType, body) if err != nil { return nil, err @@ -257,7 +257,7 @@ func (c *Client) PutTrustDomainByNameWithBody(ctx context.Context, trustDomainNa return c.Client.Do(req) } -func (c *Client) PutTrustDomainByName(ctx context.Context, trustDomainName externalRef0.UUID, body PutTrustDomainByNameJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) PutTrustDomainByName(ctx context.Context, trustDomainName externalRef0.TrustDomainName, body PutTrustDomainByNameJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewPutTrustDomainByNameRequest(c.Server, trustDomainName, body) if err != nil { return nil, err @@ -493,7 +493,7 @@ func NewGetTrustDomainByNameRequest(server string, trustDomainName externalRef0. } // NewPutTrustDomainByNameRequest calls the generic PutTrustDomainByName builder with application/json body -func NewPutTrustDomainByNameRequest(server string, trustDomainName externalRef0.UUID, body PutTrustDomainByNameJSONRequestBody) (*http.Request, error) { +func NewPutTrustDomainByNameRequest(server string, trustDomainName externalRef0.TrustDomainName, body PutTrustDomainByNameJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { @@ -504,7 +504,7 @@ func NewPutTrustDomainByNameRequest(server string, trustDomainName externalRef0. } // NewPutTrustDomainByNameRequestWithBody generates requests for PutTrustDomainByName with any type of body -func NewPutTrustDomainByNameRequestWithBody(server string, trustDomainName externalRef0.UUID, contentType string, body io.Reader) (*http.Request, error) { +func NewPutTrustDomainByNameRequestWithBody(server string, trustDomainName externalRef0.TrustDomainName, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string @@ -636,9 +636,9 @@ type ClientWithResponsesInterface interface { GetTrustDomainByNameWithResponse(ctx context.Context, trustDomainName externalRef0.TrustDomainName, reqEditors ...RequestEditorFn) (*GetTrustDomainByNameResponse, error) // PutTrustDomainByName request with any body - PutTrustDomainByNameWithBodyWithResponse(ctx context.Context, trustDomainName externalRef0.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutTrustDomainByNameResponse, error) + PutTrustDomainByNameWithBodyWithResponse(ctx context.Context, trustDomainName externalRef0.TrustDomainName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutTrustDomainByNameResponse, error) - PutTrustDomainByNameWithResponse(ctx context.Context, trustDomainName externalRef0.UUID, body PutTrustDomainByNameJSONRequestBody, reqEditors ...RequestEditorFn) (*PutTrustDomainByNameResponse, error) + PutTrustDomainByNameWithResponse(ctx context.Context, trustDomainName externalRef0.TrustDomainName, body PutTrustDomainByNameJSONRequestBody, reqEditors ...RequestEditorFn) (*PutTrustDomainByNameResponse, error) // GetJoinToken request GetJoinTokenWithResponse(ctx context.Context, trustDomainName externalRef0.TrustDomainName, reqEditors ...RequestEditorFn) (*GetJoinTokenResponse, error) @@ -867,7 +867,7 @@ func (c *ClientWithResponses) GetTrustDomainByNameWithResponse(ctx context.Conte } // PutTrustDomainByNameWithBodyWithResponse request with arbitrary body returning *PutTrustDomainByNameResponse -func (c *ClientWithResponses) PutTrustDomainByNameWithBodyWithResponse(ctx context.Context, trustDomainName externalRef0.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutTrustDomainByNameResponse, error) { +func (c *ClientWithResponses) PutTrustDomainByNameWithBodyWithResponse(ctx context.Context, trustDomainName externalRef0.TrustDomainName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutTrustDomainByNameResponse, error) { rsp, err := c.PutTrustDomainByNameWithBody(ctx, trustDomainName, contentType, body, reqEditors...) if err != nil { return nil, err @@ -875,7 +875,7 @@ func (c *ClientWithResponses) PutTrustDomainByNameWithBodyWithResponse(ctx conte return ParsePutTrustDomainByNameResponse(rsp) } -func (c *ClientWithResponses) PutTrustDomainByNameWithResponse(ctx context.Context, trustDomainName externalRef0.UUID, body PutTrustDomainByNameJSONRequestBody, reqEditors ...RequestEditorFn) (*PutTrustDomainByNameResponse, error) { +func (c *ClientWithResponses) PutTrustDomainByNameWithResponse(ctx context.Context, trustDomainName externalRef0.TrustDomainName, body PutTrustDomainByNameJSONRequestBody, reqEditors ...RequestEditorFn) (*PutTrustDomainByNameResponse, error) { rsp, err := c.PutTrustDomainByName(ctx, trustDomainName, body, reqEditors...) if err != nil { return nil, err @@ -1142,7 +1142,7 @@ type ServerInterface interface { GetTrustDomainByName(ctx echo.Context, trustDomainName externalRef0.TrustDomainName) error // Update a specific trust domain // (PUT /trust-domain/{trustDomainName}) - PutTrustDomainByName(ctx echo.Context, trustDomainName externalRef0.UUID) error + PutTrustDomainByName(ctx echo.Context, trustDomainName externalRef0.TrustDomainName) error // Get a join token for a specific Trust Domain // (GET /trust-domain/{trustDomainName}/join-token) GetJoinToken(ctx echo.Context, trustDomainName externalRef0.TrustDomainName) error @@ -1232,7 +1232,7 @@ func (w *ServerInterfaceWrapper) GetTrustDomainByName(ctx echo.Context) error { func (w *ServerInterfaceWrapper) PutTrustDomainByName(ctx echo.Context) error { var err error // ------------- Path parameter "trustDomainName" ------------- - var trustDomainName externalRef0.UUID + var trustDomainName externalRef0.TrustDomainName err = runtime.BindStyledParameterWithLocation("simple", false, "trustDomainName", runtime.ParamLocationPath, ctx.Param("trustDomainName"), &trustDomainName) if err != nil { @@ -1301,31 +1301,31 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/9xZW1PbRhT+KzvbPLQZ3WyDA3ozgaTupJSBZKYTxmXW0pG9ibSr7K5wXEb/vbMr2ZZk", - "gQUBmuQJWXs5l+87N3GDA56knAFTEvs3WIBMOZNgfhxDRLJY6ceAMwXMPJI0jWlAFOXM/SQ50+9kMIeE", - "6KcXAiLs41/czb1usSrdUUpPhOAC53lu4RBkIGiq78E+NgtodDZGGxX0rvKsvnp9XCsRhlSfJPGZ4CkI", - "RbXKEYklWDitvNKqh6D/RlwkRGEfU6aGe9jCCflKkyzB/v7hoYUTyopfPc+zsFqmUGyFGQicWzgBKcnM", - "3ARfSZLGen2EpkAyRaMsRmAsWG2zN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4sm+QHQdI0u7bipRQPmD2O0O2YtB9NY0ZUQsnFCdYzQFdQPA", + "kLrhlkjvA7J0WhXEv23+HB+Xu5aUo8X4eFtVGR8jnpjG2qKJUbGuaWsR227gNrq7aro6w/2wkH9CMmi9", + "klUrsyixBXBTH914NW/cpWW70j6HlFunurKWsQVU7zmsdeFUqSt+AmhGcdyERjVOmQ1omhrtQMa/bfWx", + "e6XYiO1oUXe9e7VotfH60N8hw81e+jgdPn1v/QGkX0aRu8Hu7CK/XwnSZ60S3SXiVyfOJzNfP0fJ8L9w", + "ytzVJ/K7qsf68/hDKHb6D6sa7f9DvHTl0FghgxVKuGjSwcJ9TQftMKpwmxhnpZkuK+DsOTrlEUnnXCpP", + "3pDZDIRHuU9y6l8PsE5qvWUb7xGqPpm1Pahxtu5ujmoj+6BKpTn7rT6xmCf6REiWVt5BXCfVOiHee7St", + "XbEPOpu+nHdYbSR8ygsWI8VbA663NtBIdjkp/woAAP//wY4RiHQdAAA=", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/pkg/server/api/admin/admin.yaml b/pkg/server/api/admin/admin.yaml index 8a721479..bed52a39 100644 --- a/pkg/server/api/admin/admin.yaml +++ b/pkg/server/api/admin/admin.yaml @@ -54,7 +54,7 @@ paths: description: Trust Domain name required: true schema: - $ref: '../../../common/api/schemas.yaml#/components/schemas/UUID' + $ref: '../../../common/api/schemas.yaml#/components/schemas/TrustDomainName' requestBody: content: application/json: @@ -199,13 +199,13 @@ components: type: object additionalProperties: false required: - - trust_domain_a_id - - trust_domain_b_id + - trust_domain_a_name + - trust_domain_b_name properties: - trust_domain_a_id: - $ref: '../../../common/api/schemas.yaml#/components/schemas/UUID' - trust_domain_b_id: - $ref: '../../../common/api/schemas.yaml#/components/schemas/UUID' + trust_domain_a_name: + $ref: '../../../common/api/schemas.yaml#/components/schemas/TrustDomainName' + trust_domain_b_name: + $ref: '../../../common/api/schemas.yaml#/components/schemas/TrustDomainName' TrustDomainPut: type: object additionalProperties: false diff --git a/pkg/server/api/admin/helper.go b/pkg/server/api/admin/helper.go index 2b996a96..0d3998af 100644 --- a/pkg/server/api/admin/helper.go +++ b/pkg/server/api/admin/helper.go @@ -7,11 +7,21 @@ import ( "github.com/spiffe/go-spiffe/v2/spiffeid" ) -func (r RelationshipRequest) ToEntity() *entity.Relationship { - return &entity.Relationship{ - TrustDomainAID: r.TrustDomainAId, - TrustDomainBID: r.TrustDomainBId, +func (r RelationshipRequest) ToEntity() (*entity.Relationship, error) { + tdA, err := spiffeid.TrustDomainFromString(r.TrustDomainAName) + if err != nil { + return nil, fmt.Errorf("malformed trust domain[%q]: %v", r.TrustDomainAName, err) + } + + tdB, err := spiffeid.TrustDomainFromString(r.TrustDomainBName) + if err != nil { + return nil, fmt.Errorf("malformed trust domain[%q]: %v", r.TrustDomainBName, err) } + + return &entity.Relationship{ + TrustDomainAName: tdA, + TrustDomainBName: tdB, + }, nil } func (td TrustDomainPut) ToEntity() (*entity.TrustDomain, error) { diff --git a/pkg/server/api/admin/helper_test.go b/pkg/server/api/admin/helper_test.go index e775dfc3..e9823233 100644 --- a/pkg/server/api/admin/helper_test.go +++ b/pkg/server/api/admin/helper_test.go @@ -3,22 +3,27 @@ package admin import ( "testing" - "github.com/google/uuid" "github.com/stretchr/testify/assert" ) +const ( + td1 = "test.com" + td2 = "test2.com" +) + func TestRelationshipRequestToEntity(t *testing.T) { t.Run("Full fill correctly the relationship entity model", func(t *testing.T) { releationshipRequest := RelationshipRequest{ - TrustDomainAId: uuid.New(), - TrustDomainBId: uuid.New(), + TrustDomainAName: td1, + TrustDomainBName: td2, } - r := releationshipRequest.ToEntity() + r, err := releationshipRequest.ToEntity() + assert.NoError(t, err) assert.NotNil(t, r) - assert.Equal(t, releationshipRequest.TrustDomainAId, r.TrustDomainAID) - assert.Equal(t, releationshipRequest.TrustDomainBId, r.TrustDomainBID) + assert.Equal(t, releationshipRequest.TrustDomainAName, r.TrustDomainAName.String()) + assert.Equal(t, releationshipRequest.TrustDomainBName, r.TrustDomainBName.String()) }) } diff --git a/pkg/server/endpoints/management.go b/pkg/server/endpoints/admin.go similarity index 90% rename from pkg/server/endpoints/management.go rename to pkg/server/endpoints/admin.go index fbf147a4..268b43e4 100644 --- a/pkg/server/endpoints/management.go +++ b/pkg/server/endpoints/admin.go @@ -102,25 +102,31 @@ func (h *AdminAPIHandlers) PutRelationship(echoCtx echo.Context) error { err := fmt.Errorf("failed to read relationship put body: %v", err) return h.handleAndLog(err, http.StatusBadRequest) } - eRelationship := reqBody.ToEntity() + eRelationship, err := reqBody.ToEntity() + if err != nil { + return err + } - _, err = h.lookupTrustDomain(ctx, eRelationship.TrustDomainAID, http.StatusBadRequest) + dbTd1, err := h.lookupTrustDomain(ctx, eRelationship.TrustDomainAName.String(), http.StatusBadRequest) if err != nil { return err } - _, err = h.lookupTrustDomain(ctx, eRelationship.TrustDomainBID, http.StatusBadRequest) + dbTd2, err := h.lookupTrustDomain(ctx, eRelationship.TrustDomainBName.String(), http.StatusBadRequest) if err != nil { return err } + eRelationship.TrustDomainAID = dbTd1.ID.UUID + eRelationship.TrustDomainBID = dbTd2.ID.UUID + rel, err := h.Datastore.CreateOrUpdateRelationship(ctx, eRelationship) if err != nil { err = fmt.Errorf("failed creating relationship: %v", err) return h.handleAndLog(err, http.StatusInternalServerError) } - h.Logger.Printf("Created relationship between trust domains %s and %s", rel.TrustDomainAID, rel.TrustDomainBID) + h.Logger.Printf("Created relationship between trust domains %s and %s", dbTd1.Name.String(), dbTd2.Name.String()) response := api.RelationshipFromEntity(rel) err = chttp.WriteResponse(echoCtx, http.StatusCreated, response) @@ -179,7 +185,7 @@ func (h *AdminAPIHandlers) PutTrustDomain(echoCtx echo.Context) error { } if td != nil { - err = fmt.Errorf("trust domain already exists: %q", dbTD.Name) + err = fmt.Errorf("trust domain already exists: %s", dbTD.Name.String()) return h.handleAndLog(err, http.StatusBadRequest) } @@ -189,7 +195,7 @@ func (h *AdminAPIHandlers) PutTrustDomain(echoCtx echo.Context) error { return h.handleAndLog(err, http.StatusInternalServerError) } - h.Logger.Printf("Created trustDomain for trust domain: %s", dbTD.Name) + h.Logger.Printf("Created trustDomain: %s", dbTD.Name.String()) response := api.TrustDomainFromEntity(m) err = chttp.WriteResponse(echoCtx, http.StatusCreated, response) @@ -233,7 +239,7 @@ func (h *AdminAPIHandlers) GetTrustDomainByName(echoCtx echo.Context, trustDomai } // PutTrustDomainByName updates the trust domain - (PUT /trust-domain/{trustDomainName}) -func (h *AdminAPIHandlers) PutTrustDomainByName(echoCtx echo.Context, trustDomainID api.UUID) error { +func (h *AdminAPIHandlers) PutTrustDomainByName(echoCtx echo.Context, trustDomainName api.TrustDomainName) error { ctx := echoCtx.Request().Context() reqBody := &admin.PutTrustDomainByNameJSONRequestBody{} @@ -249,7 +255,7 @@ func (h *AdminAPIHandlers) PutTrustDomainByName(echoCtx echo.Context, trustDomai return h.handleAndLog(err, http.StatusBadRequest) } - _, err = h.lookupTrustDomain(ctx, trustDomainID, http.StatusNotFound) + _, err = h.lookupTrustDomain(ctx, trustDomainName, http.StatusNotFound) if err != nil { return err } @@ -288,7 +294,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 %q does not exists", trustDomainName) return h.handleAndLog(errMsg, http.StatusBadRequest) } @@ -337,8 +343,13 @@ func (h *AdminAPIHandlers) findTrustDomainByName(ctx context.Context, trustDomai return td, nil } -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, err := spiffeid.TrustDomainFromString(trustDomainName) + if err != nil { + return nil, fmt.Errorf("malformed trust domain[%q]: %v", trustDomainName, err) + } + + td, err := h.Datastore.FindTrustDomainByName(ctx, tdName) if err != nil { msg := errors.New("error looking up trust domain") errMsg := fmt.Errorf("%s: %w", msg, err) @@ -346,7 +357,7 @@ func (h *AdminAPIHandlers) lookupTrustDomain(ctx context.Context, trustDomainID } if td == nil { - errMsg := fmt.Errorf("trust domain exists: %q", trustDomainID) + errMsg := fmt.Errorf("trust domain %q does not exists", tdName.String()) return nil, h.handleAndLog(errMsg, code) } diff --git a/pkg/server/endpoints/management_test.go b/pkg/server/endpoints/admin_test.go similarity index 96% rename from pkg/server/endpoints/management_test.go rename to pkg/server/endpoints/admin_test.go index 4f45b2d2..52717f8d 100644 --- a/pkg/server/endpoints/management_test.go +++ b/pkg/server/endpoints/admin_test.go @@ -198,8 +198,8 @@ func TestUDSPutRelationships(t *testing.T) { } reqBody := &admin.PutRelationshipJSONRequestBody{ - TrustDomainAId: tdUUID1.UUID, - TrustDomainBId: tdUUID2.UUID, + TrustDomainAName: td1, + TrustDomainBName: td2, } // Setup @@ -227,8 +227,8 @@ func TestUDSPutRelationships(t *testing.T) { } reqBody := &admin.PutRelationshipJSONRequestBody{ - TrustDomainAId: tdUUID1.UUID, - TrustDomainBId: tdUUID2.UUID, + TrustDomainAName: td1, + TrustDomainBName: td2, } // Setup @@ -242,8 +242,8 @@ func TestUDSPutRelationships(t *testing.T) { echoHTTPErr := err.(*echo.HTTPError) assert.Equal(t, http.StatusBadRequest, echoHTTPErr.Code) - expectedErrorMsg := fmt.Sprintf("trust domain exists: %q", tdUUID2.UUID) - assert.Equal(t, expectedErrorMsg, echoHTTPErr.Message) + expectedErrorMsg := fmt.Errorf("trust domain %q does not exists", td2) + assert.Equal(t, expectedErrorMsg.Error(), echoHTTPErr.Message) }) // Should we test sending wrong body formats ? @@ -409,7 +409,7 @@ func TestUDSPutTrustDomainByName(t *testing.T) { setup := NewManagementTestSetup(t, http.MethodPut, completePath, reqBody) setup.FakeDatabase.WithTrustDomains(&fakeTrustDomains) - err := setup.Handler.PutTrustDomainByName(setup.EchoCtx, tdUUID1.UUID) + err := setup.Handler.PutTrustDomainByName(setup.EchoCtx, td1) assert.NoError(t, err) assert.Equal(t, http.StatusOK, setup.Recorder.Code) @@ -436,14 +436,14 @@ func TestUDSPutTrustDomainByName(t *testing.T) { // Setup setup := NewManagementTestSetup(t, http.MethodPut, completePath, reqBody) - err := setup.Handler.PutTrustDomainByName(setup.EchoCtx, tdUUID1.UUID) + err := setup.Handler.PutTrustDomainByName(setup.EchoCtx, td1) assert.Error(t, err) assert.Empty(t, setup.Recorder.Body.Bytes()) echoHTTPErr := err.(*echo.HTTPError) assert.Equal(t, http.StatusNotFound, echoHTTPErr.Code) - expectedErrorMsg := fmt.Sprintf("trust domain exists: %q", tdUUID1.UUID) - assert.Equal(t, expectedErrorMsg, echoHTTPErr.Message) + expectedErrorMsg := fmt.Errorf("trust domain %q does not exists", td1) + assert.Equal(t, expectedErrorMsg.Error(), echoHTTPErr.Message) }) } @@ -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 %q does not exists", td1) assert.Equal(t, expectedMsg.Error(), echoHttpErr.Message) }) }