Delete API Key
You can delete an API key from Palette. A tenant admin can also delete an API key created by another user within the tenant. Use the following steps to delete an API key.
The following sections provide information on how to delete an API key in Palette through the UI, API, and SDK.
UI
Tenant administrators can delete an API key on behalf of any user within the tenant. Select the Tenant tab below to learn more about deleting an API key as a tenant admin.
Prerequisites
- User
- Tenant
-
You must have a Palette account, and you must be logged in.
-
You must have an API key created. Refer to the Create API Key section for more information.
-
You must have a Palette account, and you must be logged in.
-
Tenant administrator access.
-
An existing API key must be available.
Delete API Key in Palette UI
- User
- Tenant
-
Log in to Palette.
-
Navigate to the User Menu, and select My API Keys.
-
Identify your API key in the table, and click on the three-dot Menu.
-
Click on Delete.
-
Log in to Palette as a tenant admin.
-
Switch to the Tenant Admin scope.
-
Navigate to the left Main Menu and select Tenant Settings.
-
From the Tenant Settings Menu, select API Keys.
-
Identify the API key in the table you want to remove, and click on the three-dot Menu.
-
Click on Delete.
Validate
- User
- Tenant
-
Log in to Palette.
-
Navigate to the User Menu, and select My API Keys.
-
Verify your API key is not listed in the table.
-
Log in to Palette as a tenant admin.
-
Switch to the Tenant Admin scope.
-
Navigate to the left Main Menu and select Tenant Settings.
-
From the Tenant Settings Menu, select API Keys.
-
Verify the API key is not listed in the table.
API
You can use the Palette API with the https://api.spectrocloud.com/v1/apiKeys/:uid
endpoint and the API key's unique identifier to delete
an API key programmatically.
Use the following steps to learn how to delete an API key.
Prerequisites
-
You must have a valid Palette API key. Refer to the Create API Key section for more information.
-
A terminal or command prompt to execute the
curl
command. Alternatively, you can use a REST client like Postman.
Delete API Key with API
-
Open a terminal or command prompt.
-
Issue the following command to retrieve your API key's unique identifier. Replace
API_KEY_VALUE
with your API key.curl --location 'https://api.spectrocloud.com/v1/apiKeys' \
--header 'Accept: application/json' \
--header 'apiKey: API_KEY_VALUE'{
"items": [
{
"metadata": {
"annotations": {
"description": "",
"ownerUid": "****************",
"permissions": "apiKey.create,apiKey.delete,apiKey.get,apiKey.list,apiKey.update,tag.update",
"scope": "tenant",
"scopeVisibility": "20",
"tenantUid": "*************************"
},
"creationTimestamp": "2024-09-16T14:46:28.677Z",
"deletionTimestamp": "0001-01-01T00:00:00.000Z",
"lastModifiedTimestamp": "2024-09-16T14:46:29.079Z",
"name": "remove-me-test",
"uid": "66e844c44bab2337f20c7471"
},
"spec": {
"expiry": "2024-09-23T14:46:28.164Z",
"user": {
"firstName": "example",
"lastName": "example",
"uid": "*****************"
}
},
"status": {
"isActive": true
}
}
]
} -
Once you have the API key's unique identifier, issue the following command to delete the API key. Replace
uid
with the API key's unique identifier. Specify a valid API key in theApiKey
header.curl -L -X DELETE 'https://api.spectrocloud.com/v1/apiKeys/:uid' \
-H 'ApiKey: <API_KEY_VALUE>' -
No output is expected if the API key is successfully deleted.
Validate
-
Verify the API key is no longer available in Palette by issuing the following command. Replace
API_KEY_VALUE
with your API key.curl --location 'https://api.spectrocloud.com/v1/apiKeys' \
--header 'Accept: application/json' \
--header 'apiKey: API_KEY_VALUE' -
The API key should not be listed in the response. If the API key is still available, verify the API key's unique identifier and reissue the delete command. You can also validate the deletion by checking the Palette UI.
SDK
You can use the Palette SDK to delete an API key programmatically.
Prerequisites
-
You must have a valid Palette API key. Refer to the Create API Key section for more information.
-
Go version 1.22 or later.
-
A text editor or an IDE to write and execute the Go code.
-
A valid Palette API key to delete. In this example, the fictional API key named
delete-test-key
is used. -
An internet connection to download the Palette SDK and its dependencies.
Delete API Key With Go SDK
-
Create a new directory for your Go project and navigate to the directory.
mkdir delete-api-key && cd delete-api-key
-
Create a new Go file, for example, main.go.
touch main.go
-
Initialize the Go module. Use the following command to initialize the Go module.
go mod init example/delete-api-key
-
Open the main.go file in your text editor or IDE.
-
Copy and paste the following code snippet into the main.go file. Replace the variable
keyName
with the key name you want to delete.package main
import (
"fmt"
"log"
"log/slog"
"os"
"github.com/spectrocloud/palette-sdk-go/client"
)
func main() {
host := os.Getenv("PALETTE_HOST") // "api.spectrocloud.com"
apiKey := os.Getenv("PALETTE_API_KEY") // "your api key"
if host == "" || apiKey == "" {
log.Fatal("Please set PALETTE_HOST and PALETTE_API_KEY environment variables")
}
keyName := "delete-test-key" // "name of the key to delete. Replace as needed"
pc := client.New(
client.WithPaletteURI(host),
client.WithAPIKey(apiKey),
)
keys, err := pc.GetAPIKeys()
if err != nil {
log.Fatal("Error getting API keys: ", err)
}
for _, key := range keys.Items {
if key.Metadata.Name == keyName {
slog.Info(fmt.Sprintf("API key found. Deleting API key: %s", key.Metadata.Name))
err := pc.DeleteAPIKey(key.Metadata.UID)
if err != nil {
log.Fatal("Error deleting API key: ", err)
}
slog.Info("API key deleted successfully")
}
}
} -
Set the environment variables for the Palette host and API key. Replace
api.spectrocloud.com
with your Palette host URL if you are using a self-hosted Palette or VerteX instance.export PALETTE_HOST="api.spectrocloud.com"
export PALETTE_API_KEY="your api key" -
Start the Go program.
go get ./... && go run .
2024/09/16 08:27:12 INFO API key found. Deleting API key: delete-test-key
2024/09/16 08:27:12 INFO API key deleted successfully
Validate
You can validate the deletion by checking the Palette UI or by querying the API with the GetAPIKeys()
method to list
the API keys again and verifying the API key is no longer available.
-
Create a function to list the API keys and verify the API key is no longer available. Use the following code snippet to validate the deletion.
// validateKeyIsRemoved checks if the key is removed
// returns true if the key is removed, false otherwise
func validateKeyIsRemoved(keyName string, pc *client.V1Client) (bool, error) {
keys, err := pc.GetAPIKeys()
if err != nil {
log.Fatal("Error getting API keys: ", err)
}
for _, key := range keys.Items {
if key.Metadata.Name == keyName {
return false, nil
}
}
return true, nil
} -
Replace the entire content of the main.go file with the following code snippet to include the validation check.
package main
import (
"fmt"
"log"
"log/slog"
"os"
"github.com/spectrocloud/palette-sdk-go/client"
)
func main() {
host := os.Getenv("PALETTE_HOST") // "api.spectrocloud.com"
apiKey := os.Getenv("PALETTE_API_KEY") // "your api key"
if host == "" || apiKey == "" {
log.Fatal("Please set PALETTE_HOST and PALETTE_API_KEY environment variables")
}
keyName := "delete-test-key" // "name of the key to delete"
pc := client.New(
client.WithPaletteURI(host),
client.WithAPIKey(apiKey),
)
keys, err := pc.GetAPIKeys()
if err != nil {
log.Fatal("Error getting API keys: ", err)
}
for _, key := range keys.Items {
if key.Metadata.Name == keyName {
slog.Info(fmt.Sprintf("API key found. Deleting API key: %s", key.Metadata.Name))
err := pc.DeleteAPIKey(key.Metadata.UID)
if err != nil {
log.Fatal("Error deleting API key: ", err)
}
slog.Info("API key deleted successfully")
}
}
ok, err := validateKeyIsRemoved(keyName, pc)
if err != nil {
log.Fatal("Error validating key is removed: ", err)
}
if !ok {
log.Fatal("API key is not removed")
}
slog.Info("Validation ensured the key is removed successfully")
}
// validateKeyIsRemoved checks if the key is removed
// returns true if the key is removed, false otherwise
func validateKeyIsRemoved(keyName string, pc *client.V1Client) (bool, error) {
keys, err := pc.GetAPIKeys()
if err != nil {
log.Fatal("Error getting API keys: ", err)
}
for _, key := range keys.Items {
if key.Metadata.Name == keyName {
return false, nil
}
}
return true, nil
} -
Start the Go program.
go get ./... && go run .
2024/09/16 08:35:07 INFO Validation ensured the API key is removed successfully
-
The output confirms the API key is successfully deleted.