-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add API key invalidation on unenroll ACK. * Fix import location. * Fix test. (cherry picked from commit dc762b5)
- Loading branch information
1 parent
0322984
commit f2841a5
Showing
5 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package apikey | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/elastic/go-elasticsearch/v8" | ||
"github.com/elastic/go-elasticsearch/v8/esapi" | ||
) | ||
|
||
// Invalidate invalidates the provides API keys by ID. | ||
func Invalidate(ctx context.Context, client *elasticsearch.Client, ids ...string) error { | ||
|
||
payload := struct { | ||
IDs []string `json:"ids,omitempty"` | ||
}{ | ||
ids, | ||
} | ||
|
||
body, err := json.Marshal(&payload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
opts := []func(*esapi.SecurityInvalidateAPIKeyRequest){ | ||
client.Security.InvalidateAPIKey.WithContext(ctx), | ||
} | ||
|
||
res, err := client.Security.InvalidateAPIKey( | ||
bytes.NewReader(body), | ||
opts..., | ||
) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
defer res.Body.Close() | ||
|
||
if res.IsError() { | ||
return fmt.Errorf("fail InvalidateAPIKey: %s", res.String()) | ||
} | ||
return nil | ||
} |