Merge pull request #3132 from Infisical/doc/add-caching-reference-to-go-sdk

doc: add caching reference for go sdk
This commit is contained in:
Maidul Islam
2025-02-19 22:00:27 -05:00
committed by GitHub
+176 -128
View File
@@ -4,8 +4,6 @@ sidebarTitle: "Go"
icon: "golang" icon: "golang"
--- ---
If you're working with Go Lang, the official [Infisical Go SDK](https://github.com/infisical/go-sdk) package is the easiest way to fetch and work with secrets for your application. If you're working with Go Lang, the official [Infisical Go SDK](https://github.com/infisical/go-sdk) package is the easiest way to fetch and work with secrets for your application.
- [Package](https://pkg.go.dev/github.com/infisical/go-sdk) - [Package](https://pkg.go.dev/github.com/infisical/go-sdk)
@@ -57,7 +55,9 @@ func main() {
This example demonstrates how to use the Infisical Go SDK in a simple Go application. The application retrieves a secret named `API_KEY` from the `dev` environment of the `YOUR_PROJECT_ID` project. This example demonstrates how to use the Infisical Go SDK in a simple Go application. The application retrieves a secret named `API_KEY` from the `dev` environment of the `YOUR_PROJECT_ID` project.
<Warning> <Warning>
We do not recommend hardcoding your [Machine Identity Tokens](/platform/identities/overview). Setting it as an environment variable would be best. We do not recommend hardcoding your [Machine Identity
Tokens](/platform/identities/overview). Setting it as an environment variable
would be best.
</Warning> </Warning>
# Installation # Installation
@@ -95,6 +95,10 @@ client := infisical.NewInfisicalClient(context.Background(), infisical.Config{
<ParamField query="SilentMode" type="boolean" default={false} optional> <ParamField query="SilentMode" type="boolean" default={false} optional>
Whether or not to suppress logs such as warnings from the token refreshing process. Defaults to false if not specified. Whether or not to suppress logs such as warnings from the token refreshing process. Defaults to false if not specified.
</ParamField> </ParamField>
<ParamField query="CacheExpiryInSeconds" type="number" default={0} optional>
Defines how long certain responses should be cached in memory, in seconds. When set to a positive value, responses from specific methods (like secret fetching) will be cached for this duration. Set to 0 to disable caching.
</ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
@@ -140,6 +144,7 @@ Call `.Auth().UniversalAuthLogin()` with empty arguments to use the following en
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET` - Your machine identity client secret. - `INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET` - Your machine identity client secret.
**Using the SDK directly** **Using the SDK directly**
```go ```go
_, err := client.Auth().UniversalAuthLogin("CLIENT_ID", "CLIENT_SECRET") _, err := client.Auth().UniversalAuthLogin("CLIENT_ID", "CLIENT_SECRET")
@@ -150,9 +155,12 @@ if err != nil {
``` ```
#### GCP ID Token Auth #### GCP ID Token Auth
<Info> <Info>
Please note that this authentication method will only work if you're running your application on Google Cloud Platform. Please note that this authentication method will only work if you're running
Please [read more](/documentation/platform/identities/gcp-auth) about this authentication method. your application on Google Cloud Platform. Please [read
more](/documentation/platform/identities/gcp-auth) about this authentication
method.
</Info> </Info>
**Using environment variables** **Using environment variables**
@@ -162,6 +170,7 @@ Call `.Auth().GcpIdTokenAuthLogin()` with empty arguments to use the following e
- `INFISICAL_GCP_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID. - `INFISICAL_GCP_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly** **Using the SDK directly**
```go ```go
_, err := client.Auth().GcpIdTokenAuthLogin("YOUR_MACHINE_IDENTITY_ID") _, err := client.Auth().GcpIdTokenAuthLogin("YOUR_MACHINE_IDENTITY_ID")
@@ -181,6 +190,7 @@ Call `.Auth().GcpIamAuthLogin()` with empty arguments to use the following envir
- `INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH` - The path to your GCP service account key file. - `INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH` - The path to your GCP service account key file.
**Using the SDK directly** **Using the SDK directly**
```go ```go
_, err = client.Auth().GcpIamAuthLogin("MACHINE_IDENTITY_ID", "SERVICE_ACCOUNT_KEY_FILE_PATH") _, err = client.Auth().GcpIamAuthLogin("MACHINE_IDENTITY_ID", "SERVICE_ACCOUNT_KEY_FILE_PATH")
@@ -191,9 +201,12 @@ if err != nil {
``` ```
#### AWS IAM Auth #### AWS IAM Auth
<Info> <Info>
Please note that this authentication method will only work if you're running your application on AWS. Please note that this authentication method will only work if you're running
Please [read more](/documentation/platform/identities/aws-auth) about this authentication method. your application on AWS. Please [read
more](/documentation/platform/identities/aws-auth) about this authentication
method.
</Info> </Info>
**Using environment variables** **Using environment variables**
@@ -203,6 +216,7 @@ Call `.Auth().AwsIamAuthLogin()` with empty arguments to use the following envir
- `INFISICAL_AWS_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID. - `INFISICAL_AWS_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly** **Using the SDK directly**
```go ```go
_, err = client.Auth().AwsIamAuthLogin("MACHINE_IDENTITY_ID") _, err = client.Auth().AwsIamAuthLogin("MACHINE_IDENTITY_ID")
@@ -212,11 +226,13 @@ if err != nil {
} }
``` ```
#### Azure Auth #### Azure Auth
<Info> <Info>
Please note that this authentication method will only work if you're running your application on Azure. Please note that this authentication method will only work if you're running
Please [read more](/documentation/platform/identities/azure-auth) about this authentication method. your application on Azure. Please [read
more](/documentation/platform/identities/azure-auth) about this authentication
method.
</Info> </Info>
**Using environment variables** **Using environment variables**
@@ -226,6 +242,7 @@ Call `.Auth().AzureAuthLogin()` with empty arguments to use the following enviro
- `INFISICAL_AZURE_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID. - `INFISICAL_AZURE_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly** **Using the SDK directly**
```go ```go
_, err = client.Auth().AzureAuthLogin("MACHINE_IDENTITY_ID") _, err = client.Auth().AzureAuthLogin("MACHINE_IDENTITY_ID")
@@ -236,9 +253,12 @@ if err != nil {
``` ```
#### Kubernetes Auth #### Kubernetes Auth
<Info> <Info>
Please note that this authentication method will only work if you're running your application on Kubernetes. Please note that this authentication method will only work if you're running
Please [read more](/documentation/platform/identities/kubernetes-auth) about this authentication method. your application on Kubernetes. Please [read
more](/documentation/platform/identities/kubernetes-auth) about this
authentication method.
</Info> </Info>
**Using environment variables** **Using environment variables**
@@ -249,6 +269,7 @@ Call `.Auth().KubernetesAuthLogin()` with empty arguments to use the following e
- `INFISICAL_KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH_ENV_NAME` - The environment variable name that contains the path to the service account token. This is optional and will default to `/var/run/secrets/kubernetes.io/serviceaccount/token`. - `INFISICAL_KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH_ENV_NAME` - The environment variable name that contains the path to the service account token. This is optional and will default to `/var/run/secrets/kubernetes.io/serviceaccount/token`.
**Using the SDK directly** **Using the SDK directly**
```go ```go
// Service account token path will default to /var/run/secrets/kubernetes.io/serviceaccount/token if empty value is passed // Service account token path will default to /var/run/secrets/kubernetes.io/serviceaccount/token if empty value is passed
_, err = client.Auth().KubernetesAuthLogin("MACHINE_IDENTITY_ID", "SERVICE_ACCOUNT_TOKEN_PATH") _, err = client.Auth().KubernetesAuthLogin("MACHINE_IDENTITY_ID", "SERVICE_ACCOUNT_TOKEN_PATH")
@@ -262,6 +283,7 @@ if err != nil {
## Working With Secrets ## Working With Secrets
### List Secrets ### List Secrets
`client.Secrets().List(options)` `client.Secrets().List(options)`
Retrieve all secrets within the Infisical project and environment that client is connected to. Retrieve all secrets within the Infisical project and environment that client is connected to.
@@ -311,7 +333,9 @@ secrets, err := client.Secrets().List(infisical.ListSecretsOptions{
</ParamField> </ParamField>
### ###
### Retrieve Secret ### Retrieve Secret
`client.Secrets().Retrieve(options)` `client.Secrets().Retrieve(options)`
Retrieve a secret from Infisical. By default `Secrets().Retrieve()` fetches and returns a shared secret. Retrieve a secret from Infisical. By default `Secrets().Retrieve()` fetches and returns a shared secret.
@@ -327,27 +351,31 @@ secret, err := client.Secrets().Retrieve(infisical.RetrieveSecretOptions{
### Parameters ### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="SecretKey" type="string" required> <ParamField query="SecretKey" type="string" required>
The key of the secret to retrieve. The key of the secret to retrieve.
</ParamField> </ParamField>
<ParamField query="ProjectID" type="string" required> <ParamField query="ProjectID" type="string" required>
The project ID where the secret lives in. The project ID where the secret lives in.
</ParamField> </ParamField>
<ParamField query="Environment" type="string" required> <ParamField query="Environment" type="string" required>
The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. The slug name (dev, prod, etc) of the environment from where secrets
</ParamField> should be fetched from.
<ParamField query="SecretPath" type="string" optional> </ParamField>
The path from where secret should be fetched from. <ParamField query="SecretPath" type="string" optional>
</ParamField> The path from where secret should be fetched from.
<ParamField query="Type" type="string" optional> </ParamField>
The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". <ParamField query="Type" type="string" optional>
</ParamField> The type of the secret. Valid options are "shared" or "personal". If not
</Expandable> specified, the default value is "shared".
</ParamField>
</Expandable>
</ParamField> </ParamField>
### ###
### Create Secret ### Create Secret
`client.Secrets().Create(options)` `client.Secrets().Create(options)`
Create a new secret in Infisical. Create a new secret in Infisical.
@@ -363,36 +391,38 @@ secret, err := client.Secrets().Create(infisical.CreateSecretOptions{
}) })
``` ```
### Parameters ### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="SecretKey" type="string" required> <ParamField query="SecretKey" type="string" required>
The key of the secret to create. The key of the secret to create.
</ParamField> </ParamField>
<ParamField query="SecretValue" type="string" required> <ParamField query="SecretValue" type="string" required>
The value of the secret. The value of the secret.
</ParamField> </ParamField>
<ParamField query="SecretComment" type="string" optional> <ParamField query="SecretComment" type="string" optional>
A comment for the secret. A comment for the secret.
</ParamField> </ParamField>
<ParamField query="ProjectID" type="string" required> <ParamField query="ProjectID" type="string" required>
The project ID where the secret lives in. The project ID where the secret lives in.
</ParamField> </ParamField>
<ParamField query="Environment" type="string" required> <ParamField query="Environment" type="string" required>
The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. The slug name (dev, prod, etc) of the environment from where secrets
</ParamField> should be fetched from.
<ParamField query="SecretPath" type="string" optional> </ParamField>
The path from where secret should be created. <ParamField query="SecretPath" type="string" optional>
</ParamField> The path from where secret should be created.
<ParamField query="Type" type="string" optional> </ParamField>
The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". <ParamField query="Type" type="string" optional>
</ParamField> The type of the secret. Valid options are "shared" or "personal". If not
</Expandable> specified, the default value is "shared".
</ParamField>
</Expandable>
</ParamField> </ParamField>
### ###
### Update Secret ### Update Secret
`client.Secrets().Update(options)` `client.Secrets().Update(options)`
@@ -412,33 +442,42 @@ secret, err := client.Secrets().Update(infisical.UpdateSecretOptions{
### Parameters ### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="SecretKey" type="string" required> <ParamField query="SecretKey" type="string" required>
The key of the secret to update. The key of the secret to update.
</ParamField> </ParamField>
<ParamField query="NewSecretValue" type="string" required> <ParamField query="NewSecretValue" type="string" required>
The new value of the secret. The new value of the secret.
</ParamField> </ParamField>
<ParamField query="NewSkipMultilineEncoding" type="boolean" default="false" optional> <ParamField
Whether or not to skip multiline encoding for the new secret value. query="NewSkipMultilineEncoding"
</ParamField> type="boolean"
<ParamField query="ProjectID" type="string" required> default="false"
The project ID where the secret lives in. optional
</ParamField> >
<ParamField query="Environment" type="string" required> Whether or not to skip multiline encoding for the new secret value.
The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. </ParamField>
</ParamField> <ParamField query="ProjectID" type="string" required>
<ParamField query="SecretPath" type="string" optional> The project ID where the secret lives in.
The path from where secret should be updated. </ParamField>
</ParamField> <ParamField query="Environment" type="string" required>
<ParamField query="Type" type="string" optional> The slug name (dev, prod, etc) of the environment from where secrets
The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". should be fetched from.
</ParamField> </ParamField>
</Expandable> <ParamField query="SecretPath" type="string" optional>
The path from where secret should be updated.
</ParamField>
<ParamField query="Type" type="string" optional>
The type of the secret. Valid options are "shared" or "personal". If not
specified, the default value is "shared".
</ParamField>
</Expandable>
</ParamField> </ParamField>
### ###
### Delete Secret ### Delete Secret
`client.Secrets().Delete(options)` `client.Secrets().Delete(options)`
Delete a secret in Infisical. Delete a secret in Infisical.
@@ -454,30 +493,33 @@ secret, err := client.Secrets().Delete(infisical.DeleteSecretOptions{
### Parameters ### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="SecretKey" type="string"> <ParamField query="SecretKey" type="string">
The key of the secret to update. The key of the secret to update.
</ParamField> </ParamField>
<ParamField query="ProjectID" type="string" required> <ParamField query="ProjectID" type="string" required>
The project ID where the secret lives in. The project ID where the secret lives in.
</ParamField> </ParamField>
<ParamField query="Environment" type="string" required> <ParamField query="Environment" type="string" required>
The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. The slug name (dev, prod, etc) of the environment from where secrets
</ParamField> should be fetched from.
<ParamField query="SecretPath" type="string" optional> </ParamField>
The path from where secret should be deleted. <ParamField query="SecretPath" type="string" optional>
</ParamField> The path from where secret should be deleted.
<ParamField query="Type" type="string" optional> </ParamField>
The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". <ParamField query="Type" type="string" optional>
</ParamField> The type of the secret. Valid options are "shared" or "personal". If not
</Expandable> specified, the default value is "shared".
</ParamField>
</Expandable>
</ParamField> </ParamField>
## Working With folders ## Working With folders
### ###
### List Folders ### List Folders
`client.Folders().List(options)` `client.Folders().List(options)`
Retrieve all within the Infisical project and environment that client is connected to. Retrieve all within the Infisical project and environment that client is connected to.
@@ -510,7 +552,9 @@ folders, err := client.Folders().List(infisical.ListFoldersOptions{
</ParamField> </ParamField>
### ###
### Create Folder ### Create Folder
`client.Folders().Create(options)` `client.Folders().Create(options)`
Create a new folder in Infisical. Create a new folder in Infisical.
@@ -527,25 +571,27 @@ folder, err := client.Folders().Create(infisical.CreateFolderOptions{
### Parameters ### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="ProjectID" type="string" required> <ParamField query="ProjectID" type="string" required>
The ID of the project where the folder will be created. The ID of the project where the folder will be created.
</ParamField> </ParamField>
<ParamField query="Environment" type="string" required> <ParamField query="Environment" type="string" required>
The slug name (dev, prod, etc) of the environment where the folder will be created. The slug name (dev, prod, etc) of the environment where the folder will be
</ParamField> created.
<ParamField query="Path" type="string" optional> </ParamField>
The path to create the folder in. The root path is `/`. <ParamField query="Path" type="string" optional>
</ParamField> The path to create the folder in. The root path is `/`.
<ParamField query="Name" type="string" optional> </ParamField>
The name of the folder to create. <ParamField query="Name" type="string" optional>
</ParamField> The name of the folder to create.
</Expandable> </ParamField>
</Expandable>
</ParamField> </ParamField>
### ###
### Update Folder ### Update Folder
`client.Folders().Update(options)` `client.Folders().Update(options)`
Update an existing folder in Infisical. Update an existing folder in Infisical.
@@ -563,27 +609,30 @@ folder, err := client.Folders().Update(infisical.UpdateFolderOptions{
### Parameters ### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="ProjectID" type="string" required> <ParamField query="ProjectID" type="string" required>
The ID of the project where the folder will be updated. The ID of the project where the folder will be updated.
</ParamField> </ParamField>
<ParamField query="Environment" type="string" required> <ParamField query="Environment" type="string" required>
The slug name (dev, prod, etc) of the environment from where the folder lives in. The slug name (dev, prod, etc) of the environment from where the folder
</ParamField> lives in.
<ParamField query="Path" type="string" optional> </ParamField>
The path from where the folder should be updated. <ParamField query="Path" type="string" optional>
</ParamField> The path from where the folder should be updated.
<ParamField query="FolderID" type="string" required> </ParamField>
The ID of the folder to update. <ParamField query="FolderID" type="string" required>
</ParamField> The ID of the folder to update.
<ParamField query="NewName" type="string" required> </ParamField>
The new name of the folder. <ParamField query="NewName" type="string" required>
</ParamField> The new name of the folder.
</Expandable> </ParamField>
</Expandable>
</ParamField> </ParamField>
### ###
### Delete Folder ### Delete Folder
`client.Folders().Delete(options)` `client.Folders().Delete(options)`
Delete a folder in Infisical. Delete a folder in Infisical.
@@ -620,6 +669,5 @@ deletedFolder, err := client.Folders().Delete(infisical.DeleteFolderOptions{
The path from where the folder should be deleted. The path from where the folder should be deleted.
</ParamField> </ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>