doc: add caching reference for go sdk

This commit is contained in:
Sheen Capadngan
2025-02-19 20:11:14 +08:00
parent 1f5a73047d
commit 198b607e2e
+76 -28
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.
@@ -335,19 +359,23 @@ secret, err := client.Secrets().Retrieve(infisical.RetrieveSecretOptions{
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
should be fetched from.
</ParamField> </ParamField>
<ParamField query="SecretPath" type="string" optional> <ParamField query="SecretPath" type="string" optional>
The path from where secret should be fetched from. The path from where secret should be fetched from.
</ParamField> </ParamField>
<ParamField query="Type" type="string" optional> <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". The type of the secret. Valid options are "shared" or "personal". If not
specified, the default value is "shared".
</ParamField> </ParamField>
</Expandable> </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,7 +391,6 @@ secret, err := client.Secrets().Create(infisical.CreateSecretOptions{
}) })
``` ```
### Parameters ### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
@@ -381,18 +408,21 @@ secret, err := client.Secrets().Create(infisical.CreateSecretOptions{
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
should be fetched from.
</ParamField> </ParamField>
<ParamField query="SecretPath" type="string" optional> <ParamField query="SecretPath" type="string" optional>
The path from where secret should be created. The path from where secret should be created.
</ParamField> </ParamField>
<ParamField query="Type" type="string" optional> <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". The type of the secret. Valid options are "shared" or "personal". If not
specified, the default value is "shared".
</ParamField> </ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
### ###
### Update Secret ### Update Secret
`client.Secrets().Update(options)` `client.Secrets().Update(options)`
@@ -419,26 +449,35 @@ secret, err := client.Secrets().Update(infisical.UpdateSecretOptions{
<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
query="NewSkipMultilineEncoding"
type="boolean"
default="false"
optional
>
Whether or not to skip multiline encoding for the new secret value. Whether or not to skip multiline encoding for the new secret value.
</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
should be fetched from.
</ParamField> </ParamField>
<ParamField query="SecretPath" type="string" optional> <ParamField query="SecretPath" type="string" optional>
The path from where secret should be updated. The path from where secret should be updated.
</ParamField> </ParamField>
<ParamField query="Type" type="string" optional> <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". The type of the secret. Valid options are "shared" or "personal". If not
specified, the default value is "shared".
</ParamField> </ParamField>
</Expandable> </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.
@@ -462,22 +501,25 @@ secret, err := client.Secrets().Delete(infisical.DeleteSecretOptions{
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
should be fetched from.
</ParamField> </ParamField>
<ParamField query="SecretPath" type="string" optional> <ParamField query="SecretPath" type="string" optional>
The path from where secret should be deleted. The path from where secret should be deleted.
</ParamField> </ParamField>
<ParamField query="Type" type="string" optional> <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". The type of the secret. Valid options are "shared" or "personal". If not
specified, the default value is "shared".
</ParamField> </ParamField>
</Expandable> </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.
@@ -532,7 +576,8 @@ folder, err := client.Folders().Create(infisical.CreateFolderOptions{
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
created.
</ParamField> </ParamField>
<ParamField query="Path" type="string" optional> <ParamField query="Path" type="string" optional>
The path to create the folder in. The root path is `/`. The path to create the folder in. The root path is `/`.
@@ -543,9 +588,10 @@ folder, err := client.Folders().Create(infisical.CreateFolderOptions{
</Expandable> </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.
@@ -568,7 +614,8 @@ folder, err := client.Folders().Update(infisical.UpdateFolderOptions{
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
lives in.
</ParamField> </ParamField>
<ParamField query="Path" type="string" optional> <ParamField query="Path" type="string" optional>
The path from where the folder should be updated. The path from where the folder should be updated.
@@ -583,7 +630,9 @@ folder, err := client.Folders().Update(infisical.UpdateFolderOptions{
</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>