diff --git a/CHANGELOG.md b/CHANGELOG.md index a240b038..9f9deb0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - Added witness configuration to recovery plan spec. +- Added support for creating, deleting, and listing idempotence identifiers. ### Changed - Updated the v3 Cluster spec and status structs to match latest swagger spec diff --git a/Makefile b/Makefile index ca5825ba..3cbc5998 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,11 @@ generate-v3-models: ## Generate V3 models using go-swagger --model=recovery_plan_list_intent_response \ --model=recovery_plan_intent_resource \ --model=recovery_plan_list_metadata_output \ - --model=sort_order + --model=sort_order \ + --model=idempotence_identifiers_input \ + --model=idempotence_identifiers_metadata \ + --model=idempotence_identifiers_response \ + --model=idempotence_identifiers_status clean: ## Remove build related file rm -fr ./bin vendor hack/tools/bin diff --git a/v3/mocks/TestOperations_CreateIdempotenceIdentifers.yaml b/v3/mocks/TestOperations_CreateIdempotenceIdentifers.yaml new file mode 100644 index 00000000..aeff6907 --- /dev/null +++ b/v3/mocks/TestOperations_CreateIdempotenceIdentifers.yaml @@ -0,0 +1,46 @@ +version: api.keploy.io/v1beta2 +kind: Http +name: TestOperations_CreateIdempotenceIdentifers +spec: + metadata: + name: Http + operation: POST + type: HTTP_CLIENT + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: https://prism-test.nutanix.com:9440/api/nutanix/v3/idempotence_identifiers + header: + Accept: application/json + Content-Type: application/json + User-Agent: nutanix/v3 + body: | + {"client_identifier":"testclient","count":2,"valid_duration_in_minutes":10} + body_type: utf-8 + resp: + status_code: 200 + header: + Content-Security-Policy: 'default-src ''self'' https://*.nutanix.com; script-src ''self'' ''unsafe-inline'' ''unsafe-eval''; style-src ''self'' ''unsafe-inline''; connect-src ''self'' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src ''self'' blob: data:; frame-src ''self'' https://*.nutanix.com blob: data:' + Content-Type: application/json + Date: Tue, 10 Dec 2024 16:52:24 GMT + Server: envoy + Strict-Transport-Security: max-age=8640000:includeSubdomains + Vary: Accept-Encoding + X-Content-Type-Options: nosniff + X-Dns-Prefetch-Control: "off" + X-Envoy-Upstream-Service-Time: "274" + X-Frame-Options: SAMEORIGIN + X-Ntnx-Env: pc + X-Ntnx-Product: pc.2024.1.0.1 + X-Permitted-Cross-Domain-Policies: master-only + X-Xss-Protection: 1; mode=block + body: | + {"client_identifier": "testclient", "count": 2, "expiration_time": "2024-12-10T17:01:02Z", "uuid_list": ["ab411b1a-f173-4009-9a8f-3d6e996c752a", "2515c166-dc95-4c12-8eb2-5d0aed9ad931"]} + body_type: utf-8 + status_message: "" + proto_major: 0 + proto_minor: 0 + objects: + - type: error + data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA= diff --git a/v3/mocks/TestOperations_DeleteIdempotenceIdentifers.yaml b/v3/mocks/TestOperations_DeleteIdempotenceIdentifers.yaml new file mode 100644 index 00000000..c478fdd7 --- /dev/null +++ b/v3/mocks/TestOperations_DeleteIdempotenceIdentifers.yaml @@ -0,0 +1,45 @@ +version: api.keploy.io/v1beta2 +kind: Http +name: TestOperations_DeleteIdempotenceIdentifers +spec: + metadata: + name: Http + operation: DELETE + type: HTTP_CLIENT + req: + method: DELETE + proto_major: 1 + proto_minor: 1 + url: https://prism-test.nutanix.com:9440/api/nutanix/v3/idempotence_identifiers/testclient + header: + Accept: application/json + Content-Type: application/json + User-Agent: nutanix/v3 + body: "" + body_type: utf-8 + resp: + status_code: 200 + header: + Content-Length: "5" + Content-Security-Policy: 'default-src ''self'' https://*.nutanix.com; script-src ''self'' ''unsafe-inline'' ''unsafe-eval''; style-src ''self'' ''unsafe-inline''; connect-src ''self'' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src ''self'' blob: data:; frame-src ''self'' https://*.nutanix.com blob: data:' + Content-Type: application/json + Date: Tue, 10 Dec 2024 16:53:51 GMT + Server: envoy + Strict-Transport-Security: max-age=8640000:includeSubdomains + X-Content-Type-Options: nosniff + X-Dns-Prefetch-Control: "off" + X-Envoy-Upstream-Service-Time: "191" + X-Frame-Options: SAMEORIGIN + X-Ntnx-Env: pc + X-Ntnx-Product: pc.2024.1.0.1 + X-Permitted-Cross-Domain-Policies: master-only + X-Xss-Protection: 1; mode=block + body: | + null + body_type: utf-8 + status_message: "" + proto_major: 0 + proto_minor: 0 + objects: + - type: error + data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA= diff --git a/v3/mocks/TestOperations_GetIdempotenceIdentifers.yaml b/v3/mocks/TestOperations_GetIdempotenceIdentifers.yaml new file mode 100644 index 00000000..3247fd2c --- /dev/null +++ b/v3/mocks/TestOperations_GetIdempotenceIdentifers.yaml @@ -0,0 +1,45 @@ +version: api.keploy.io/v1beta2 +kind: Http +name: TestOperations_GetIdempotenceIdentifers +spec: + metadata: + name: Http + operation: GET + type: HTTP_CLIENT + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: https://prism-test.nutanix.com:9440/api/nutanix/v3/idempotence_identifiers/testclient + header: + Accept: application/json + Content-Type: application/json + User-Agent: nutanix/v3 + body: "" + body_type: utf-8 + resp: + status_code: 200 + header: + Content-Security-Policy: 'default-src ''self'' https://*.nutanix.com; script-src ''self'' ''unsafe-inline'' ''unsafe-eval''; style-src ''self'' ''unsafe-inline''; connect-src ''self'' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src ''self'' blob: data:; frame-src ''self'' https://*.nutanix.com blob: data:' + Content-Type: application/json + Date: Tue, 10 Dec 2024 16:52:31 GMT + Server: envoy + Strict-Transport-Security: max-age=8640000:includeSubdomains + Vary: Accept-Encoding + X-Content-Type-Options: nosniff + X-Dns-Prefetch-Control: "off" + X-Envoy-Upstream-Service-Time: "181" + X-Frame-Options: SAMEORIGIN + X-Ntnx-Env: pc + X-Ntnx-Product: pc.2024.1.0.1 + X-Permitted-Cross-Domain-Policies: master-only + X-Xss-Protection: 1; mode=block + body: | + {"client_identifier": "testclient", "count": 2, "expiration_time": "2024-12-10T17:01:02Z", "uuid_list": ["ab411b1a-f173-4009-9a8f-3d6e996c752a", "2515c166-dc95-4c12-8eb2-5d0aed9ad931"]} + body_type: utf-8 + status_message: "" + proto_major: 0 + proto_minor: 0 + objects: + - type: error + data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA= diff --git a/v3/models/idempotence_identifiers_input.go b/v3/models/idempotence_identifiers_input.go new file mode 100644 index 00000000..c2ae90ab --- /dev/null +++ b/v3/models/idempotence_identifiers_input.go @@ -0,0 +1,111 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// IdempotenceIdentifiersInput Idempotence object +// +// Resources for the idempotence identifier kind. +// +// swagger:model idempotence_identifiers_input +type IdempotenceIdentifiersInput struct { + + // The client identifier string. + ClientIdentifier string `json:"client_identifier,omitempty"` + + // The number of idempotence identifiers provided. + // Required: true + // Maximum: 4096 + // Minimum: 1 + Count *int64 `json:"count"` + + // Number of minutes from creation time for which idempotence identifier uuid list is valid. + // Maximum: 527040 + // Minimum: 1 + ValidDurationInMinutes int64 `json:"valid_duration_in_minutes,omitempty"` +} + +// Validate validates this idempotence identifiers input +func (m *IdempotenceIdentifiersInput) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateCount(formats); err != nil { + res = append(res, err) + } + + if err := m.validateValidDurationInMinutes(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *IdempotenceIdentifiersInput) validateCount(formats strfmt.Registry) error { + + if err := validate.Required("count", "body", m.Count); err != nil { + return err + } + + if err := validate.MinimumInt("count", "body", *m.Count, 1, false); err != nil { + return err + } + + if err := validate.MaximumInt("count", "body", *m.Count, 4096, false); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersInput) validateValidDurationInMinutes(formats strfmt.Registry) error { + if swag.IsZero(m.ValidDurationInMinutes) { // not required + return nil + } + + if err := validate.MinimumInt("valid_duration_in_minutes", "body", m.ValidDurationInMinutes, 1, false); err != nil { + return err + } + + if err := validate.MaximumInt("valid_duration_in_minutes", "body", m.ValidDurationInMinutes, 527040, false); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this idempotence identifiers input based on context it is used +func (m *IdempotenceIdentifiersInput) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *IdempotenceIdentifiersInput) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *IdempotenceIdentifiersInput) UnmarshalBinary(b []byte) error { + var res IdempotenceIdentifiersInput + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/v3/models/idempotence_identifiers_metadata.go b/v3/models/idempotence_identifiers_metadata.go new file mode 100644 index 00000000..ef37ff57 --- /dev/null +++ b/v3/models/idempotence_identifiers_metadata.go @@ -0,0 +1,367 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// IdempotenceIdentifiersMetadata idempotence_identifiers metadata +// +// The idempotence_identifiers kind metadata +// +// swagger:model idempotence_identifiers_metadata +type IdempotenceIdentifiersMetadata struct { + + // Categories for the idempotence_identifiers. This allows assigning one value + // of a key to any entity. Changes done in this will be reflected in + // the categories_mapping field. + // + Categories map[string]string `json:"categories,omitempty"` + + // Categories for the idempotence_identifiers. This allows setting up multiple + // values from a single key. Categories assigned using the older view will be + // present here. This is the new way of assigning categories. + // + CategoriesMapping map[string][]string `json:"categories_mapping,omitempty"` + + // UTC date and time in RFC-3339 format when idempotence_identifiers was created + // + // Read Only: true + // Format: date-time + CreationTime strfmt.DateTime `json:"creation_time,omitempty"` + + // Logical entity version that allows serializing updates to the entity + // across multiple API namespaces. For kinds that support + // entity_version, it overrides spec_version described above. + // + // Read Only: true + EntityVersion string `json:"entity_version,omitempty"` + + // The kind name + // Required: true + // Read Only: true + Kind string `json:"kind"` + + // UTC date and time in RFC-3339 format when idempotence_identifiers was last updated + // + // Read Only: true + // Format: date-time + LastUpdateTime strfmt.DateTime `json:"last_update_time,omitempty"` + + // idempotence_identifiers name + // Read Only: true + // Max Length: 80 + Name string `json:"name,omitempty"` + + // owner reference + OwnerReference *UserReference `json:"owner_reference,omitempty"` + + // The project the idempotence_identifiers is in. + ProjectReference *ProjectReference `json:"project_reference,omitempty"` + + // Applied on Prism Central only. Indicate whether force to translate the spec of the fanout request to fit the target cluster API schema. + // + ShouldForceTranslate bool `json:"should_force_translate,omitempty"` + + // Hash of the spec. This will be returned from server. + // + SpecHash string `json:"spec_hash,omitempty"` + + // Version number of the latest spec. + SpecVersion int64 `json:"spec_version,omitempty"` + + // Client need to specify this field as true if user want to use the + // newer way of assigning the categories. Without this things should work + // as it was earlier. + // + UseCategoriesMapping *bool `json:"use_categories_mapping,omitempty"` + + // idempotence_identifiers uuid + // Pattern: ^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$ + UUID string `json:"uuid,omitempty"` +} + +// Validate validates this idempotence identifiers metadata +func (m *IdempotenceIdentifiersMetadata) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateCreationTime(formats); err != nil { + res = append(res, err) + } + + if err := m.validateKind(formats); err != nil { + res = append(res, err) + } + + if err := m.validateLastUpdateTime(formats); err != nil { + res = append(res, err) + } + + if err := m.validateName(formats); err != nil { + res = append(res, err) + } + + if err := m.validateOwnerReference(formats); err != nil { + res = append(res, err) + } + + if err := m.validateProjectReference(formats); err != nil { + res = append(res, err) + } + + if err := m.validateUUID(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *IdempotenceIdentifiersMetadata) validateCreationTime(formats strfmt.Registry) error { + if swag.IsZero(m.CreationTime) { // not required + return nil + } + + if err := validate.FormatOf("creation_time", "body", "date-time", m.CreationTime.String(), formats); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) validateKind(formats strfmt.Registry) error { + + if err := validate.RequiredString("kind", "body", m.Kind); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) validateLastUpdateTime(formats strfmt.Registry) error { + if swag.IsZero(m.LastUpdateTime) { // not required + return nil + } + + if err := validate.FormatOf("last_update_time", "body", "date-time", m.LastUpdateTime.String(), formats); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) validateName(formats strfmt.Registry) error { + if swag.IsZero(m.Name) { // not required + return nil + } + + if err := validate.MaxLength("name", "body", m.Name, 80); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) validateOwnerReference(formats strfmt.Registry) error { + if swag.IsZero(m.OwnerReference) { // not required + return nil + } + + if m.OwnerReference != nil { + if err := m.OwnerReference.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("owner_reference") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("owner_reference") + } + return err + } + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) validateProjectReference(formats strfmt.Registry) error { + if swag.IsZero(m.ProjectReference) { // not required + return nil + } + + if m.ProjectReference != nil { + if err := m.ProjectReference.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("project_reference") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("project_reference") + } + return err + } + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) validateUUID(formats strfmt.Registry) error { + if swag.IsZero(m.UUID) { // not required + return nil + } + + if err := validate.Pattern("uuid", "body", m.UUID, `^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$`); err != nil { + return err + } + + return nil +} + +// ContextValidate validate this idempotence identifiers metadata based on the context it is used +func (m *IdempotenceIdentifiersMetadata) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateCreationTime(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateEntityVersion(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateKind(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateLastUpdateTime(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateName(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateOwnerReference(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateProjectReference(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *IdempotenceIdentifiersMetadata) contextValidateCreationTime(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "creation_time", "body", strfmt.DateTime(m.CreationTime)); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) contextValidateEntityVersion(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "entity_version", "body", string(m.EntityVersion)); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) contextValidateKind(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "kind", "body", string(m.Kind)); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) contextValidateLastUpdateTime(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "last_update_time", "body", strfmt.DateTime(m.LastUpdateTime)); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) contextValidateName(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "name", "body", string(m.Name)); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) contextValidateOwnerReference(ctx context.Context, formats strfmt.Registry) error { + + if m.OwnerReference != nil { + + if swag.IsZero(m.OwnerReference) { // not required + return nil + } + + if err := m.OwnerReference.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("owner_reference") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("owner_reference") + } + return err + } + } + + return nil +} + +func (m *IdempotenceIdentifiersMetadata) contextValidateProjectReference(ctx context.Context, formats strfmt.Registry) error { + + if m.ProjectReference != nil { + + if swag.IsZero(m.ProjectReference) { // not required + return nil + } + + if err := m.ProjectReference.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("project_reference") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("project_reference") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *IdempotenceIdentifiersMetadata) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *IdempotenceIdentifiersMetadata) UnmarshalBinary(b []byte) error { + var res IdempotenceIdentifiersMetadata + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/v3/models/idempotence_identifiers_response.go b/v3/models/idempotence_identifiers_response.go new file mode 100644 index 00000000..3f6a11b4 --- /dev/null +++ b/v3/models/idempotence_identifiers_response.go @@ -0,0 +1,122 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// IdempotenceIdentifiersResponse Idempotence identifier status definition. +// +// Idempotence identifier status definition. +// +// swagger:model idempotence_identifiers_response +type IdempotenceIdentifiersResponse struct { + + // The client identifier string. + ClientIdentifier string `json:"client_identifier,omitempty"` + + // The number of idempotence identifiers provided. + // Required: true + Count *int64 `json:"count"` + + // UTC date and time in RFC-3339 format of the expiration time (with reference to system time). Value is creation time + valid_duration + // Format: date-time + ExpirationTime strfmt.DateTime `json:"expiration_time,omitempty"` + + // uuid list + // Required: true + UUIDList []string `json:"uuid_list"` +} + +// Validate validates this idempotence identifiers response +func (m *IdempotenceIdentifiersResponse) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateCount(formats); err != nil { + res = append(res, err) + } + + if err := m.validateExpirationTime(formats); err != nil { + res = append(res, err) + } + + if err := m.validateUUIDList(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *IdempotenceIdentifiersResponse) validateCount(formats strfmt.Registry) error { + + if err := validate.Required("count", "body", m.Count); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersResponse) validateExpirationTime(formats strfmt.Registry) error { + if swag.IsZero(m.ExpirationTime) { // not required + return nil + } + + if err := validate.FormatOf("expiration_time", "body", "date-time", m.ExpirationTime.String(), formats); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersResponse) validateUUIDList(formats strfmt.Registry) error { + + if err := validate.Required("uuid_list", "body", m.UUIDList); err != nil { + return err + } + + for i := 0; i < len(m.UUIDList); i++ { + + if err := validate.Pattern("uuid_list"+"."+strconv.Itoa(i), "body", m.UUIDList[i], `^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$`); err != nil { + return err + } + + } + + return nil +} + +// ContextValidate validates this idempotence identifiers response based on context it is used +func (m *IdempotenceIdentifiersResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *IdempotenceIdentifiersResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *IdempotenceIdentifiersResponse) UnmarshalBinary(b []byte) error { + var res IdempotenceIdentifiersResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/v3/models/idempotence_identifiers_status.go b/v3/models/idempotence_identifiers_status.go new file mode 100644 index 00000000..daad6bed --- /dev/null +++ b/v3/models/idempotence_identifiers_status.go @@ -0,0 +1,227 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// IdempotenceIdentifiersStatus Response Kind +// +// The status of a REST API call. Only used when there is a failure to +// report. +// +// swagger:model idempotence_identifiers_status +type IdempotenceIdentifiersStatus struct { + + // api version + APIVersion APIVersion `json:"api_version,omitempty"` + + // The HTTP error code. + // Read Only: true + Code int64 `json:"code,omitempty"` + + // The kind name + // Read Only: true + Kind string `json:"kind,omitempty"` + + // message list + // Read Only: true + MessageList []*MessageResource `json:"message_list"` + + // state + // Read Only: true + State string `json:"state,omitempty"` +} + +// Validate validates this idempotence identifiers status +func (m *IdempotenceIdentifiersStatus) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAPIVersion(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMessageList(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *IdempotenceIdentifiersStatus) validateAPIVersion(formats strfmt.Registry) error { + if swag.IsZero(m.APIVersion) { // not required + return nil + } + + if err := m.APIVersion.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("api_version") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("api_version") + } + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersStatus) validateMessageList(formats strfmt.Registry) error { + if swag.IsZero(m.MessageList) { // not required + return nil + } + + for i := 0; i < len(m.MessageList); i++ { + if swag.IsZero(m.MessageList[i]) { // not required + continue + } + + if m.MessageList[i] != nil { + if err := m.MessageList[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("message_list" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("message_list" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this idempotence identifiers status based on the context it is used +func (m *IdempotenceIdentifiersStatus) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateAPIVersion(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateCode(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateKind(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateMessageList(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateState(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *IdempotenceIdentifiersStatus) contextValidateAPIVersion(ctx context.Context, formats strfmt.Registry) error { + + if swag.IsZero(m.APIVersion) { // not required + return nil + } + + if err := m.APIVersion.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("api_version") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("api_version") + } + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersStatus) contextValidateCode(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "code", "body", int64(m.Code)); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersStatus) contextValidateKind(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "kind", "body", string(m.Kind)); err != nil { + return err + } + + return nil +} + +func (m *IdempotenceIdentifiersStatus) contextValidateMessageList(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "message_list", "body", []*MessageResource(m.MessageList)); err != nil { + return err + } + + for i := 0; i < len(m.MessageList); i++ { + + if m.MessageList[i] != nil { + + if swag.IsZero(m.MessageList[i]) { // not required + return nil + } + + if err := m.MessageList[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("message_list" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("message_list" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *IdempotenceIdentifiersStatus) contextValidateState(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "state", "body", string(m.State)); err != nil { + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *IdempotenceIdentifiersStatus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *IdempotenceIdentifiersStatus) UnmarshalBinary(b []byte) error { + var res IdempotenceIdentifiersStatus + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/v3/v3_service.go b/v3/v3_service.go index 290c2796..5c708beb 100644 --- a/v3/v3_service.go +++ b/v3/v3_service.go @@ -131,6 +131,9 @@ type Service interface { GroupsGetEntities(ctx context.Context, request *GroupsGetEntitiesRequest) (*GroupsGetEntitiesResponse, error) GetAvailabilityZone(ctx context.Context, uuid string) (*AvailabilityZoneIntentResponse, error) GetPrismCentral(ctx context.Context) (*models.PrismCentral, error) + CreateIdempotenceIdentifiers(ctx context.Context, request *models.IdempotenceIdentifiersInput) (*models.IdempotenceIdentifiersResponse, error) + GetIdempotenceIdentifiers(ctx context.Context, clientIdentifier string) (*models.IdempotenceIdentifiersResponse, error) + DeleteIdempotenceIdentifiers(ctx context.Context, clientIdentifier string) error } /*CreateVM Creates a VM @@ -2446,3 +2449,41 @@ func (op Operations) GetPrismCentral(ctx context.Context) (*models.PrismCentral, return response, op.client.Do(ctx, req, response) } + +// CreateIdempotenceIdentifiers creates an idempotence identifier, scoped to the client identifier. +func (op Operations) CreateIdempotenceIdentifiers(ctx context.Context, request *models.IdempotenceIdentifiersInput) (*models.IdempotenceIdentifiersResponse, error) { + req, err := op.client.NewRequest(http.MethodPost, "/idempotence_identifiers", request) + idResponse := new(models.IdempotenceIdentifiersResponse) + + if err != nil { + return nil, err + } + + return idResponse, op.client.Do(ctx, req, idResponse) +} + +// GetIdempotenceIdentifiers gets all idempotence identifiers scoped to the client identifier. +func (op Operations) GetIdempotenceIdentifiers(ctx context.Context, clientIdentifier string) (*models.IdempotenceIdentifiersResponse, error) { + path := fmt.Sprintf("/idempotence_identifiers/%s", clientIdentifier) + + req, err := op.client.NewRequest(http.MethodGet, path, nil) + idResponse := new(models.IdempotenceIdentifiersResponse) + + if err != nil { + return nil, err + } + + return idResponse, op.client.Do(ctx, req, idResponse) +} + +// DeleteIdempotenceIdentifiers deletes all idempotence identifier scoped to the client identifier. +func (op Operations) DeleteIdempotenceIdentifiers(ctx context.Context, clientIdentifier string) error { + path := fmt.Sprintf("/idempotence_identifiers/%s", clientIdentifier) + + req, err := op.client.NewRequest(http.MethodDelete, path, nil) + if err != nil { + return err + } + + return op.client.Do(ctx, req, nil) +} diff --git a/v3/v3_service_test.go b/v3/v3_service_test.go index e975a1ab..8fb6b458 100644 --- a/v3/v3_service_test.go +++ b/v3/v3_service_test.go @@ -5809,3 +5809,67 @@ func TestOperations_ListCluster(t *testing.T) { assert.Equal(t, "cluster", *prismElements[0].Metadata.Kind) assert.Equal(t, "ganon", prismElements[0].Status.Name) } + +func TestOperations_CreateIdempotenceIdentifers(t *testing.T) { + creds := testhelpers.CredentialsFromEnvironment(t) + interceptor := khttpclient.NewInterceptor(http.DefaultTransport) + v3Client, err := NewV3Client(creds, WithRoundTripper(interceptor)) + require.NoError(t, err) + + kctx := mock.NewContext(mock.Config{ + Mode: keploy.MODE_TEST, + Name: t.Name(), + }) + + resp, err := v3Client.V3.CreateIdempotenceIdentifiers( + kctx, + &models.IdempotenceIdentifiersInput{ + ClientIdentifier: "testclient", + Count: utils.Int64Ptr(2), + ValidDurationInMinutes: 10, + }, + ) + require.NoError(t, err) + assert.Equal(t, resp.ClientIdentifier, "testclient") + assert.NotZero(t, resp.ExpirationTime) + assert.Len(t, resp.UUIDList, 2) +} + +func TestOperations_GetIdempotenceIdentifers(t *testing.T) { + creds := testhelpers.CredentialsFromEnvironment(t) + interceptor := khttpclient.NewInterceptor(http.DefaultTransport) + v3Client, err := NewV3Client(creds, WithRoundTripper(interceptor)) + require.NoError(t, err) + + kctx := mock.NewContext(mock.Config{ + Mode: keploy.MODE_TEST, + Name: t.Name(), + }) + + resp, err := v3Client.V3.GetIdempotenceIdentifiers( + kctx, + "testclient", + ) + require.NoError(t, err) + assert.Equal(t, resp.ClientIdentifier, "testclient") + assert.Equal(t, *resp.Count, int64(2)) + assert.Len(t, resp.UUIDList, 2) +} + +func TestOperations_DeleteIdempotenceIdentifers(t *testing.T) { + creds := testhelpers.CredentialsFromEnvironment(t) + interceptor := khttpclient.NewInterceptor(http.DefaultTransport) + v3Client, err := NewV3Client(creds, WithRoundTripper(interceptor)) + require.NoError(t, err) + + kctx := mock.NewContext(mock.Config{ + Mode: keploy.MODE_TEST, + Name: t.Name(), + }) + + err = v3Client.V3.DeleteIdempotenceIdentifiers( + kctx, + "testclient", + ) + require.NoError(t, err) +}