Skip to content

Commit 3858a27

Browse files
authored
fix: invalidating API Keys against ES master (#4587)
The ES InvalidateApiKey API does not support param ID anymore. Switch to using IDs instead. Related elastic/elasticsearch#66671
1 parent fd21932 commit 3858a27

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

cmd/apikey.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ If neither of them are, an error will be returned.`,
116116
// TODO(axw) this should trigger usage
117117
return errors.New(`either "id" or "name" are required`)
118118
}
119-
return invalidateAPIKey(client, &id, &name, json)
119+
return invalidateAPIKey(client, id, name, json)
120120
}),
121121
}
122122
invalidate.Flags().StringVar(&id, "id", "", "id of the API Key to delete")
@@ -393,17 +393,12 @@ func getAPIKey(client es.Client, id, name *string, validOnly, asJSON bool) error
393393
return nil
394394
}
395395

396-
func invalidateAPIKey(client es.Client, id, name *string, asJSON bool) error {
397-
if isSet(id) {
398-
name = nil
399-
} else if isSet(name) {
400-
id = nil
401-
}
402-
invalidateKeysRequest := es.InvalidateAPIKeyRequest{
403-
APIKeyQuery: es.APIKeyQuery{
404-
ID: id,
405-
Name: name,
406-
},
396+
func invalidateAPIKey(client es.Client, id string, name string, asJSON bool) error {
397+
invalidateKeysRequest := es.InvalidateAPIKeyRequest{}
398+
if id != "" {
399+
invalidateKeysRequest.IDs = []string{id}
400+
} else if name != "" {
401+
invalidateKeysRequest.Name = &name
407402
}
408403
invalidation, err := es.InvalidateAPIKey(context.Background(), client, invalidateKeysRequest)
409404
if err != nil {

elasticsearch/security_api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ type HasPrivilegesResponse struct {
9797
}
9898

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

103105
type InvalidateAPIKeyResponse struct {

0 commit comments

Comments
 (0)