Skip to content

Commit

Permalink
fix: invalidating API Keys against ES master (#4587)
Browse files Browse the repository at this point in the history
The ES InvalidateApiKey API does not support param ID anymore. Switch
to using IDs instead. Related elastic/elasticsearch#66671
  • Loading branch information
simitt authored Dec 24, 2020
1 parent fd21932 commit 3858a27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
19 changes: 7 additions & 12 deletions cmd/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ If neither of them are, an error will be returned.`,
// TODO(axw) this should trigger usage
return errors.New(`either "id" or "name" are required`)
}
return invalidateAPIKey(client, &id, &name, json)
return invalidateAPIKey(client, id, name, json)
}),
}
invalidate.Flags().StringVar(&id, "id", "", "id of the API Key to delete")
Expand Down Expand Up @@ -393,17 +393,12 @@ func getAPIKey(client es.Client, id, name *string, validOnly, asJSON bool) error
return nil
}

func invalidateAPIKey(client es.Client, id, name *string, asJSON bool) error {
if isSet(id) {
name = nil
} else if isSet(name) {
id = nil
}
invalidateKeysRequest := es.InvalidateAPIKeyRequest{
APIKeyQuery: es.APIKeyQuery{
ID: id,
Name: name,
},
func invalidateAPIKey(client es.Client, id string, name string, asJSON bool) error {
invalidateKeysRequest := es.InvalidateAPIKeyRequest{}
if id != "" {
invalidateKeysRequest.IDs = []string{id}
} else if name != "" {
invalidateKeysRequest.Name = &name
}
invalidation, err := es.InvalidateAPIKey(context.Background(), client, invalidateKeysRequest)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion elasticsearch/security_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ type HasPrivilegesResponse struct {
}

type InvalidateAPIKeyRequest struct {
APIKeyQuery
// normally the Elasticsearch API will require either Ids or Name, but not both
IDs []string `json:"ids,omitempty"`
Name *string `json:"name,omitempty"`
}

type InvalidateAPIKeyResponse struct {
Expand Down

0 comments on commit 3858a27

Please sign in to comment.