Skip to content

Commit

Permalink
Add idempotence identifier client methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dlipovetsky committed Dec 10, 2024
1 parent 69fb309 commit 6954ff7
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 0 deletions.
46 changes: 46 additions & 0 deletions v3/mocks/TestOperations_CreateIdempotenceIdentifers.yaml
Original file line number Diff line number Diff line change
@@ -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://pc.dev.nkp.sh: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=
45 changes: 45 additions & 0 deletions v3/mocks/TestOperations_DeleteIdempotenceIdentifers.yaml
Original file line number Diff line number Diff line change
@@ -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://pc.dev.nkp.sh: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=
45 changes: 45 additions & 0 deletions v3/mocks/TestOperations_GetIdempotenceIdentifers.yaml
Original file line number Diff line number Diff line change
@@ -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://pc.dev.nkp.sh: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=
41 changes: 41 additions & 0 deletions v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
64 changes: 64 additions & 0 deletions v3/v3_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_RECORD,
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_RECORD,
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_RECORD,
Name: t.Name(),
})

err = v3Client.V3.DeleteIdempotenceIdentifiers(
kctx,
"testclient",
)
require.NoError(t, err)
}

0 comments on commit 6954ff7

Please sign in to comment.