diff --git a/CHANGELOG.md b/CHANGELOG.md index f875f73..16ad247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/clients/restore/restore.go b/clients/restore/restore.go index 03e2813..73375d4 100644 --- a/clients/restore/restore.go +++ b/clients/restore/restore.go @@ -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 { diff --git a/cmd/influx/restore.go b/cmd/influx/restore.go index 7e350b3..7cc95ee 100644 --- a/cmd/influx/restore.go +++ b/cmd/influx/restore.go @@ -91,6 +91,7 @@ Examples: RestoreApi: api.RestoreApi.OnlyOSS(), BucketsApi: api.BucketsApi, OrganizationsApi: api.OrganizationsApi, + ApiConfig: api, } return client.Restore(getContext(ctx), ¶ms) },