fix: restore when changing tokens works (#297)

* fix: restore when changing tokens works

* fix: remove cruft

* chore: changelog update

* chore: CHANGELOG word-smithing

Co-authored-by: Dan Moran <dmoran@influxdata.com>
This commit is contained in:
Sam Arnold 2021-10-07 08:23:39 -04:00 committed by GitHub
parent 64b1b03f8f
commit c4a5a13c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -5,6 +5,10 @@
1. [259](https://github.com/influxdata/influx-cli/pull/259): Add `-b` shorthand for `--bucket` to `delete`
1. [285](https://github.com/influxdata/influx-cli/pull/285): Add short-hand `--all-access` and `--operator` options to `auth create`.
### Bug Fixes
1. [297](https://github.com/influxdata/influx-cli/pull/297): Detect and warn when `restore --full` changes the operator token.
## v2.1.1 [2021-09-22]
### Go Version

View File

@ -19,12 +19,17 @@ import (
"github.com/influxdata/influx-cli/v2/pkg/gzip"
)
type ApiConfig interface {
GetConfig() *api.Configuration
}
type Client struct {
clients.CLI
api.HealthApi
api.RestoreApi
api.BucketsApi
api.OrganizationsApi
ApiConfig
manifest br.Manifest
}
@ -169,10 +174,20 @@ func (c Client) fullRestore(ctx context.Context, path string, legacy bool) error
if !legacy {
kvReq = kvReq.ContentEncoding("gzip")
}
// TODO: Use the response object for something here.
if _, err := kvReq.Execute(); err != nil {
// Deal with new token
newOperatorToken, err := kvReq.Execute()
if err != nil {
return fmt.Errorf("failed to restore KV snapshot: %w", err)
}
if newOperatorToken.Token != nil {
newAuthorization := fmt.Sprintf("Token %s", *newOperatorToken.Token)
const authorizationHeader = "Authorization"
if newAuthorization != c.ApiConfig.GetConfig().DefaultHeader[authorizationHeader] {
log.Println("WARN: Restoring KV snapshot overwrote the operator token, ensure following commands use the correct token")
c.ApiConfig.GetConfig().DefaultHeader[authorizationHeader] = newAuthorization
}
}
// TODO: Should we have some way of wiping out any existing SQL on the server-side in the case when there is no backup?
if c.manifest.SQL != nil {

View File

@ -91,6 +91,7 @@ Examples:
RestoreApi: api.RestoreApi.OnlyOSS(),
BucketsApi: api.BucketsApi,
OrganizationsApi: api.OrganizationsApi,
ApiConfig: api,
}
return client.Restore(getContext(ctx), &params)
},