Infisical::SDK, lets a Perl application log in to Infisical as a machine identity and create, update, fetch, list, and delete secrets. It can also store the secrets of a folder in %ENV, so that every program your application starts gets the secrets as environment variables.
This page covers the main methods of the SDK. For every method and option, see the Infisical::SDK documentation on MetaCPAN.
Prerequisites
- Perl 5.14 or later
- A machine identity that uses Universal Auth, and its client ID and client secret
- The machine identity added to your project with a role that can read secrets, such as Viewer (or Member, if your application creates, updates, or deletes secrets)
Installation
Getting started
site_url to the URL of your instance. For the EU region of Infisical Cloud, set site_url to https://eu.infisical.com.
Client options
new takes these options, and each of them is optional:
site_url(string): the URL of your Infisical instance, starting withhttp://orhttps://(defaults tohttps://app.infisical.com)timeout(number): the number of seconds to wait for each request (defaults to10)max_retries(integer): the number of times to retry a request after Infisical rate-limits it or after a temporary network error, such as a timeout (defaults to4)ua(object): the HTTP client that the SDK sends requests with, such as an HTTP::Tiny object with proxy settings (any object with HTTP::Tiny’srequestmethod works)
Core methods
The client’s methods are in two groups:auth: logs the client insecrets: creates, updates, fetches, lists, and deletes secrets
project_id. If you pass an argument that the method doesn’t take, such as projectId, the method throws an error and sends nothing to Infisical.
auth
Universal Auth
client_id(string, optional): the client ID of the machine identity (defaults to the value of theINFISICAL_UNIVERSAL_AUTH_CLIENT_IDenvironment variable)client_secret(string, optional): the client secret of the machine identity (defaults to the value of theINFISICAL_UNIVERSAL_AUTH_CLIENT_SECRETenvironment variable)organization_slug(string, optional): the slug of a sub-organization to log in to (defaults to the organization where the machine identity was created)
Infisical::SDK: the client, so you can create the client and log in with one statement
login gets. The token lasts as long as the Access Token TTL in the machine identity’s Universal Auth settings. If your application runs longer than that, call login again.
secrets
Each secrets method works on one folder, which these arguments select:
project_id(string): the ID of your projectenvironment(string): the slug of the environment, such asdevsecret_path(string, optional): the path of the folder, such as/backend(defaults to/)
list and get replace each secret reference, such as ${dev.DB_HOST}, with the value that the reference points to.
For the full reference of these methods, see Infisical::SDK::Secrets.
List secrets
recursive(boolean, optional): whether to also list the secrets in every subfolder ofsecret_path(defaults to false)view_secret_value(boolean, optional): whether to return the secrets’ values (defaults to true; if false, each secret’ssecret_value_hiddenis true and its value is a placeholder)tag_slugs(array reference, optional): tag slugs, to list only the secrets that have at least one of these tagsattach_to_env(boolean, optional): whether to also load the secrets into%ENV(defaults to false)
- A list of
Infisical::SDK::Secretobjects, or the number of secrets if you calllistin scalar context
Get secret by name
secret_name(string): the name of the secretversion(integer, optional): the version of the secret to fetch (defaults to the latest version)view_secret_value(boolean, optional): whether to return the secret’s value (defaults to true)
Infisical::SDK::Secret: the secret
Create secret
secret_name(string): the name of the secretsecret_value(string): the value of the secret, which can be an empty stringsecret_comment(string, optional): a comment that Infisical shows with the secrettag_ids(array reference, optional): the IDs of the tags to add to the secretsecret_metadata(array reference, optional): key-value pairs to store with the secret, each a hash reference withkey,value, and an optional booleanis_encryptedskip_multiline_encoding(boolean, optional): whether to store a multi-line value without encoding its line breaks
Infisical::SDK::Secret: the new secret, without its tags and metadata (callgetfor the full secret)
Update secret
secret_name(string): the current name of the secretnew_secret_name(string, optional): a new name for the secretsecret_value,secret_comment,tag_ids,secret_metadata, andskip_multiline_encoding(optional): the new values, in the same format as forcreate
Infisical::SDK::Secret: the new version of the secret, in whichsecret_valueandsecret_commenthold only the values that this call sent, and tags and metadata are empty (callgetfor the full secret)
Delete secret
secret_name(string): the name of the secret
Infisical::SDK::Secret: the deleted secret, with the values it had before the delete
Secret objects
list, get, create, update, and delete return Infisical::SDK::Secret objects. Each field has a read-only method of the same name:
For an imported secret,
secret_path and environment are the folder and environment that the secret was imported from. For every field, see Infisical::SDK::Secret.
Error handling
If a method fails, it throws anInfisical::SDK::Error object, or an object of one of these subclasses:
This example creates a secret if it doesn’t exist: