Skip to content

Commit

Permalink
Feat: Add Logout API Call
Browse files Browse the repository at this point in the history
Adds the /logout call to the openAPI generation code to gracefully
end an API session
  • Loading branch information
David-T-White committed Jan 19, 2024
1 parent 9694ef0 commit fd3c437
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 15 deletions.
14 changes: 14 additions & 0 deletions api/mc-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/statusObject'
# Logout
/logout:
get:
description: Log out of the storage array management controller
operationId: LogoutGet
security:
- basicAuth: []
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/statusObject'
# Meta
/meta/{schemaId}:
get:
Expand Down
2 changes: 1 addition & 1 deletion internal/generator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func main() {
s := &generator.Specification{}
s.Reset()
s.GenerateHeader(ctx)
s.GenerateLogin(ctx)
s.GenerateLoginLogout(ctx)
s.GenerateMetaSchema(ctx)

logger.V(0).Info(">> generate openapi spec...", "commands", len(yamlc.Commands), "exceptions", len(yamlc.Exceptions))
Expand Down
19 changes: 17 additions & 2 deletions internal/generator/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func (s *Specification) GenerateHeader(ctx context.Context) error {
return nil
}

// GenerateLogin: Add all required lines for MC login path
func (s *Specification) GenerateLogin(ctx context.Context) error {
// GenerateLoginLogout: Add all required lines for MC login and logout paths
func (s *Specification) GenerateLoginLogout(ctx context.Context) error {

s.Paths(1, "# Login")
s.Paths(1, "/login:")
Expand All @@ -197,6 +197,21 @@ func (s *Specification) GenerateLogin(ctx context.Context) error {
s.Paths(7, "schema:")
s.Paths(8, "$ref: '#/components/schemas/statusObject'")

s.Paths(1, "# Logout")
s.Paths(1, "/logout:")
s.Paths(2, "get:")
s.Paths(3, "description: Log out of the storage array management controller")
s.Paths(3, "operationId: LogoutGet")
s.Paths(3, "security:")
s.Paths(3, "- basicAuth: []")
s.Paths(3, "responses:")
s.Paths(4, "'200':")
s.Paths(5, "description: OK")
s.Paths(5, "content:")
s.Paths(6, "application/json:")
s.Paths(7, "schema:")
s.Paths(8, "$ref: '#/components/schemas/statusObject'")

s.generatedResources["status"] = true
s.Resources(2, "statusResource:")
s.Resources(3, "type: array")
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/mcapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ func (client *Client) Login(ctx context.Context) error {
return err
}

// Login: Called to log into the storage controller API
func (client *Client) Logout() error {
if client.Ctx == nil {
client.Ctx = context.Background()
}
_, _, err := client.apiClient.DefaultApi.LogoutGet(client.Ctx).Execute()
return err
}

// SessionValid : Determine if a session is valid, if not a login is required
func (client *Client) SessionValid(addr, username string) bool {
if client.Ctx == nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/api/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ func (client *Client) ShowVolumes(volume string) ([]common.VolumeObject, *common
}
} else {
logger.V(4).Info("-- ShowVolumesNamesGet", "status", httpRes.Status, "err", err, "body", httpRes.Body)
return nil, &common.ResponseStatus{}, err
}

logger.V(4).Info("================================================================================")

returnVolumes := []common.VolumeObject{}
status := CreateCommonStatus(logger, &response.Status)
status := &common.ResponseStatus{}
if response.Status != nil {
status = CreateCommonStatus(logger, &response.Status)
}

if response != nil {
for _, v := range response.Volumes {
Expand Down
1 change: 1 addition & 0 deletions pkg/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Class | Method | HTTP request | Description
*DefaultApi* | [**DeleteVolumesNamesGet**](docs/DefaultApi.md#deletevolumesnamesget) | **Get** /delete/volumes/{namesOption} |
*DefaultApi* | [**ExpandVolumeSizeNameGet**](docs/DefaultApi.md#expandvolumesizenameget) | **Get** /expand/volume/size/{sizeOption}/{nameOption} |
*DefaultApi* | [**LoginGet**](docs/DefaultApi.md#loginget) | **Get** /login |
*DefaultApi* | [**LogoutGet**](docs/DefaultApi.md#logoutget) | **Get** /logout |
*DefaultApi* | [**MapVolumeAccessLunInitiatorNamesGet**](docs/DefaultApi.md#mapvolumeaccessluninitiatornamesget) | **Get** /map/volume/access/{accessOption}/lun/{lunOption}/initiator/{initiatorOption}/{namesOption} |
*DefaultApi* | [**SchemaGet**](docs/DefaultApi.md#schemaget) | **Get** /meta/{schemaId} |
*DefaultApi* | [**SetInitiatorIdNicknameGet**](docs/DefaultApi.md#setinitiatoridnicknameget) | **Get** /set/initiator/id/{idOption}/nickname/{nicknameOption} |
Expand Down
13 changes: 13 additions & 0 deletions pkg/client/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ paths:
description: OK
security:
- basicAuth: []
/logout:
get:
description: Log out of the storage array management controller
operationId: LogoutGet
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/statusObject'
description: OK
security:
- basicAuth: []
/meta/{schemaId}:
get:
description: Retrieve schema definition for a resource
Expand Down
100 changes: 100 additions & 0 deletions pkg/client/api_default.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions pkg/client/docs/DefaultApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Method | HTTP request | Description
[**DeleteVolumesNamesGet**](DefaultApi.md#DeleteVolumesNamesGet) | **Get** /delete/volumes/{namesOption} |
[**ExpandVolumeSizeNameGet**](DefaultApi.md#ExpandVolumeSizeNameGet) | **Get** /expand/volume/size/{sizeOption}/{nameOption} |
[**LoginGet**](DefaultApi.md#LoginGet) | **Get** /login |
[**LogoutGet**](DefaultApi.md#LogoutGet) | **Get** /logout |
[**MapVolumeAccessLunInitiatorNamesGet**](DefaultApi.md#MapVolumeAccessLunInitiatorNamesGet) | **Get** /map/volume/access/{accessOption}/lun/{lunOption}/initiator/{initiatorOption}/{namesOption} |
[**SchemaGet**](DefaultApi.md#SchemaGet) | **Get** /meta/{schemaId} |
[**SetInitiatorIdNicknameGet**](DefaultApi.md#SetInitiatorIdNicknameGet) | **Get** /set/initiator/id/{idOption}/nickname/{nicknameOption} |
Expand Down Expand Up @@ -687,6 +688,67 @@ Other parameters are passed through a pointer to a apiLoginGetRequest struct via
[[Back to README]](../README.md)


## LogoutGet

> StatusObject LogoutGet(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.LogoutGet(context.Background()).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DefaultApi.LogoutGet``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `LogoutGet`: StatusObject
fmt.Fprintf(os.Stdout, "Response from `DefaultApi.LogoutGet`: %v\n", resp)
}
```

### Path Parameters

This endpoint does not need any parameter.

### Other Parameters

Other parameters are passed through a pointer to a apiLogoutGetRequest 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)


## MapVolumeAccessLunInitiatorNamesGet

> StatusObject MapVolumeAccessLunInitiatorNamesGet(ctx, accessOption, lunOption, initiatorOption, namesOption).Execute()
Expand Down
31 changes: 20 additions & 11 deletions pkg/client/test/api_default_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pkg/regression/v2_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,17 @@ var _ = DescribeRegression("Login Testing (v2)", func(tc *TestContext) {
Expect(valid).To(Equal(true))
})

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)
Expect(err).To(BeNil())
})

It("should be an invalid session", func() {
valid := client.SessionValid(client.Addr, client.Username)
Expect(valid).To(Equal(false))
})

})
})

0 comments on commit fd3c437

Please sign in to comment.