Skip to content

Commit

Permalink
add flag to safely export data without any credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu committed Nov 19, 2023
1 parent 30676c8 commit 4f73f81
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 20 deletions.
2 changes: 2 additions & 0 deletions api/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ api_roles_monitoring.go
api_roles_tsdb.go
client.go
configuration.go
docs/ApiAPIExportInput.md
docs/ApiAPIExportOutput.md
docs/ApiAPIImportInput.md
docs/ApiAPILogMessage.md
Expand Down Expand Up @@ -106,6 +107,7 @@ docs/TypesOIDCConfig.md
git_push.sh
go.mod
go.sum
model_api_api_export_input.go
model_api_api_export_output.go
model_api_api_import_input.go
model_api_api_log_message.go
Expand Down
3 changes: 2 additions & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Class | Method | HTTP request | Description
*RolesApiApi* | [**ApiAuthConfig**](docs/RolesApiApi.md#apiauthconfig) | **Get** /api/v1/auth/config | API Users
*RolesApiApi* | [**ApiDeleteTokens**](docs/RolesApiApi.md#apideletetokens) | **Delete** /api/v1/auth/tokens | Tokens
*RolesApiApi* | [**ApiDeleteUsers**](docs/RolesApiApi.md#apideleteusers) | **Delete** /api/v1/auth/users | API Users
*RolesApiApi* | [**ApiExport**](docs/RolesApiApi.md#apiexport) | **Get** /api/v1/cluster/export | Export Cluster
*RolesApiApi* | [**ApiExport**](docs/RolesApiApi.md#apiexport) | **Post** /api/v1/cluster/export | Export Cluster
*RolesApiApi* | [**ApiGetLogMessages**](docs/RolesApiApi.md#apigetlogmessages) | **Get** /api/v1/cluster/node/logs | Log messages
*RolesApiApi* | [**ApiGetMembers**](docs/RolesApiApi.md#apigetmembers) | **Get** /api/v1/etcd/members | Etcd members
*RolesApiApi* | [**ApiGetMetricsCpu**](docs/RolesApiApi.md#apigetmetricscpu) | **Get** /api/v1/system/metrics/cpu | System Metrics
Expand Down Expand Up @@ -140,6 +140,7 @@ Class | Method | HTTP request | Description

## Documentation For Models

- [ApiAPIExportInput](docs/ApiAPIExportInput.md)
- [ApiAPIExportOutput](docs/ApiAPIExportOutput.md)
- [ApiAPIImportInput](docs/ApiAPIImportInput.md)
- [ApiAPILogMessage](docs/ApiAPILogMessage.md)
Expand Down
14 changes: 13 additions & 1 deletion api/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,13 @@ paths:
tags:
- roles/backup
/api/v1/cluster/export:
get:
post:
operationId: api.export
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ApiAPIExportInput'
responses:
"200":
content:
Expand Down Expand Up @@ -1522,6 +1527,13 @@ paths:
- roles/api
components:
schemas:
ApiAPIExportInput:
example:
safe: true
properties:
safe:
type: boolean
type: object
ApiAPIExportOutput:
example:
entries:
Expand Down
16 changes: 12 additions & 4 deletions api/api_roles_api.go

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

56 changes: 56 additions & 0 deletions api/docs/ApiAPIExportInput.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# ApiAPIExportInput

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Safe** | Pointer to **bool** | | [optional]

## Methods

### NewApiAPIExportInput

`func NewApiAPIExportInput() *ApiAPIExportInput`

NewApiAPIExportInput instantiates a new ApiAPIExportInput object
This constructor will assign default values to properties that have it defined,
and makes sure properties required by API are set, but the set of arguments
will change when the set of required properties is changed

### NewApiAPIExportInputWithDefaults

`func NewApiAPIExportInputWithDefaults() *ApiAPIExportInput`

NewApiAPIExportInputWithDefaults instantiates a new ApiAPIExportInput object
This constructor will only assign default values to properties that have it defined,
but it doesn't guarantee that properties required by API are set

### GetSafe

`func (o *ApiAPIExportInput) GetSafe() bool`

GetSafe returns the Safe field if non-nil, zero value otherwise.

### GetSafeOk

`func (o *ApiAPIExportInput) GetSafeOk() (*bool, bool)`

GetSafeOk returns a tuple with the Safe field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetSafe

`func (o *ApiAPIExportInput) SetSafe(v bool)`

SetSafe sets Safe field to given value.

### HasSafe

`func (o *ApiAPIExportInput) HasSafe() bool`

HasSafe returns a boolean if a field has been set.


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


15 changes: 10 additions & 5 deletions api/docs/RolesApiApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Method | HTTP request | Description
[**ApiAuthConfig**](RolesApiApi.md#ApiAuthConfig) | **Get** /api/v1/auth/config | API Users
[**ApiDeleteTokens**](RolesApiApi.md#ApiDeleteTokens) | **Delete** /api/v1/auth/tokens | Tokens
[**ApiDeleteUsers**](RolesApiApi.md#ApiDeleteUsers) | **Delete** /api/v1/auth/users | API Users
[**ApiExport**](RolesApiApi.md#ApiExport) | **Get** /api/v1/cluster/export | Export Cluster
[**ApiExport**](RolesApiApi.md#ApiExport) | **Post** /api/v1/cluster/export | Export Cluster
[**ApiGetLogMessages**](RolesApiApi.md#ApiGetLogMessages) | **Get** /api/v1/cluster/node/logs | Log messages
[**ApiGetMembers**](RolesApiApi.md#ApiGetMembers) | **Get** /api/v1/etcd/members | Etcd members
[**ApiGetMetricsCpu**](RolesApiApi.md#ApiGetMetricsCpu) | **Get** /api/v1/system/metrics/cpu | System Metrics
Expand Down Expand Up @@ -212,7 +212,7 @@ No authorization required

## ApiExport

> ApiAPIExportOutput ApiExport(ctx).Execute()
> ApiAPIExportOutput ApiExport(ctx).ApiAPIExportInput(apiAPIExportInput).Execute()
Export Cluster

Expand All @@ -229,10 +229,11 @@ import (
)

func main() {
apiAPIExportInput := *openapiclient.NewApiAPIExportInput() // ApiAPIExportInput | (optional)

configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.RolesApiApi.ApiExport(context.Background()).Execute()
resp, r, err := apiClient.RolesApiApi.ApiExport(context.Background()).ApiAPIExportInput(apiAPIExportInput).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `RolesApiApi.ApiExport``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
Expand All @@ -244,13 +245,17 @@ func main() {

### Path Parameters

This endpoint does not need any parameter.


### Other Parameters

Other parameters are passed through a pointer to a apiApiExportRequest struct via the builder pattern


Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**apiAPIExportInput** | [**ApiAPIExportInput**](ApiAPIExportInput.md) | |

### Return type

[**ApiAPIExportOutput**](ApiAPIExportOutput.md)
Expand All @@ -261,7 +266,7 @@ No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Content-Type**: application/json
- **Accept**: application/json

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints)
Expand Down
124 changes: 124 additions & 0 deletions api/model_api_api_export_input.go

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

8 changes: 7 additions & 1 deletion cmd/cli_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import (
"encoding/json"
"os"

"beryju.io/gravity/api"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var exportSafe = false

var exportCmd = &cobra.Command{
Use: "export [file]",
Short: "Output entire database into JSON file",
Run: func(cmd *cobra.Command, args []string) {
exp, _, err := apiClient.RolesApiApi.ApiExport(cmd.Context()).Execute()
exp, _, err := apiClient.RolesApiApi.ApiExport(cmd.Context()).ApiAPIExportInput(api.ApiAPIExportInput{
Safe: &exportSafe,
}).Execute()
if err != nil {
logger.Error("failed to export", zap.Error(err))
return
Expand All @@ -37,5 +42,6 @@ var exportCmd = &cobra.Command{
}

func init() {
exportCmd.Flags().BoolVar(&exportSafe, "safe", false, "Export only safe values")
cliCmd.AddCommand(exportCmd)
}
Loading

0 comments on commit 4f73f81

Please sign in to comment.