diff --git a/cmd/common/cli/consent_status.go b/cmd/common/cli/consent_status.go new file mode 100644 index 00000000..8fd91100 --- /dev/null +++ b/cmd/common/cli/consent_status.go @@ -0,0 +1,17 @@ +package cli + +import ( + "fmt" + "strings" +) + +var ValidConsentStatusValues = []string{"approved", "denied", "pending"} + +func ValidateConsentStatusValue(status string) error { + for _, validValue := range ValidConsentStatusValues { + if status == validValue { + return nil + } + } + return fmt.Errorf("invalid value for status. Valid values: %s", strings.Join(ValidConsentStatusValues, ", ")) +} diff --git a/cmd/common/cli/flags.go b/cmd/common/cli/flags.go index 532df883..8b2a4eca 100644 --- a/cmd/common/cli/flags.go +++ b/cmd/common/cli/flags.go @@ -8,6 +8,8 @@ const ( TrustDomainBFlagName = "trustDomainB" TrustDomainDescriptionFlagName = "trustDomainDescription" ConsentStatusFlagName = "status" + ConsentStatusAFlagName = "statusA" + ConsentStatusBFlagName = "statusB" TTLFlagName = "ttl" RelationshipIDFlagName = "relationshipID" JoinTokenFlagName = "joinToken" diff --git a/cmd/harvester/cli/relationship.go b/cmd/harvester/cli/relationship.go index 7b4f4d41..61d6eff4 100644 --- a/cmd/harvester/cli/relationship.go +++ b/cmd/harvester/cli/relationship.go @@ -12,8 +12,6 @@ import ( "github.com/spf13/cobra" ) -var validConsentStatusValues = []string{"approved", "denied", "pending"} - var relationshipCmd = &cobra.Command{ Use: "relationship", Args: cobra.ExactArgs(0), @@ -187,24 +185,15 @@ func init() { fmt.Printf("cannot mark relationshipID flag as required: %v", err) } - listRelationshipCmd.Flags().StringP(cli.ConsentStatusFlagName, "s", "", fmt.Sprintf("Consent status to filter relationships by. Valid values: %s", strings.Join(validConsentStatusValues, ", "))) + listRelationshipCmd.Flags().StringP(cli.ConsentStatusFlagName, "s", "", fmt.Sprintf("Consent status to filter relationships by. Valid values: %s", strings.Join(cli.ValidConsentStatusValues, ", "))) listRelationshipCmd.PreRunE = func(cmd *cobra.Command, args []string) error { status, err := cmd.Flags().GetString(cli.ConsentStatusFlagName) if err != nil { return fmt.Errorf("cannot get status flag: %v", err) } if status != "" { - return validateConsentStatusValue(status) + return cli.ValidateConsentStatusValue(status) } return nil } } - -func validateConsentStatusValue(status string) error { - for _, validValue := range validConsentStatusValues { - if status == validValue { - return nil - } - } - return fmt.Errorf("invalid value for status. Valid values: %s", strings.Join(validConsentStatusValues, ", ")) -} diff --git a/cmd/server/cli/relationship.go b/cmd/server/cli/relationship.go index 66670857..bfdcf280 100644 --- a/cmd/server/cli/relationship.go +++ b/cmd/server/cli/relationship.go @@ -3,10 +3,13 @@ package cli import ( "context" "fmt" + "strings" "github.com/HewlettPackard/galadriel/cmd/common/cli" "github.com/HewlettPackard/galadriel/cmd/server/util" + "github.com/HewlettPackard/galadriel/pkg/common/api" "github.com/HewlettPackard/galadriel/pkg/common/entity" + "github.com/google/uuid" "github.com/spf13/cobra" "github.com/spiffe/go-spiffe/v2/spiffeid" ) @@ -52,10 +55,6 @@ Importantly, the initiation of a federation relationship is a two-party agreemen return fmt.Errorf("cannot get trust domain A flag: %v", err) } - if tdA == "" { - return fmt.Errorf("trust domain A flag is required") - } - trustDomain1, err := spiffeid.TrustDomainFromString(tdA) if err != nil { return err @@ -66,10 +65,6 @@ Importantly, the initiation of a federation relationship is a two-party agreemen return fmt.Errorf("cannot get trust domain B flag: %v", err) } - if tdB == "" { - return fmt.Errorf("trust domain B flag is required") - } - trustDomain2, err := spiffeid.TrustDomainFromString(tdB) if err != nil { return err @@ -98,6 +93,47 @@ var listRelationshipCmd = &cobra.Command{ Long: `The 'list' command allows you to retrieve a list of registered relationships.`, RunE: func(cmd *cobra.Command, args []string) error { + socketPath, err := cmd.Flags().GetString(cli.SocketPathFlagName) + if err != nil { + return fmt.Errorf("cannot get socket path flag: %v", err) + } + + status, err := cmd.Flags().GetString(cli.ConsentStatusFlagName) + if err != nil { + return fmt.Errorf("cannot get consent status flag: %v", err) + } + + trustDomainName, err := cmd.Flags().GetString(cli.TrustDomainFlagName) + if err != nil { + return fmt.Errorf("cannot get trust domain flag: %v", err) + } + + consentStatus := api.ConsentStatus(status) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + client, err := util.NewGaladrielUDSClient(socketPath, nil) + if err != nil { + return err + } + + relationships, err := client.GetRelationships(ctx, consentStatus, trustDomainName) + if err != nil { + return err + } + + if len(relationships) == 0 { + fmt.Println("No relationships found") + return nil + } + + fmt.Println() + for _, r := range relationships { + fmt.Printf("%s\n", r.ConsoleString()) + } + fmt.Println() + return nil }, } @@ -116,6 +152,31 @@ Before deleting a relationship, carefully consider the implications it may have Exercise caution when using this command, as it permanently removes the relationship configuration and may affect the ability of workloads in different trust domains to securely communicate with each other. `, RunE: func(cmd *cobra.Command, args []string) error { + socketPath, err := cmd.Flags().GetString(cli.SocketPathFlagName) + if err != nil { + return fmt.Errorf("cannot get socket path flag: %v", err) + } + + relID, err := getRelationshipIDAndParse(cmd) + if err != nil { + return err + } + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + client, err := util.NewGaladrielUDSClient(socketPath, nil) + if err != nil { + return err + } + + err = client.DeleteRelationshipByID(ctx, relID) + if err != nil { + return err + } + + fmt.Printf("Relationship deleted.\n") + return nil }, } @@ -128,6 +189,44 @@ var updateRelationshipCmd = &cobra.Command{ in the Galadriel Server.`, RunE: func(cmd *cobra.Command, args []string) error { + socketPath, err := cmd.Flags().GetString(cli.SocketPathFlagName) + if err != nil { + return fmt.Errorf("cannot get socket path flag: %v", err) + } + + relID, err := getRelationshipIDAndParse(cmd) + if err != nil { + return err + } + + statusA, err := cmd.Flags().GetString(cli.ConsentStatusAFlagName) + if err != nil { + return fmt.Errorf("cannot get consent status for trust domain A flag: %v", err) + } + + statusB, err := cmd.Flags().GetString(cli.ConsentStatusBFlagName) + if err != nil { + return fmt.Errorf("cannot get consent status for trust domain B flag: %v", err) + } + + consentStatusA := api.ConsentStatus(statusA) + consentStatusB := api.ConsentStatus(statusB) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + client, err := util.NewGaladrielUDSClient(socketPath, nil) + if err != nil { + return err + } + + rel, err := client.PatchRelationshipByID(ctx, relID, consentStatusA, consentStatusB) + if err != nil { + return err + } + + fmt.Printf("Relationship %q updated.\n", rel.ID.UUID.String()) + return nil }, } @@ -140,5 +239,90 @@ func init() { relationshipCmd.AddCommand(updateRelationshipCmd) createRelationshipCmd.Flags().StringP(cli.TrustDomainAFlagName, "a", "", "The name of a SPIFFE trust domain to participate in the relationship.") + err := createRelationshipCmd.MarkFlagRequired(cli.TrustDomainAFlagName) + if err != nil { + fmt.Printf(errMarkFlagAsRequired, cli.TrustDomainAFlagName, err) + } createRelationshipCmd.Flags().StringP(cli.TrustDomainBFlagName, "b", "", "The name of a SPIFFE trust domain to participate in the relationship.") + err = createRelationshipCmd.MarkFlagRequired(cli.TrustDomainBFlagName) + if err != nil { + fmt.Printf(errMarkFlagAsRequired, cli.TrustDomainBFlagName, err) + } + + listRelationshipCmd.Flags().StringP(cli.TrustDomainFlagName, "t", "", "The name of a trust domain to filter relationships by.") + err = listRelationshipCmd.MarkFlagRequired(cli.TrustDomainFlagName) + if err != nil { + fmt.Printf(errMarkFlagAsRequired, cli.TrustDomainFlagName, err) + } + listRelationshipCmd.Flags().StringP(cli.ConsentStatusFlagName, "s", "", fmt.Sprintf("Consent status to filter relationships by. Valid values: %s", strings.Join(cli.ValidConsentStatusValues, ", "))) + err = listRelationshipCmd.MarkFlagRequired(cli.ConsentStatusFlagName) + if err != nil { + fmt.Printf(errMarkFlagAsRequired, cli.ConsentStatusFlagName, err) + } + listRelationshipCmd.PreRunE = func(cmd *cobra.Command, args []string) error { + status, err := cmd.Flags().GetString(cli.ConsentStatusFlagName) + if err != nil { + return fmt.Errorf("cannot get status flag: %v", err) + } + + if status != "" { + return cli.ValidateConsentStatusValue(status) + } + return nil + } + + updateRelationshipCmd.Flags().StringP(cli.RelationshipIDFlagName, "r", "", "The ID of the relationship to be updated.") + err = updateRelationshipCmd.MarkFlagRequired(cli.RelationshipIDFlagName) + if err != nil { + fmt.Printf(errMarkFlagAsRequired, cli.RelationshipIDFlagName, err) + } + updateRelationshipCmd.Flags().StringP(cli.ConsentStatusAFlagName, "a", "", fmt.Sprintf("Trust domain A consent status to update. Valid values: %s", strings.Join(cli.ValidConsentStatusValues, ", "))) + err = updateRelationshipCmd.MarkFlagRequired(cli.ConsentStatusAFlagName) + if err != nil { + fmt.Printf(errMarkFlagAsRequired, cli.ConsentStatusAFlagName, err) + } + updateRelationshipCmd.Flags().StringP(cli.ConsentStatusBFlagName, "b", "", fmt.Sprintf("Trust domain B consent status to update. Valid values: %s", strings.Join(cli.ValidConsentStatusValues, ", "))) + err = updateRelationshipCmd.MarkFlagRequired(cli.ConsentStatusBFlagName) + if err != nil { + fmt.Printf(errMarkFlagAsRequired, cli.ConsentStatusBFlagName, err) + } + updateRelationshipCmd.PreRunE = func(cmd *cobra.Command, args []string) error { + statusA, err := cmd.Flags().GetString(cli.ConsentStatusAFlagName) + if err != nil { + return fmt.Errorf("cannot get consent status A flag: %v", err) + } + if statusA != "" { + return cli.ValidateConsentStatusValue(statusA) + } + + statusB, err := cmd.Flags().GetString(cli.ConsentStatusBFlagName) + if err != nil { + return fmt.Errorf("cannot get consent status B flag: %v", err) + } + if statusB != "" { + return cli.ValidateConsentStatusValue(statusB) + } + + return nil + } + + deleteRelationshipCmd.Flags().StringP(cli.RelationshipIDFlagName, "r", "", "The ID of the relationship to be deleted.") + err = deleteRelationshipCmd.MarkFlagRequired(cli.RelationshipIDFlagName) + if err != nil { + fmt.Printf(errMarkFlagAsRequired, cli.RelationshipIDFlagName, err) + } +} + +func getRelationshipIDAndParse(cmd *cobra.Command) (uuid.UUID, error) { + idStr, err := cmd.Flags().GetString(cli.RelationshipIDFlagName) + if err != nil { + return uuid.Nil, fmt.Errorf("cannot get relationship ID flag: %v", err) + } + + relID, err := uuid.Parse(idStr) + if err != nil { + return uuid.Nil, fmt.Errorf("cannot parse relationship ID: %v", err) + } + + return relID, nil } diff --git a/cmd/server/util/client.go b/cmd/server/util/client.go index 66e8739e..9135d1ac 100644 --- a/cmd/server/util/client.go +++ b/cmd/server/util/client.go @@ -11,7 +11,6 @@ import ( "github.com/HewlettPackard/galadriel/pkg/common/api" "github.com/HewlettPackard/galadriel/pkg/common/entity" "github.com/HewlettPackard/galadriel/pkg/server/api/admin" - "github.com/google/uuid" ) const ( @@ -29,8 +28,9 @@ type GaladrielAPIClient interface { DeleteTrustDomainByName(context.Context, api.TrustDomainName) error UpdateTrustDomainByName(context.Context, api.TrustDomainName, string) (*entity.TrustDomain, error) CreateRelationship(context.Context, *entity.Relationship) (*entity.Relationship, error) - GetRelationshipByID(context.Context, uuid.UUID) (*entity.Relationship, error) - GetRelationships(context.Context, api.ConsentStatus, api.TrustDomainName) (*entity.Relationship, error) + GetRelationships(context.Context, api.ConsentStatus, api.TrustDomainName) ([]*entity.Relationship, error) + PatchRelationshipByID(context.Context, api.UUID, api.ConsentStatus, api.ConsentStatus) (*entity.Relationship, error) + DeleteRelationshipByID(ctx context.Context, relID api.UUID) error GetJoinToken(context.Context, api.TrustDomainName, int32) (*entity.JoinToken, error) } @@ -123,6 +123,7 @@ func (g *galadrielAdminClient) DeleteTrustDomainByName(ctx context.Context, trus func (g *galadrielAdminClient) UpdateTrustDomainByName(ctx context.Context, trustDomainName api.TrustDomainName, description string) (*entity.TrustDomain, error) { payload := api.TrustDomain{Name: trustDomainName, Description: &description} + res, err := g.client.PutTrustDomainByName(ctx, trustDomainName, payload) if err != nil { return nil, fmt.Errorf(errorRequestFailed, err) @@ -185,10 +186,10 @@ func (g *galadrielAdminClient) CreateRelationship(ctx context.Context, rel *enti return relationship, nil } -func (g *galadrielAdminClient) GetRelationships(ctx context.Context, consentStatus api.ConsentStatus, trustDomainName api.TrustDomainName) (*entity.Relationship, error) { - payload := &admin.GetRelationshipsParams{ConsentStatus: &consentStatus, TrustDomainName: &trustDomainName} +func (g *galadrielAdminClient) PatchRelationshipByID(ctx context.Context, relID api.UUID, statusA api.ConsentStatus, statusB api.ConsentStatus) (*entity.Relationship, error) { + payload := admin.PatchRelationshipByIDRequest{ConsentStatusA: statusA, ConsentStatusB: statusB} - res, err := g.client.GetRelationships(ctx, payload) + res, err := g.client.PatchRelationshipByID(ctx, relID, payload) if err != nil { return nil, fmt.Errorf(errorRequestFailed, err) } @@ -207,8 +208,25 @@ func (g *galadrielAdminClient) GetRelationships(ctx context.Context, consentStat return relationship, nil } -func (g *galadrielAdminClient) GetRelationshipByID(ctx context.Context, relID uuid.UUID) (*entity.Relationship, error) { - res, err := g.client.GetRelationshipByID(ctx, relID) +func (g *galadrielAdminClient) DeleteRelationshipByID(ctx context.Context, relID api.UUID) error { + res, err := g.client.DeleteRelationshipByID(ctx, relID) + if err != nil { + return fmt.Errorf(errorRequestFailed, err) + } + defer res.Body.Close() + + _, err = httputil.ReadResponse(res) + if err != nil { + return err + } + + return nil +} + +func (g *galadrielAdminClient) GetRelationships(ctx context.Context, status api.ConsentStatus, trustDomainName api.TrustDomainName) ([]*entity.Relationship, error) { + payload := &admin.GetRelationshipsParams{ConsentStatus: &status, TrustDomainName: &trustDomainName} + + res, err := g.client.GetRelationships(ctx, payload) if err != nil { return nil, fmt.Errorf(errorRequestFailed, err) } @@ -219,12 +237,21 @@ func (g *galadrielAdminClient) GetRelationshipByID(ctx context.Context, relID uu return nil, err } - relationship, err := unmarshalJSONToRelationship(body) - if err != nil { - return nil, err + var relationships []*api.Relationship + if err := json.Unmarshal(body, &relationships); err != nil { + return nil, fmt.Errorf(errUnmarshalRelationships, err) } - return relationship, nil + rels := make([]*entity.Relationship, 0, len(relationships)) + for i, r := range relationships { + rel, err := r.ToEntity() + if err != nil { + return nil, fmt.Errorf("failed to convert relationship %d: %v", i, err) + } + rels = append(rels, rel) + } + + return rels, nil } func (g *galadrielAdminClient) GetJoinToken(ctx context.Context, trustDomainName api.TrustDomainName, ttl int32) (*entity.JoinToken, error) { diff --git a/pkg/common/api/schemas.gen.go b/pkg/common/api/schemas.gen.go index abbb9f5b..7ccb4e3d 100644 --- a/pkg/common/api/schemas.gen.go +++ b/pkg/common/api/schemas.gen.go @@ -42,6 +42,12 @@ type ConsentStatus string // Date defines model for Date. type Date = openapi_types.Date +// DeleteResponse defines model for DeleteResponse. +type DeleteResponse struct { + Code int64 `json:"code"` + Message string `json:"message"` +} + // JWT defines model for JWT. type JWT = string @@ -98,62 +104,62 @@ type UUID = openapi_types.UUID // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/9RZ6ZLbOJJ+FQV3fsy0qixeOlgRHRPgIYmUeEikLja9FTzASxRI8ZToqHffoOS2q+zy", - "uMexG7vrP4YSiQ+ZROLLTNQnzE1PWYogKgvs6RNWuCE82bchyCIhz9O8G9ueF5VRiuxEy9MM5mUEC+zJ", - "t5MCPmDZK1GH58Hufz/NT3aJPWERKkc09oCd7Et0qk7Y05BhHrBThO6/CBx/wMprBu+qMIA59vKAnWBR", - "2MENCV7sU5Z086DnQLsqI79KerCzrfen2sPX/Yoyj1Bw33AJUVCG2BP5apPP8y8vD1gOz1WUQw97+uNu", - "99d9P37RT50YumVnE1shL4F8FMCi7AzzYOHmUdZ9GOwJc+wCjugeRB2S19Pn4JEcjnreTb2X+r0yhD3n", - "BoE9vHLKx+nhyBvb0MMnEzhmCEiPCNylXNL2RpTtQ3oESTgej5nJxPcclyHHuE8MocuMCcKhSew7zx4w", - "rjsPP3LtEnKhHaHvrd1/GOJMz/2q13M7xV6Eepog9z5/zdd2Pnb/WGEmKj1OWBviVOSAIdykFpJFkZ+1", - "HAcCNQCNyIJAFI16Wg+FKXes3YZfHaRFaoph7SpgJSzZFWhmsXCQ2cMMEBvBQuAia/ZuiJt7qTR36+yw", - "XyfLnRLKLL3nDbGV+cNV5sVGjsFFSdJOhsv84aIad5mFlCRt5rxgy2xww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oug0yiLxu3cd3gHi7/KbsJXGSeMSJRwp/bYfX6b2tcol3", - "4KSd8RYNXqXQmbmRGkniphUJJRILEa2HLieOxGO233IS8wFepdbbiZEaiRc5lnHFOFAqf2zEqImc07Q0", - "9Ztybc/oYD1jkk7esZwYpxfFEEg5locyL1791QfdTxaXZi3pMlwspuTKoP0mk6HkUyNNPY6u0vbZ9lZF", - "0Qzd1+7FTfnWOxpnRg9YZpclzLsK9j//sB9b8Gjij4xlPT5/7P/Tsj68J/v7t8J//PNv752glEbISI8Q", - "vf1elG9Phv6IfhyOifEjPRyRjw7lu4+ky4wofzSyfXv02vCqiry3llPf2I0/Mvaj//HT5OXxy5j+C2OC", - "fHnXcM0OoFKdHJh/X+cbIeyh21zXgkQlPBW9Mu0VxyjrOdBPc9grSjsvIxR0cjdNEuiWt14lh0WVlL0C", - "lh+wVw3bu+1aZ4IetfBugG9XSdl1XQ8/tKZ4Y04OyypHH950ifjrJvG9PdcwsTvcIoyyf7dJzaFdQu/Z", - "Ln900wx88kThTzhufnvnHsvo9FcuXuR12H/LoY89Yf8x+NpnDz432YPNRuQ7zTKvivLZS092hJ7tZ/fO", - "JD9b/ZZwvof55f2RfYI/W2p0S/jbCqVT/xbF+e/xwvlVL5xf9aLKvP/hyPjm3eFGFq/i8Y0J7x3qe5/o", - "hzH0w2N5731D18TpVBD5t54XWeT78GkweI00aNL8mKS29xx5EJWRH8H8548w9OSde6JHAbLLKoc/fVIp", - "/tT8F68p9mxk7inb9PujMhhc17zprXWllCkmac2dcjX3a8nkCemwI4wvvzkz9vbS1dwN8e0sKc2tgh92", - "RKMZAqG0wlU2No1qbE7mPmzsvZTcdAz8ovIBqRguIfNHQkJS6JzWtWPgVznuGobN7+9x9S3k7g9J3/t7", - "P4DeTeezc70I9SRdVd57kflkdVny2a7KMM2jjtss7OmPTxYGL1mUw+LZLi3sycKI0YQeEiOKpizswcKO", - "8PocebcZ4Bmmi7vjtmBG7iioVxeJHa08YcRf9Urx65t+VjlJ5D4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OPIjK", + "yI9g/vN8Rk/eOSd6FCC7rHL403em4g/Nf/LEZM9G5p6yTb8/KoPBdc2b3lpXSpliktbcKVdzv5ZMnpAO", + "O8L48s2ZsbeXruZuiG9nSWluFfywIxrNEAilFa6ysWlUY3My92Fj76XkpmPgF5UPSMVwCZk/EhKSQue0", + "rh0Dv8pxd4va/PYeV99C7v669r2/9w3o3XQ+O9eLUE/SVeW9Z6pPVpcln+2qDNM86rjNwp5+/2Rh8JJF", + "OSye7dLCniyMGE3oITGiaMrCHizsCK/PkXfrAZ5hurg7bgtm5I6CenWR2NHKE0b8Va8Uv77pZ5WTRO7z", + "EV5vY+TpsRGaw7y71bUxzoHVQfzc5sHK5VcBEC6EZq4bX6B4s1DPpMzi6lDb+U7R5nY2U/zTUJgOiLTZ", + "D5HIK6fYiJyBcvXHHORqfekKLoUfMtupgRMs5xO3IEO+Jbr7Mvby8CP/JsT3/vnB1uZd2wAHuz3OyJ3P", + "ULtydjmtvb0PcIX9Vf9yXo8jN0dnfYME8goJKa18lp8tnVKUY2m6nS3gXC0XxrA6J+xgYUwUkhrui2If", + "GMvVWg7bDPCuLNObwSFx6/R6nA9Pwc2/jw8WlkM/h0X4HEbo7iF+A1rAcwWRC5/vKfTWM771vD6aN3Hp", + "ERb28sMAvHPev2HSfHMeXk9yPxN3D3tlaJe9HGY57LjsRgXwXmLv/1RR/aoY+2vv77/fa0P7sf3Y+/vf", + "/v5uiRXaeQ2LEubPdzr8E3npC5v+S7XAL6atFDmpnXcXrWfnC7n81MZnHvo/S3s3Z3+c/d7LUd/6/gbt", + "7Rh8uAfJBzc9/WJGuu3F/6s7wMsDVkC3yqPyqncbfD+wX4O2SxGdxIF2DvPpHzC7u+HD/Yewztq996v1", + "sCwz7KUzHiE/xZ5QlSQPWJpBZGcR9oRhN5fC4t7z8l8BAAD//7tN79hhGwAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/pkg/common/api/schemas.yaml b/pkg/common/api/schemas.yaml index f2beb96c..998b87c1 100644 --- a/pkg/common/api/schemas.yaml +++ b/pkg/common/api/schemas.yaml @@ -188,8 +188,25 @@ components: format: date maxLength: 21 example: "2021-01-30" + DeleteResponse: + type: object + additionalProperties: false + required: + - code + - message + properties: + message: + type: string + format: string + maxLength: 200 + example: "Entity deleted message" + code: + type: integer + format: int64 + maximum: 599 + minimum: 100 securitySchemes: harvester_auth: type: "http" scheme: "bearer" - bearerFormat: "JWT" \ No newline at end of file + bearerFormat: "JWT" diff --git a/pkg/common/telemetry/names.go b/pkg/common/telemetry/names.go index 2166acf2..62a90b7f 100644 --- a/pkg/common/telemetry/names.go +++ b/pkg/common/telemetry/names.go @@ -56,4 +56,7 @@ const ( // TrustDomain tags the name of some trust domain TrustDomain = "trust_domain" + + //Relationship tags the name of a relationship + Relationship = "relationship" ) diff --git a/pkg/server/api/admin/admin.gen.go b/pkg/server/api/admin/admin.gen.go index 518d8bd7..e09dfe33 100644 --- a/pkg/server/api/admin/admin.gen.go +++ b/pkg/server/api/admin/admin.gen.go @@ -22,11 +22,22 @@ import ( "github.com/labstack/echo/v4" ) +// DeleteResponse defines model for DeleteResponse. +type DeleteResponse struct { + Schema *externalRef0.DeleteResponse `json:"schema,omitempty"` +} + // JoinTokenResponse defines model for JoinTokenResponse. type JoinTokenResponse struct { Token externalRef0.JoinToken `json:"token"` } +// PatchRelationshipByIDRequest defines model for PatchRelationshipByIDRequest. +type PatchRelationshipByIDRequest struct { + ConsentStatusA externalRef0.ConsentStatus `json:"consent_status_a"` + ConsentStatusB externalRef0.ConsentStatus `json:"consent_status_b"` +} + // PutRelationshipRequest defines model for PutRelationshipRequest. type PutRelationshipRequest struct { TrustDomainAName externalRef0.TrustDomainName `json:"trust_domain_a_name"` @@ -44,14 +55,16 @@ type Default = externalRef0.ApiError // GetRelationshipsParams defines parameters for GetRelationships. type GetRelationshipsParams struct { - // ConsentStatus relationship status from a Trust Domain perspective, + // ConsentStatus relationship status from a Trust Domain perspective. ConsentStatus *externalRef0.ConsentStatus `form:"consentStatus,omitempty" json:"consentStatus,omitempty"` - // TrustDomainName TrustDomain + // TrustDomainName Trust Domain name that participates in a relationship. TrustDomainName *externalRef0.TrustDomainName `form:"trustDomainName,omitempty" json:"trustDomainName,omitempty"` - // PageSize TrustDomain - PageSize *externalRef0.PageSize `form:"pageSize,omitempty" json:"pageSize,omitempty"` + // PageSize Number of items in each page. + PageSize *externalRef0.PageSize `form:"pageSize,omitempty" json:"pageSize,omitempty"` + + // PageNumber Number of pages. PageNumber *externalRef0.PageNumber `form:"pageNumber,omitempty" json:"pageNumber,omitempty"` } @@ -64,6 +77,9 @@ type GetJoinTokenParams struct { // PutRelationshipJSONRequestBody defines body for PutRelationship for application/json ContentType. type PutRelationshipJSONRequestBody = PutRelationshipRequest +// PatchRelationshipByIDJSONRequestBody defines body for PatchRelationshipByID for application/json ContentType. +type PatchRelationshipByIDJSONRequestBody = PatchRelationshipByIDRequest + // PutTrustDomainJSONRequestBody defines body for PutTrustDomain for application/json ContentType. type PutTrustDomainJSONRequestBody = PutTrustDomainRequest @@ -151,9 +167,17 @@ type ClientInterface interface { PutRelationship(ctx context.Context, body PutRelationshipJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // DeleteRelationshipByID request + DeleteRelationshipByID(ctx context.Context, relationshipID externalRef0.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + // GetRelationshipByID request GetRelationshipByID(ctx context.Context, relationshipID externalRef0.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + // PatchRelationshipByID request with any body + PatchRelationshipByIDWithBody(ctx context.Context, relationshipID externalRef0.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PatchRelationshipByID(ctx context.Context, relationshipID externalRef0.UUID, body PatchRelationshipByIDJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // GetJoinToken request GetJoinToken(ctx context.Context, trustDomainName externalRef0.TrustDomainName, params *GetJoinTokenParams, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -213,6 +237,18 @@ func (c *Client) PutRelationship(ctx context.Context, body PutRelationshipJSONRe return c.Client.Do(req) } +func (c *Client) DeleteRelationshipByID(ctx context.Context, relationshipID externalRef0.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteRelationshipByIDRequest(c.Server, relationshipID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) GetRelationshipByID(ctx context.Context, relationshipID externalRef0.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewGetRelationshipByIDRequest(c.Server, relationshipID) if err != nil { @@ -225,6 +261,30 @@ func (c *Client) GetRelationshipByID(ctx context.Context, relationshipID externa return c.Client.Do(req) } +func (c *Client) PatchRelationshipByIDWithBody(ctx context.Context, relationshipID externalRef0.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPatchRelationshipByIDRequestWithBody(c.Server, relationshipID, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PatchRelationshipByID(ctx context.Context, relationshipID externalRef0.UUID, body PatchRelationshipByIDJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPatchRelationshipByIDRequest(c.Server, relationshipID, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) GetJoinToken(ctx context.Context, trustDomainName externalRef0.TrustDomainName, params *GetJoinTokenParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewGetJoinTokenRequest(c.Server, trustDomainName, params) if err != nil { @@ -458,6 +518,40 @@ func NewPutRelationshipRequestWithBody(server string, contentType string, body i return req, nil } +// NewDeleteRelationshipByIDRequest generates requests for DeleteRelationshipByID +func NewDeleteRelationshipByIDRequest(server string, relationshipID externalRef0.UUID) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "relationshipID", runtime.ParamLocationPath, relationshipID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/relationships/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewGetRelationshipByIDRequest generates requests for GetRelationshipByID func NewGetRelationshipByIDRequest(server string, relationshipID externalRef0.UUID) (*http.Request, error) { var err error @@ -492,6 +586,53 @@ func NewGetRelationshipByIDRequest(server string, relationshipID externalRef0.UU return req, nil } +// NewPatchRelationshipByIDRequest calls the generic PatchRelationshipByID builder with application/json body +func NewPatchRelationshipByIDRequest(server string, relationshipID externalRef0.UUID, body PatchRelationshipByIDJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPatchRelationshipByIDRequestWithBody(server, relationshipID, "application/json", bodyReader) +} + +// NewPatchRelationshipByIDRequestWithBody generates requests for PatchRelationshipByID with any type of body +func NewPatchRelationshipByIDRequestWithBody(server string, relationshipID externalRef0.UUID, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "relationshipID", runtime.ParamLocationPath, relationshipID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/relationships/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PATCH", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewGetJoinTokenRequest generates requests for GetJoinToken func NewGetJoinTokenRequest(server string, trustDomainName externalRef0.TrustDomainName, params *GetJoinTokenParams) (*http.Request, error) { var err error @@ -777,9 +918,17 @@ type ClientWithResponsesInterface interface { PutRelationshipWithResponse(ctx context.Context, body PutRelationshipJSONRequestBody, reqEditors ...RequestEditorFn) (*PutRelationshipResponse, error) + // DeleteRelationshipByID request + DeleteRelationshipByIDWithResponse(ctx context.Context, relationshipID externalRef0.UUID, reqEditors ...RequestEditorFn) (*DeleteRelationshipByIDResponse, error) + // GetRelationshipByID request GetRelationshipByIDWithResponse(ctx context.Context, relationshipID externalRef0.UUID, reqEditors ...RequestEditorFn) (*GetRelationshipByIDResponse, error) + // PatchRelationshipByID request with any body + PatchRelationshipByIDWithBodyWithResponse(ctx context.Context, relationshipID externalRef0.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PatchRelationshipByIDResponse, error) + + PatchRelationshipByIDWithResponse(ctx context.Context, relationshipID externalRef0.UUID, body PatchRelationshipByIDJSONRequestBody, reqEditors ...RequestEditorFn) (*PatchRelationshipByIDResponse, error) + // GetJoinToken request GetJoinTokenWithResponse(ctx context.Context, trustDomainName externalRef0.TrustDomainName, params *GetJoinTokenParams, reqEditors ...RequestEditorFn) (*GetJoinTokenResponse, error) @@ -849,6 +998,28 @@ func (r PutRelationshipResponse) StatusCode() int { return 0 } +type DeleteRelationshipByIDResponse struct { + Body []byte + HTTPResponse *http.Response + JSONDefault *externalRef0.ApiError +} + +// Status returns HTTPResponse.Status +func (r DeleteRelationshipByIDResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteRelationshipByIDResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type GetRelationshipByIDResponse struct { Body []byte HTTPResponse *http.Response @@ -872,6 +1043,28 @@ func (r GetRelationshipByIDResponse) StatusCode() int { return 0 } +type PatchRelationshipByIDResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *externalRef0.Relationship +} + +// Status returns HTTPResponse.Status +func (r PatchRelationshipByIDResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PatchRelationshipByIDResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type GetJoinTokenResponse struct { Body []byte HTTPResponse *http.Response @@ -1035,6 +1228,15 @@ func (c *ClientWithResponses) PutRelationshipWithResponse(ctx context.Context, b return ParsePutRelationshipResponse(rsp) } +// DeleteRelationshipByIDWithResponse request returning *DeleteRelationshipByIDResponse +func (c *ClientWithResponses) DeleteRelationshipByIDWithResponse(ctx context.Context, relationshipID externalRef0.UUID, reqEditors ...RequestEditorFn) (*DeleteRelationshipByIDResponse, error) { + rsp, err := c.DeleteRelationshipByID(ctx, relationshipID, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteRelationshipByIDResponse(rsp) +} + // GetRelationshipByIDWithResponse request returning *GetRelationshipByIDResponse func (c *ClientWithResponses) GetRelationshipByIDWithResponse(ctx context.Context, relationshipID externalRef0.UUID, reqEditors ...RequestEditorFn) (*GetRelationshipByIDResponse, error) { rsp, err := c.GetRelationshipByID(ctx, relationshipID, reqEditors...) @@ -1044,6 +1246,23 @@ func (c *ClientWithResponses) GetRelationshipByIDWithResponse(ctx context.Contex return ParseGetRelationshipByIDResponse(rsp) } +// PatchRelationshipByIDWithBodyWithResponse request with arbitrary body returning *PatchRelationshipByIDResponse +func (c *ClientWithResponses) PatchRelationshipByIDWithBodyWithResponse(ctx context.Context, relationshipID externalRef0.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PatchRelationshipByIDResponse, error) { + rsp, err := c.PatchRelationshipByIDWithBody(ctx, relationshipID, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePatchRelationshipByIDResponse(rsp) +} + +func (c *ClientWithResponses) PatchRelationshipByIDWithResponse(ctx context.Context, relationshipID externalRef0.UUID, body PatchRelationshipByIDJSONRequestBody, reqEditors ...RequestEditorFn) (*PatchRelationshipByIDResponse, error) { + rsp, err := c.PatchRelationshipByID(ctx, relationshipID, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePatchRelationshipByIDResponse(rsp) +} + // GetJoinTokenWithResponse request returning *GetJoinTokenResponse func (c *ClientWithResponses) GetJoinTokenWithResponse(ctx context.Context, trustDomainName externalRef0.TrustDomainName, params *GetJoinTokenParams, reqEditors ...RequestEditorFn) (*GetJoinTokenResponse, error) { rsp, err := c.GetJoinToken(ctx, trustDomainName, params, reqEditors...) @@ -1180,6 +1399,32 @@ func ParsePutRelationshipResponse(rsp *http.Response) (*PutRelationshipResponse, return response, nil } +// ParseDeleteRelationshipByIDResponse parses an HTTP response from a DeleteRelationshipByIDWithResponse call +func ParseDeleteRelationshipByIDResponse(rsp *http.Response) (*DeleteRelationshipByIDResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteRelationshipByIDResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest externalRef0.ApiError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSONDefault = &dest + + } + + return response, nil +} + // ParseGetRelationshipByIDResponse parses an HTTP response from a GetRelationshipByIDWithResponse call func ParseGetRelationshipByIDResponse(rsp *http.Response) (*GetRelationshipByIDResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -1213,6 +1458,32 @@ func ParseGetRelationshipByIDResponse(rsp *http.Response) (*GetRelationshipByIDR return response, nil } +// ParsePatchRelationshipByIDResponse parses an HTTP response from a PatchRelationshipByIDWithResponse call +func ParsePatchRelationshipByIDResponse(rsp *http.Response) (*PatchRelationshipByIDResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PatchRelationshipByIDResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest externalRef0.Relationship + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + // ParseGetJoinTokenResponse parses an HTTP response from a GetJoinTokenWithResponse call func ParseGetJoinTokenResponse(rsp *http.Response) (*GetJoinTokenResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -1406,15 +1677,21 @@ func ParsePutTrustDomainByNameResponse(rsp *http.Response) (*PutTrustDomainByNam // ServerInterface represents all server handlers. type ServerInterface interface { - // Get relationships + // Get the relationships based on the trust domain name and/or consent statuses. // (GET /relationships) GetRelationships(ctx echo.Context, params GetRelationshipsParams) error // Create a relationship request between two Trust Domains // (PUT /relationships) PutRelationship(ctx echo.Context) error + // Deletes a specific relationship + // (DELETE /relationships/{relationshipID}) + DeleteRelationshipByID(ctx echo.Context, relationshipID externalRef0.UUID) error // Get a specific relationship // (GET /relationships/{relationshipID}) GetRelationshipByID(ctx echo.Context, relationshipID externalRef0.UUID) error + // Update a specific relationship + // (PATCH /relationships/{relationshipID}) + PatchRelationshipByID(ctx echo.Context, relationshipID externalRef0.UUID) error // Get a join token for a specific Trust Domain // (GET /trust-domain/{trustDomainName}/join-token) GetJoinToken(ctx echo.Context, trustDomainName externalRef0.TrustDomainName, params GetJoinTokenParams) error @@ -1488,6 +1765,22 @@ func (w *ServerInterfaceWrapper) PutRelationship(ctx echo.Context) error { return err } +// DeleteRelationshipByID converts echo context to params. +func (w *ServerInterfaceWrapper) DeleteRelationshipByID(ctx echo.Context) error { + var err error + // ------------- Path parameter "relationshipID" ------------- + var relationshipID externalRef0.UUID + + err = runtime.BindStyledParameterWithLocation("simple", false, "relationshipID", runtime.ParamLocationPath, ctx.Param("relationshipID"), &relationshipID) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter relationshipID: %s", err)) + } + + // Invoke the callback with all the unmarshalled arguments + err = w.Handler.DeleteRelationshipByID(ctx, relationshipID) + return err +} + // GetRelationshipByID converts echo context to params. func (w *ServerInterfaceWrapper) GetRelationshipByID(ctx echo.Context) error { var err error @@ -1504,6 +1797,22 @@ func (w *ServerInterfaceWrapper) GetRelationshipByID(ctx echo.Context) error { return err } +// PatchRelationshipByID converts echo context to params. +func (w *ServerInterfaceWrapper) PatchRelationshipByID(ctx echo.Context) error { + var err error + // ------------- Path parameter "relationshipID" ------------- + var relationshipID externalRef0.UUID + + err = runtime.BindStyledParameterWithLocation("simple", false, "relationshipID", runtime.ParamLocationPath, ctx.Param("relationshipID"), &relationshipID) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter relationshipID: %s", err)) + } + + // Invoke the callback with all the unmarshalled arguments + err = w.Handler.PatchRelationshipByID(ctx, relationshipID) + return err +} + // GetJoinToken converts echo context to params. func (w *ServerInterfaceWrapper) GetJoinToken(ctx echo.Context) error { var err error @@ -1625,7 +1934,9 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.GET(baseURL+"/relationships", wrapper.GetRelationships) router.PUT(baseURL+"/relationships", wrapper.PutRelationship) + router.DELETE(baseURL+"/relationships/:relationshipID", wrapper.DeleteRelationshipByID) router.GET(baseURL+"/relationships/:relationshipID", wrapper.GetRelationshipByID) + router.PATCH(baseURL+"/relationships/:relationshipID", wrapper.PatchRelationshipByID) router.GET(baseURL+"/trust-domain/:trustDomainName/join-token", wrapper.GetJoinToken) router.GET(baseURL+"/trust-domains", wrapper.ListTrustDomains) router.PUT(baseURL+"/trust-domains", wrapper.PutTrustDomain) @@ -1638,42 +1949,45 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/9xab1fayPd/K3Pmtw92ewIJIFQ5Zx+goKVVq0K3rdUfZ0huYDTJxJkJiJ689++ZScQE", - "giJr3e0+asxk5v75fO69cy+9xzbzQxZAIAVu3mMOImSBAP1HG1wSeVI92iyQEOhHEoYetYmkLDCvBAvU", - "O2GPwSfq6TcOLm7i/zMfzzWTVWG2QtrhnHEcx7GBHRA2p6E6BzexXkCtky56VEF9le5VR8+3KyUch6qd", - "xDvhLAQuqVLZJZ4AA4eZV0p1B9S/LuM+kbiJaSAbW9jAPrmlfuTjZn1nx8A+DZK/KpZlYDkLIfkURsBx", - "bGAfhCAjfRLcEj/01HoLDYFEkrqRh0Bb8PCZ8ShPSE6DUSLwEIKRHONmNSMkXVfWcriJKAcHN38kej/K", - "vZx/z4ZXYEul057yUyB7kshI2wqBsuCHwoizCThYuTmg+iGEwFFyLpcEG/gjo0GfXUOQN6/mku2629gq", - "1d9X3pe26o1qaVhz7VLV3mnU3EaDuKSRtTSKqJO3s9YwcEikBK5A/v8fVmmHlNzL++24NH/eWuO5Uo1/", - "w08pfpay5oXkkA9GP8XbR+8sYpRsL4LmhIzgOPKHoOma53p/DCjQa4i5iErwBZIMiWsaoiG4jAMSknBJ", - "g5F6bzPPA1siOQYVHJEnkQBZxhnOFjJWqdCjd5AokIZy1TJWaiNy6nCQEQ/KuUCxsnFSKDOSZ+Dp5CDG", - "NDyDmwiEfCkoPBJy4DCf0GBABgHx4TmI+mpLW+84Vp/HRv6U4WanLMJdoFixoEJKRDIjYDPX5KDLhqo+", - "GSVKIDkmEnEIOaj0oIkDgaRyhr5tkpgM/BrOW+mXLGFemts5EAnOgMi8N6pWtVKyKqWa1be2mzWraVnn", - "WcsdIqEkqYYva3ylwHbqPGf5ly/d9hLjyMBOsvNzu/NJfPmYjeW/Tty8ihXDTa0YbmpFFDo/mR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uXeBr", + "mPapa0Zabu/csZ13d3K74TSG49PbDzuNU3ev0Z52o2NvbL4Po4FPnf41TM2co/3ryd7k2/uP/Lxzd2Xv", + "tk6/dZLnduvUaZ8OW3u31ZPzs4m3V2+fy083taMd+9PmyRdvIO8ECQ+OvWBzb9+q8snXTdZpHwdXPTqw", + "jqfeu13YHXcPnT2nbn8LyWDcGgwP3285sjZq31Vbf/11gWelZfZtVRft84Z/k7ZDeq1v5O76oPbF265/", + "UQe3wZn71WvZxzvr2ifa3SvqCHbT/cz2alOofuCRt9M+OByoztHVh/2/Dz7C+0/qY28zuvF3rI+9reNa", + "ffOrlF+HvcPTs6PRXdhqO0dHG5+tb74z5tPr95vB0Nh3WbrAAjwBctQfURZbaBtFpd4MmQP9uDQzI+/M", + "SDpZzWvlVi/wDC9LwJgFfsJt5G127tTp43f05/dW+dycKe4u0Z9//Fl4phgRMQapQPRjgliBqef88qLd", + "cU0i52zAidBHyv5gTi7PrpHw0D+2ESSl4bL9oIi187ZntDUwqMRJUnF4sCZHm1j8Uode7V3KPP7QHSKO", + "iWOcTPiAqlE00L4VPm7ikVKhbFrW0LzWfrLew8QHpU6Ic02Eaw2JT1xBwV+AJD54GEJdEGMQ6IgwMoRA", + "47B10kEyBId6SUtKHxR96kByBk/UaYXEGQGqVeyMSk3LmkwmFWJGK1wMrWSqtA47u3vH3b1yrWJXRiow", + "aimqTGgWFGq5AWVGlzL6FALTT3UjawxCxlZUK3alWjXACYGRkOoYV+xKHZsojQzfWSJVcps3QzBu1aRo", + "BjquVgAyhzlplhAkAAVC6v0458H0qig+JiJP8ACRZOOPsxuFILQzFR2D9qOma3wTgZg+AKf5cNhMysnS", + "is2fhTPtQi8irYYWFRNuSISiDg2JAqnLEoLSpizTUeUAu6qWBQelvJ7HuX4JZQiIM0IhGS51WfjQAFlV", + "j3nH5EkF9LLyKZlJ3+clUpMps9llKdsKrtn2i9rAxjvPScycLx/7gUQIMi3qEXcjxwEpvchHczzEdDHv", + "UxeJmxtiPTS0TWM5CgIipjGakqZWClJoQCS4iDMzpNKlgElPwlyLC5TAIQFVHA9FhhqEOAvRy1kJh1EB", + "mHOdGRxvWiDVDnenr9Z7X9L/mWU3SSUimP2foV894m8W4V2z2+fYAyVuRgNQEwCG1IRn6FA+EctZKcfV", + "1n36b6c9i49aPihYDPlDLzzbn3yOxTttDXudjrl8MQSg95BH/GeVwfkYr8oJcYm4jA3eJHaxryQi830+", + "E8Un8bbK5vlLev5XBqOm23WCGRLljAros6jV/5MH9AfQ+1MXHrOE5X+qPMrkxGdzAlsjLTQPm825nLTN", + "7nPF38y64pSV5xdsyyjh8XLtmdTJVKpJeVmQNYs16Hpps0JN2qMBlBUvH9IxoN97vcM/dFkqweHMlcjj", + "wiS6dgNSiYWFVbPyn9RyDvt6w7ZLmev0ei19PbfV2LDtp28FfyivLV7GvjW5PfrauD+V1unsSaW1VhnF", + "6beY08vPgYdUpm+uJP6BXk038d7On9pCRHw/U4GnC7OMQ5+qsdP6/7ASu+AasZB8q28VlrjydV8hEi3X", + "TSdyOh7Lw7GQyov8/HydnDJxZ5qQ6eoUzf4Biv7J6uXVYrW8XP7XBOAXJsJc1bxqSFdgw18ppK9P2rlo", + "zv51ibNYWq9I3XoV096O0yHbyPe5Q/wRl6oiJ2Q4BFGh3CIhtcZ1rEOVLJrPohbK3DfPt+MkezJvFwvd", + "VrZ/Q2XStksu5cyIPteRByn74CaOzJzznuz4JKpkDxqLupwVSE2VfQMeMRcpnuuwVx4FpEq+2eXsfwEA", + "AP//NrPyPYgrAAA=", } // 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 7610b648..e3b30cfe 100644 --- a/pkg/server/api/admin/admin.yaml +++ b/pkg/server/api/admin/admin.yaml @@ -128,29 +128,30 @@ paths: operationId: GetRelationships tags: - Relationships - summary: Get relationships + summary: Get the relationships based on the trust domain name and/or consent statuses. parameters: - name: consentStatus in: query schema: $ref: '../../../common/api/schemas.yaml#/components/schemas/ConsentStatus' - description: relationship status from a Trust Domain perspective, + description: relationship status from a Trust Domain perspective. - name: trustDomainName in: query schema: $ref: '../../../common/api/schemas.yaml#/components/schemas/TrustDomainName' - description: TrustDomain + description: Trust Domain name that participates in a relationship. - name: pageSize required: false in: query schema: $ref: '../../../common/api/schemas.yaml#/components/schemas/PageSize' - description: TrustDomain + description: Number of items in each page. - name: pageNumber in: query required: false schema: $ref: '../../../common/api/schemas.yaml#/components/schemas/PageNumber' + description: Number of pages. responses: '200': description: Successful operation @@ -205,6 +206,48 @@ paths: $ref: '../../../common/api/schemas.yaml#/components/schemas/Relationship' default: $ref: '#/components/responses/Default' + delete: + operationId: DeleteRelationshipByID + tags: + - Relationships + summary: Deletes a specific relationship + parameters: + - name: relationshipID + in: path + description: ID of the Relationship + required: true + schema: + $ref: '../../../common/api/schemas.yaml#/components/schemas/UUID' + responses: + '200': + description: Successful operation + default: + $ref: '#/components/responses/Default' + patch: + operationId: PatchRelationshipByID + tags: + - Relationships + summary: Update a specific relationship + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PatchRelationshipByIDRequest' + parameters: + - name: relationshipID + in: path + description: ID of the Relationship + required: true + schema: + $ref: '../../../common/api/schemas.yaml#/components/schemas/UUID' + responses: + '200': + description: Successful operation + content: + application/json: + schema: + $ref: '../../../common/api/schemas.yaml#/components/schemas/Relationship' + /trust-domain/{trustDomainName}/join-token: get: @@ -272,6 +315,17 @@ components: example: "Trust domain that represent the entity X" name: $ref: '../../../common/api/schemas.yaml#/components/schemas/TrustDomainName' + PatchRelationshipByIDRequest: + type: object + additionalProperties: false + required: + - consent_status_a + - consent_status_b + properties: + consent_status_a: + $ref: '../../../common/api/schemas.yaml#/components/schemas/ConsentStatus' + consent_status_b: + $ref: '../../../common/api/schemas.yaml#/components/schemas/ConsentStatus' JoinTokenResponse: type: object additionalProperties: false @@ -280,3 +334,9 @@ components: properties: token: $ref: ../../../common/api/schemas.yaml#/components/schemas/JoinToken + DeleteResponse: + type: object + additionalProperties: false + properties: + schema: + $ref: ../../../common/api/schemas.yaml#/components/schemas/DeleteResponse diff --git a/pkg/server/api/admin/helper.go b/pkg/server/api/admin/helper.go index c1177548..6ebc8ac3 100644 --- a/pkg/server/api/admin/helper.go +++ b/pkg/server/api/admin/helper.go @@ -40,3 +40,22 @@ func (td *PutTrustDomainRequest) ToEntity() (*entity.TrustDomain, error) { Description: description, }, nil } + +func (r *PatchRelationshipByIDRequest) ToEntity() (*entity.Relationship, error) { + var ( + consentStatusA = "" + consentStatusB = "" + ) + + if r.ConsentStatusA != "" { + consentStatusA = string(r.ConsentStatusA) + } + if r.ConsentStatusB != "" { + consentStatusB = string(r.ConsentStatusB) + } + + return &entity.Relationship{ + TrustDomainAConsent: entity.ConsentStatus(consentStatusA), + TrustDomainBConsent: entity.ConsentStatus(consentStatusB), + }, nil +} diff --git a/pkg/server/endpoints/admin.go b/pkg/server/endpoints/admin.go index f8999894..e22d31d3 100644 --- a/pkg/server/endpoints/admin.go +++ b/pkg/server/endpoints/admin.go @@ -115,8 +115,6 @@ func (h *AdminAPIHandlers) PutRelationship(echoCtx echo.Context) error { return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) } - 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) if err != nil { @@ -124,6 +122,8 @@ func (h *AdminAPIHandlers) PutRelationship(echoCtx echo.Context) error { return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) } + h.Logger.WithField(telemetry.TrustDomain, fmt.Sprintf("Created relationship between trust domains %s and %s", dbTd1.Name.String(), dbTd2.Name.String())) + return nil } @@ -240,12 +240,16 @@ func (h *AdminAPIHandlers) DeleteTrustDomainByName(echoCtx echo.Context, trustDo return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) } - err = chttp.WriteResponse(echoCtx, http.StatusOK, fmt.Sprintf("Trust domain %q deleted", trustDomainName)) + message := fmt.Sprintf("Trust Domain %q deleted", trustDomain.Name.String()) + response := api.DeleteResponse{Code: http.StatusOK, Message: message} + err = chttp.WriteResponse(echoCtx, http.StatusOK, response) if err != nil { err = fmt.Errorf("trust domain entity - %v", err.Error()) return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) } + h.Logger.WithField(telemetry.TrustDomain, fmt.Sprintf("Trust Domain %q deleted", trustDomain.Name.String())) + return nil } @@ -311,8 +315,6 @@ func (h *AdminAPIHandlers) PutTrustDomainByName(echoCtx echo.Context, trustDomai return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) } - h.Logger.Printf("Trust Bundle %v updated", td.Name) - response := api.TrustDomainFromEntity(td) err = chttp.WriteResponse(echoCtx, http.StatusOK, response) if err != nil { @@ -320,6 +322,97 @@ func (h *AdminAPIHandlers) PutTrustDomainByName(echoCtx echo.Context, trustDomai return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) } + h.Logger.WithField(telemetry.TrustDomain, fmt.Sprintf("Trust Domain %q updated", td.Name.String())) + + return nil +} + +// PatchRelationshipByID updates a specific relationship based on its id - (PATCH /relationships/{relationshipID}) +func (h *AdminAPIHandlers) PatchRelationshipByID(echoCtx echo.Context, relationshipID api.UUID) error { + ctx := echoCtx.Request().Context() + + reqBody := &admin.PatchRelationshipByIDJSONRequestBody{} + err := chttp.ParseRequestBodyToStruct(echoCtx, reqBody) + if err != nil { + err := fmt.Errorf("failed to parse relationship patch body: %v", err) + return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusBadRequest) + } + + rel, err := reqBody.ToEntity() + if err != nil { + err := fmt.Errorf("failed to read relationship patch body: %v", err) + return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusBadRequest) + } + + relDB, err := h.findRelationshipByID(ctx, relationshipID) + if err != nil { + return err + } + + if relDB == nil { + err = fmt.Errorf("relationship does not exist") + return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusNotFound) + } + + // Set the ID to perform an Update instead of a Creation of a new Relationship. + rel.ID = relDB.ID + + // Check if the user its performing an update in a single consent status, and replace the other one with the existing consent in the databse. + if rel.TrustDomainAConsent == "" { + rel.TrustDomainAConsent = relDB.TrustDomainAConsent + } + if rel.TrustDomainBConsent == "" { + rel.TrustDomainBConsent = relDB.TrustDomainBConsent + } + + relationship, err := h.Datastore.CreateOrUpdateRelationship(ctx, rel) + if err != nil { + err = fmt.Errorf("failed updating relationship: %v", err) + return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) + } + + response := api.RelationshipFromEntity(relationship) + err = chttp.WriteResponse(echoCtx, http.StatusOK, response) + if err != nil { + err = fmt.Errorf("relationship entity - %v", err.Error()) + return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) + } + + h.Logger.WithField(telemetry.Relationship, fmt.Sprintf("Relationship %q updated.", rel.ID.UUID.String())) + + return nil +} + +// DeleteRelationshipByID deletes a specific relationship based on its id - (DELETE /relationships/{relationshipID}) +func (h *AdminAPIHandlers) DeleteRelationshipByID(echoCtx echo.Context, relationshipID api.UUID) error { + ctx := echoCtx.Request().Context() + + //Check if the relationship exist in the database + relationship, err := h.findRelationshipByID(ctx, relationshipID) + if err != nil { + return err + } + + if relationship == nil { + err = fmt.Errorf("relationship does not exist") + return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusNotFound) + } + + err = h.Datastore.DeleteRelationship(ctx, relationship.ID.UUID) + if err != nil { + err = fmt.Errorf("failed getting relationships: %v", err) + return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) + } + + response := api.DeleteResponse{Code: http.StatusOK, Message: "Relationship deleted"} + err = chttp.WriteResponse(echoCtx, http.StatusOK, response) + if err != nil { + err = fmt.Errorf("relationship entity - %v", err.Error()) + return chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) + } + + h.Logger.WithField(telemetry.Relationship, fmt.Sprintf("Relationship %q deleted.", relationship.ID.UUID.String())) + return nil } @@ -408,3 +501,13 @@ func (h *AdminAPIHandlers) lookupTrustDomain(ctx context.Context, trustDomainNam return td, nil } + +func (h *AdminAPIHandlers) findRelationshipByID(ctx context.Context, relationshipID api.UUID) (*entity.Relationship, error) { + relationship, err := h.Datastore.FindRelationshipByID(ctx, relationshipID) + if err != nil { + err = fmt.Errorf("failed getting relationship: %v", err) + return nil, chttp.LogAndRespondWithError(h.Logger, err, err.Error(), http.StatusInternalServerError) + } + + return relationship, nil +} diff --git a/pkg/server/endpoints/admin_test.go b/pkg/server/endpoints/admin_test.go index 052266c0..42ef88b4 100644 --- a/pkg/server/endpoints/admin_test.go +++ b/pkg/server/endpoints/admin_test.go @@ -304,6 +304,116 @@ func TestUDSGetRelationshipsByID(t *testing.T) { }) } +func TestUDSDeleteRelationshipByID(t *testing.T) { + relationshipPath := "/relationship/%v" + r1ID := NewNullableID() + fakeID := NewNullableID() + t.Run("Successfully delete a relationship", func(t *testing.T) { + fakeTrustDomains := []*entity.TrustDomain{ + {ID: tdUUID1, Name: NewTrustDomain(t, td1)}, + {ID: tdUUID2, Name: NewTrustDomain(t, td2)}, + } + + fakeRelationship := &entity.Relationship{ + ID: r1ID, + TrustDomainAID: tdUUID1.UUID, + TrustDomainBID: tdUUID2.UUID, + } + + completePath := fmt.Sprintf(relationshipPath, r1ID.UUID) + + // Setup + setup := NewManagementTestSetup(t, http.MethodDelete, completePath, nil) + setup.FakeDatabase.WithTrustDomains(fakeTrustDomains...) + setup.FakeDatabase.WithRelationships(fakeRelationship) + + err := setup.Handler.DeleteRelationshipByID(setup.EchoCtx, fakeRelationship.ID.UUID) + assert.NoError(t, err) + assert.Equal(t, http.StatusOK, setup.Recorder.Code) + + expectedOutput := "{\"code\":200,\"message\":\"Relationship deleted\"}\n" + got := bytes.NewBuffer(setup.Recorder.Body.Bytes()).String() + + assert.Equal(t, expectedOutput, got) + }) + + t.Run("Error when deleting a relationship that does not exists", func(t *testing.T) { + fakeRelationship := &entity.Relationship{} + + completePath := fmt.Sprintf(relationshipPath, fakeID.UUID) + + // Setup + setup := NewManagementTestSetup(t, http.MethodDelete, completePath, nil) + setup.FakeDatabase.WithRelationships(fakeRelationship) + + err := setup.Handler.DeleteRelationshipByID(setup.EchoCtx, fakeID.UUID) + assert.Error(t, err) + + expectedErrMsg := "code=404, message=relationship does not exist" + assert.Equal(t, expectedErrMsg, err.Error()) + }) +} + +func TestUDSPatchRelationshipByID(t *testing.T) { + relationshipPath := "/relationship/%v" + r1ID := NewNullableID() + fakeID := NewNullableID() + t.Run("Successfully update the consent status of a relationship", func(t *testing.T) { + fakeRelationship := &entity.Relationship{ + ID: r1ID, + TrustDomainAConsent: entity.ConsentStatus(api.Pending), + TrustDomainBConsent: entity.ConsentStatus(api.Pending), + } + + completePath := fmt.Sprintf(relationshipPath, fakeRelationship.ID.UUID) + + reqBody := &admin.PatchRelationshipByIDJSONRequestBody{ + ConsentStatusA: api.Approved, + ConsentStatusB: api.Denied, + } + + // Setup + setup := NewManagementTestSetup(t, http.MethodPut, completePath, reqBody) + setup.FakeDatabase.WithRelationships(fakeRelationship) + + err := setup.Handler.PatchRelationshipByID(setup.EchoCtx, fakeRelationship.ID.UUID) + assert.NoError(t, err) + assert.Equal(t, http.StatusOK, setup.Recorder.Code) + + apiRelationship := api.Relationship{} + err = json.Unmarshal(setup.Recorder.Body.Bytes(), &apiRelationship) + assert.NoError(t, err) + + assert.Equal(t, api.Approved, apiRelationship.TrustDomainAConsent) + assert.Equal(t, api.Denied, apiRelationship.TrustDomainBConsent) + }) + + t.Run("Error when trying to update a relationship that does not exist", func(t *testing.T) { + fakeRelationship := &entity.Relationship{ + ID: r1ID, + TrustDomainAConsent: entity.ConsentStatus(api.Pending), + TrustDomainBConsent: entity.ConsentStatus(api.Pending), + } + + completePath := fmt.Sprintf(relationshipPath, fakeID.UUID) + + reqBody := &admin.PatchRelationshipByIDJSONRequestBody{ + ConsentStatusA: api.Approved, + ConsentStatusB: api.Denied, + } + + // Setup + setup := NewManagementTestSetup(t, http.MethodPut, completePath, reqBody) + setup.FakeDatabase.WithRelationships(fakeRelationship) + + err := setup.Handler.PatchRelationshipByID(setup.EchoCtx, fakeID.UUID) + assert.Error(t, err) + + expectedErrMsg := "code=404, message=relationship does not exist" + assert.Equal(t, expectedErrMsg, err.Error()) + }) +} + func TestUDSPutTrustDomain(t *testing.T) { trustDomainPath := "/trust-domain" t.Run("Successfully create a new trust domain", func(t *testing.T) { @@ -410,7 +520,7 @@ func TestUDSDeleteTrustDomain(t *testing.T) { assert.NoError(t, err) assert.Equal(t, http.StatusOK, setup.Recorder.Code) - expectedOutput := fmt.Sprintf("\"Trust domain %q deleted\"\n", td1) + expectedOutput := fmt.Sprintf("{\"code\":200,\"message\":\"Trust Domain %q deleted\"}\n", td1) got := bytes.NewBuffer(setup.Recorder.Body.Bytes()).String() assert.Equal(t, expectedOutput, strings.ReplaceAll(got, "\\", ""))