Update a tenant with the Go SDK
Permit.Api.Tenants.Update() changes the name, description, or attributes of an existing tenant in the environment that your API key belongs to. This reference is for Go developers who manage tenants from backend code.
Tenants.Update signature
func (t *Tenants) Update(ctx context.Context, tenantKey string, tenantUpdate models.TenantUpdate) (*models.TenantRead, error)
Tenants.Update parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | The context of the request. |
tenantKey | string | Yes | The key of the tenant to update. The tenant ID also works. |
tenantUpdate | models.TenantUpdate | Yes | The fields to change. Build it with models.NewTenantUpdate(). |
TenantUpdate fields
Tenants.Update is a partial update. The Permit API changes only the fields you set, and each field you set replaces the stored value completely. For example, setting Attributes replaces all the tenant's attributes, not only the keys you pass.
| Field | Type | Required | Description |
|---|---|---|---|
Name | *string | No | A descriptive name for the tenant. Set it with SetName(). |
Description | *string | No | A longer description of the tenant. Set it with SetDescription(). |
Attributes | map[string]interface{} | No | Tenant attributes that attribute-based access control (ABAC) policies evaluate. Set them with SetAttributes(). |
Example: rename a tenant with Tenants.Update
The example uses a client named Permit, created with permit.NewPermit() as shown in Check permissions with the Go SDK, and a ctx of type context.Context.
Build the TenantUpdate struct with the new name:
tenantUpdate := models.NewTenantUpdate()
tenantUpdate.SetName("New Tenant Name")
Pass the key of the tenant and the struct to Tenants.Update:
tenant, err := Permit.Api.Tenants.Update(ctx, "tenant-key", *tenantUpdate)
Tenants.Update return value and errors
On success, Tenants.Update returns a *models.TenantRead with the updated tenant.
If the call fails, err holds an errors.PermitError from the github.com/permitio/permit-golang/pkg/errors package. Its StatusCode field has the HTTP status, and its ErrorCode field has one of these codes:
ErrorCode | Cause |
|---|---|
NotFound | HTTP 404: no tenant with that key or ID exists in the environment. |
UnprocessableEntityError | HTTP 422: a field failed validation. |
Unauthorized, ForbiddenAccess | HTTP 401 or 403: the API key is invalid or has no access to the environment. |
UnexpectedError | A server error (HTTP 5xx) or a network error. |