From 0a088ba95013b3279c9f5929675439dcdc5101e6 Mon Sep 17 00:00:00 2001 From: David White Date: Thu, 7 Dec 2023 15:23:17 -0700 Subject: [PATCH] feat: Add support for 'show controller-date' and use it for session validation Use show controller-date for session validity check. Also marks SessionValid as a deprecated function call with the expectation that it will be made redundant through future addition of retry logic --- README.md | 2 +- api/mc-openapi.yaml | 18 +++++ internal/generator/mc-commands.yaml | 5 ++ pkg/api/mcapi.go | 5 +- pkg/client/README.md | 1 + pkg/client/api/openapi.yaml | 17 +++++ pkg/client/api_default.go | 110 ++++++++++++++++++++++++++++ pkg/client/docs/DefaultApi.md | 62 ++++++++++++++++ pkg/client/test/api_default_test.go | 12 +++ pkg/regression/v2_login.go | 2 +- 10 files changed, 231 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d168e35..b63d2bc 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ The following table provides a list of all possible MC API commands and which on | `show ciphers` | | not supported | | `show cli-parameters` | | not supported | | `show configuration` | | not supported | -| `show controller-date` | | not supported | +| `show controller-date` | | supported | | `show controller-statistics` | | not supported | | `show controllers` | supported | | | `show debug-log-parameters` | | not supported | diff --git a/api/mc-openapi.yaml b/api/mc-openapi.yaml index 18f09c9..abb2e36 100644 --- a/api/mc-openapi.yaml +++ b/api/mc-openapi.yaml @@ -92,6 +92,24 @@ paths: application/json: schema: $ref: '#/components/schemas/statusObject' + # /show/controller-date + /show/controller-date: + get: + description: Execute /show/controller-date command + operationId: ShowController-DateGet + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/statusObject' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/statusObject' # /show/volumes /show/volumes/{namesOption}: get: diff --git a/internal/generator/mc-commands.yaml b/internal/generator/mc-commands.yaml index 6c2dbf6..5ff2a1e 100644 --- a/internal/generator/mc-commands.yaml +++ b/internal/generator/mc-commands.yaml @@ -24,6 +24,11 @@ commands: meta: fan include: - status + + - command: /show/controller-date + meta: status + include: + - status - command: /show/volumes meta: volumes diff --git a/pkg/api/mcapi.go b/pkg/api/mcapi.go index f1aa1e5..e73bc34 100644 --- a/pkg/api/mcapi.go +++ b/pkg/api/mcapi.go @@ -91,6 +91,9 @@ func (client *Client) Logout() error { } // SessionValid : Determine if a session is valid, if not a login is required +// Makes the 'show controller-date' API call to validate the session is still valid +// +// Deprecated: This function will be made redundant by retry logic in a future update func (client *Client) SessionValid(addr, username string) bool { if client.Ctx == nil { return false @@ -108,7 +111,7 @@ func (client *Client) SessionValid(addr, username string) bool { } //run an API call to test that the session is still valid - _, _, err := client.apiClient.DefaultApi.ShowSystemGet(client.Ctx).Execute() + _, _, err := client.apiClient.DefaultApi.ShowControllerDateGet(client.Ctx).Execute() return err == nil } diff --git a/pkg/client/README.md b/pkg/client/README.md index cde568d..f5204b2 100644 --- a/pkg/client/README.md +++ b/pkg/client/README.md @@ -94,6 +94,7 @@ Class | Method | HTTP request | Description *DefaultApi* | [**ShowAdvancedSettingsGet**](docs/DefaultApi.md#showadvancedsettingsget) | **Get** /show/advanced-settings | *DefaultApi* | [**ShowCacheParametersGet**](docs/DefaultApi.md#showcacheparametersget) | **Get** /show/cache-parameters | *DefaultApi* | [**ShowCertificateGet**](docs/DefaultApi.md#showcertificateget) | **Get** /show/certificate | +*DefaultApi* | [**ShowControllerDateGet**](docs/DefaultApi.md#showcontrollerdateget) | **Get** /show/controller-date | *DefaultApi* | [**ShowControllersGet**](docs/DefaultApi.md#showcontrollersget) | **Get** /show/controllers | *DefaultApi* | [**ShowDiskGroupsGet**](docs/DefaultApi.md#showdiskgroupsget) | **Get** /show/disk-groups | *DefaultApi* | [**ShowDisksGet**](docs/DefaultApi.md#showdisksget) | **Get** /show/disks | diff --git a/pkg/client/api/openapi.yaml b/pkg/client/api/openapi.yaml index 1c3ff3e..ffed546 100644 --- a/pkg/client/api/openapi.yaml +++ b/pkg/client/api/openapi.yaml @@ -94,6 +94,23 @@ paths: schema: $ref: '#/components/schemas/statusObject' description: Unauthorized + /show/controller-date: + get: + description: Execute /show/controller-date command + operationId: ShowController-DateGet + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/statusObject' + description: OK + "401": + content: + application/json: + schema: + $ref: '#/components/schemas/statusObject' + description: Unauthorized /show/volumes/{namesOption}: get: description: Execute /show/volumes command diff --git a/pkg/client/api_default.go b/pkg/client/api_default.go index 202318c..a6c6ec4 100644 --- a/pkg/client/api_default.go +++ b/pkg/client/api_default.go @@ -1840,6 +1840,116 @@ func (a *DefaultApiService) ShowCertificateGetExecute(r ApiShowCertificateGetReq return localVarReturnValue, localVarHTTPResponse, nil } +type ApiShowControllerDateGetRequest struct { + ctx context.Context + ApiService *DefaultApiService +} + +func (r ApiShowControllerDateGetRequest) Execute() (*StatusObject, *http.Response, error) { + return r.ApiService.ShowControllerDateGetExecute(r) +} + +/* +ShowControllerDateGet Method for ShowControllerDateGet + +Execute /show/controller-date command + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiShowControllerDateGetRequest +*/ +func (a *DefaultApiService) ShowControllerDateGet(ctx context.Context) ApiShowControllerDateGetRequest { + return ApiShowControllerDateGetRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +// +// @return StatusObject +func (a *DefaultApiService) ShowControllerDateGetExecute(r ApiShowControllerDateGetRequest) (*StatusObject, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *StatusObject + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ShowControllerDateGet") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/show/controller-date" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 401 { + var v StatusObject + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + type ApiShowControllersGetRequest struct { ctx context.Context ApiService *DefaultApiService diff --git a/pkg/client/docs/DefaultApi.md b/pkg/client/docs/DefaultApi.md index 2580a63..1131cef 100644 --- a/pkg/client/docs/DefaultApi.md +++ b/pkg/client/docs/DefaultApi.md @@ -20,6 +20,7 @@ Method | HTTP request | Description [**ShowAdvancedSettingsGet**](DefaultApi.md#ShowAdvancedSettingsGet) | **Get** /show/advanced-settings | [**ShowCacheParametersGet**](DefaultApi.md#ShowCacheParametersGet) | **Get** /show/cache-parameters | [**ShowCertificateGet**](DefaultApi.md#ShowCertificateGet) | **Get** /show/certificate | +[**ShowControllerDateGet**](DefaultApi.md#ShowControllerDateGet) | **Get** /show/controller-date | [**ShowControllersGet**](DefaultApi.md#ShowControllersGet) | **Get** /show/controllers | [**ShowDiskGroupsGet**](DefaultApi.md#ShowDiskGroupsGet) | **Get** /show/disk-groups | [**ShowDisksGet**](DefaultApi.md#ShowDisksGet) | **Get** /show/disks | @@ -1154,6 +1155,67 @@ Other parameters are passed through a pointer to a apiShowCertificateGetRequest [[Back to README]](../README.md) +## ShowControllerDateGet + +> StatusObject ShowControllerDateGet(ctx).Execute() + + + + + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID" +) + +func main() { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.DefaultApi.ShowControllerDateGet(context.Background()).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DefaultApi.ShowControllerDateGet``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `ShowControllerDateGet`: StatusObject + fmt.Fprintf(os.Stdout, "Response from `DefaultApi.ShowControllerDateGet`: %v\n", resp) +} +``` + +### Path Parameters + +This endpoint does not need any parameter. + +### Other Parameters + +Other parameters are passed through a pointer to a apiShowControllerDateGetRequest struct via the builder pattern + + +### Return type + +[**StatusObject**](StatusObject.md) + +### Authorization + +[basicAuth](../README.md#basicAuth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + ## ShowControllersGet > ControllersObject ShowControllersGet(ctx).Execute() diff --git a/pkg/client/test/api_default_test.go b/pkg/client/test/api_default_test.go index 1678e2b..f150317 100644 --- a/pkg/client/test/api_default_test.go +++ b/pkg/client/test/api_default_test.go @@ -247,6 +247,18 @@ func Test_client_DefaultApiService(t *testing.T) { }) + t.Run("Test DefaultApiService ShowControllerDateGet", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.DefaultApi.ShowControllerDateGet(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + t.Run("Test DefaultApiService ShowControllersGet", func(t *testing.T) { t.Skip("skip test") // remove to run test diff --git a/pkg/regression/v2_login.go b/pkg/regression/v2_login.go index 0575e36..d94a385 100644 --- a/pkg/regression/v2_login.go +++ b/pkg/regression/v2_login.go @@ -35,7 +35,7 @@ var _ = DescribeRegression("Login Testing (v2)", func(tc *TestContext) { It("should be able to log out of the storage controller", func() { err := client.Logout() logger := klog.FromContext(tc.Config.Ctx) - logger.V(3).Info("Login", "ip", client.Addr, "username", client.Username, "err", err) + logger.V(3).Info("Logout", "ip", client.Addr, "username", client.Username, "err", err) Expect(err).To(BeNil()) })