cb-core-secrets-manager.php
Table of Contents
Functions
- cb_core_generate_uuid() : string
- CB Core Generate UUID
- cb_core_set_api_key() : string
- CB Core Set API Key
- cb_core_get_api_key() : string
- CB Core Get API Key
- cb_core_secrets_manager_init() : string
- CB Core Secrets Manager Init
- cb_core_update_api_key() : string
- CB Core Update API Key
- cb_core_validate_api_key() : bool
- Validates against a supplied API key safe name.
Functions
cb_core_generate_uuid()
CB Core Generate UUID
cb_core_generate_uuid([mixed $bytes = 32 ]) : string
Generates a UUID that we can use to create unique keys and other neat things for API validation and the like. "Cryptographically secure", unless someone is using a quantum computer. In which case... you're really picking this program as the thing you want to hack? Really?
Parameters
- $bytes : mixed = 32
Tags
Return values
string —An RFC 4211 compliant universally unique identifier.
cb_core_set_api_key()
CB Core Set API Key
cb_core_set_api_key([array<string|int, mixed> $args = [] ]) : string
Sets the encryption key that we use to encrypt and decrypt our API key in the database.
Parameters
- $args : array<string|int, mixed> = []
-
{ Array of arguments.
@type string $Name Required. A name for the secret. We hang onto this and use it to pull the secret from our secrets manager.
@type string $Description Optional. A description for the secret. Nice to have if you want, but not entirely necessary.
@type string $SecretString Required. This is a secret! Handle with extreme care. Please.
}
Return values
string —Results of the createSecret method, or error message on failure.
cb_core_get_api_key()
CB Core Get API Key
cb_core_get_api_key([mixed $secret = '' ]) : string
Pulls the API key from our secrets manager. You may wanna study up on AWS!
Parameters
- $secret : mixed = ''
Tags
Return values
string —The API key. Use with caution, share with none.
cb_core_secrets_manager_init()
CB Core Secrets Manager Init
cb_core_secrets_manager_init() : string
Creates our first set of API credentials automatically. Can refresh them at any time via WordPress admin panel.
Tags
Return values
string —The stringified Model data, or error message on failure.
cb_core_update_api_key()
CB Core Update API Key
cb_core_update_api_key() : string
Creates a new API key in our secrets manager and updates its safe name in the options table.
Tags
Return values
string —The stringified Model data, or error message on failure.
cb_core_validate_api_key()
Validates against a supplied API key safe name.
cb_core_validate_api_key([string $safe_name = '' ]) : bool
We work with safe names here. We store the safe name in our DB, and that works as the current valid API key for the current website. If the safe name that gets supplied does not match our safe name, it will fail the test. If the supplied safe name matches, it will then search our secrets manager for a valid API key. If one is not found, or it is expired or invalid, it will also fail.
Parameters
- $safe_name : string = ''
-
The safe name for our API key.
Tags
Return values
bool —Whether the API key exists and is valid.