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:
parent
64b1b03f8f
commit
c4a5a13c8e
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -91,6 +91,7 @@ Examples:
|
||||
RestoreApi: api.RestoreApi.OnlyOSS(),
|
||||
BucketsApi: api.BucketsApi,
|
||||
OrganizationsApi: api.OrganizationsApi,
|
||||
ApiConfig: api,
|
||||
}
|
||||
return client.Restore(getContext(ctx), ¶ms)
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user