Compatible with C++ 17 and later
The Infisical C++ SDK is compatible with C++ 17 capable compilers. This implies GCC 8 or newer, and clang 3.8 or newer. Earlier versions of C++ are unsupported.Dependencies
- cURL: Used internally for crafting HTTP requests.
CMake Installation
Manual Installation
If you’re unable to use the recommended CMake installation approach, you can choose to manually build the library and use it in your project.Quick-Start Example
Below you’ll find an example that uses the Infisical SDK to fetch a secret with the keyAPI_KEY using Machine Identity Universal Auth
More examples can be found in the /examples folder.
JSON Serialization
The SDK uses nlohmann/json internally to serialize/deserialize JSON data. This SDK makes no assumptions about which JSON library you use in your project, and you aren’t constrained tonlohmann/json in any way. Data returned by the SDK is returned as a class, which exposes Getter methods for getting fields such as the secret value or secret key.
Documentation
The Infisical C++ SDK follows a builder pattern for all types of input. Below is a detailed documentation of our currently support methods. Everything related to the Infisical SDK lives inside theInfisical namespace.
InfisicalClient Class
InfisicalClient(Config &config)
ConfigBuilder class. See below for more details
Config Class
Config defines the configuration of the Infisical Client itself, such as authentication.
- withHostUrl(string)(optional): Specify a custom Infisical host URL, pointing to your Infisical instance. Defaults to- https://app.infisical.com
- withAuthentication(Infisical::Authentication): Configure the authentication that will be used by the SDK. See Authentication Class for more details.
- build(): Returns the- Configobject with the options you configured.
Authentication Class
- withUniversalAuth(string, string): Specify the Universal Auth Client ID and Client Secret that will be used for authentication.
- build(): Returns the- Authenticationobject with the options you specified.
TSecret Class
TheTSecret class is the class that’s returned by all secret methods (get/list/delete/update/create). It can come in the form of a std::vector or a single instance.
Available getter methods:
- getId(): std::string: Returns the ID of the secret.
- getWorkspace(): std::string: Returns the project ID of the secret.
- getEnvironment(): std::string: Returns the environment slug of the secret.
- getVersion(): unsigned int: Gets the version of the secret. By default this will always be the latest version unless specified otherwise with- withVersion()
- getType(): std::string: Returns the type of the secret. Can only be- sharedor- personal. Shared secrets are available to everyone with access to the secret. Personal secrets are personal overwrites of the secret, mainly intended for local development purposes.
- getSecretKey(): std::string: Returns the secret key.
- getSecretValue(): std::stringReturns the secret value.
- getRotationId(): std::string: If the secret is a rotation secret, this will return the rotation ID of the secret. If it’s a regular secret, this will return an empty string.
- getSecretPath(): std::string: Returns the secret path of the secret.
- getSkipMultilineEncoding(): bool: Returns whether or not skip multiline encoding is enabled for the secret or not.- getIsRotatedSecret(): bool: Returns wether or not the secret is a rotated secret. If- true, then- getRotationId()returns the ID of the rotation.
Secrets
Create Secret
- withEnvironment(string): Specify the slug of the environment to create the secret in.
- withProjectId(string): Specify the ID of the project to create the secret in.
- withSecretPath(string): Specify the secret path to create the secret in. Defaults to- /
- withSecretKey(string): The secret key to be created.
- withSecretValue(string): The value of the secret to create.
- withSecretComment(string)(optional): Optionally add a comment to the secret.
- withTagIds(std::vector<std::string>>)(optional): A list of ID’s of tags to attach to the secret.
- build(): Returns the- CreateSecretOptionsclass that can be passed into the- createSecret()method.
- Returns the created secret as a TSecretclass. Read more in the TSecret Class documentation.
Update Secret
- withEnvironment(string): Specify the slug of the environment where the secret lives in.
- withProjectId(string): Specify the ID of the project where the secret to update lives in.
- withSecretPath(string): Specify the secret path of the secret to update. Defaults to- /.
- withType("shared" | "personal"): (optional): The type of secret to update. Defaults to- shared.
- withSecretKey(string): The key of the secret you wish to update.
- withNewSecretKey(string)(optional): The new key of the secret you wish to update.
- withSecretValue(string)(optional): The new value of the secret.
- withSecretReminderNote(string)(optional): Update the secret reminder note attached to the secret.
- withSecretReminderRepeatDays(unsigned int)(optional): Update the secret reminder repeat days attached to the secret.
- withTagIds(std::vector<std::string>>)(optional): A list of ID’s of tags to attach to the secret.
- build(): Returns the- UpdateSecretOptionsclass that can be passed into the- updateSecret()method.
- Returns the updated secret as a TSecretclass. Read more in the TSecret Class documentation.
Get Secret
- withEnvironment(string): Specify the slug of the environment where the secret lives in.
- withProjectId(string): Specify the ID of the project where the secret lives in.
- withSecretPath(string): Specify the secret path of the secret to get. Defaults to- /
- withType("shared" | "personal"): (optional): The type of secret to get. Defaults to- shared.
- withSecretKey(string): The key of the secret to get.
- withExpandSecretReferences(bool)(optional): Whether or not to expand secret references automatically. Defaults to- true.
- withVersion(unsigned int)(optional): Optionally fetch a specific version of the secret. If not defined, the latest version of the secret is returned.
- build(): Returns the- GetSecretOptionsclass that can be passed into the- getSecret()method.
- Returns the secret as a TSecretclass. Read more in the TSecret Class documentation.
Delete Secret
- withEnvironment(string): Specify the slug of the environment where the secret to delete lives in.
- withProjectId(string): Specify the ID of the project where the secret to delete lives in.
- withSecretPath(string): Specify the secret path of the secret to delete. Defaults to- /
- withType("shared" | "personal"): (optional): The type of secret to delete. Defaults to- shared.
- withSecretKey(string): The key of the secret to delete.
- build()Returns the- DeleteSecretOptionsclass that can be passed into the- deleteSecret()method.
- Returns the deleted secret as a TSecretclass. Read more in the TSecret Class documentation.
List Secrets
- withEnvironment(string): Specify the slug of the environment to list secrets from.
- withProjectId(string): Specify the ID of the project to fetch secrets from.
- withSecretPath(string): Specify the secret path to fetch secrets from. Defaults to- /
- withExpandSecretReferences(bool)(optional): Whether or not to expand secret references automatically. Defaults to- true.
- withRecursive(bool)(optional): Wether or not to recursively fetch secrets from sub-folders. If set to true, all secrets from the secret path specified with- withSecretPath()and downwards will be fetched.
- withAddSecretsToEnvironmentVariables(bool)(optional): If set to true, the fetched secrets will be automatically set as environment variables, making them accessible with- std::getenvor equivalent by secret key.
- build(): Returns the- ListSecretsOptionsclass that can be passed into the- listSecrets()method.
- Returns the listed secrets as std::vector<TSecret>. Read more in the TSecret Class documentation.