# Keys

## Create Object Storage Key

`client.Storage.Keys.New(ctx, body) (*ObjectStorageKeyWithSecret, error)`

**post** `/v1/storage/keys`

Create an S3 access key for a project's Buckets in a region. The response is the only one that includes the secret access key.

### Parameters

- `body KeyNewParams`

  - `Name param.Field[string]`

    Name of the Object Storage Key.

  - `ProjectID param.Field[string]`

    Project ID the Object Storage Key belongs to. The key can access the
    project's Buckets in its region.

  - `Region param.Field[RegionName]`

    Region the resource is in.

### Returns

- `type ObjectStorageKeyWithSecret struct{…}`

  Object Storage Key details, including the secret access key. Returned only when the key is created.

  - `ID string`

    Unique identifier for the Object Storage Key.

  - `AccessKey string`

    S3 access key ID.

  - `CreatedAt Time`

    When the Object Storage Key was created.

  - `Name string`

    Name of the Object Storage Key.

  - `ProjectID string`

    Project ID the Object Storage Key belongs to.

  - `Region RegionName`

    Region the resource is in.

    - `const RegionNameUsSva2 RegionName = "us-sva-2"`

    - `const RegionNameUsWdc1 RegionName = "us-wdc-1"`

  - `Secret string`

    S3 secret access key. It is only returned here and cannot be retrieved
    again: store it securely, or delete the key and create a new one if it is
    lost.

  - `Status ResourceStatus`

    Status of the resource.

    - `const ResourceStatusPending ResourceStatus = "pending"`

    - `const ResourceStatusCreating ResourceStatus = "creating"`

    - `const ResourceStatusUpdating ResourceStatus = "updating"`

    - `const ResourceStatusReady ResourceStatus = "ready"`

    - `const ResourceStatusDeleting ResourceStatus = "deleting"`

    - `const ResourceStatusDeleted ResourceStatus = "deleted"`

    - `const ResourceStatusError ResourceStatus = "error"`

    - `const ResourceStatusSuspended ResourceStatus = "suspended"`

  - `UpdatedAt Time`

    When the Object Storage Key was updated.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/nirvana-labs/nirvana-go"
  "github.com/nirvana-labs/nirvana-go/option"
  "github.com/nirvana-labs/nirvana-go/shared"
  "github.com/nirvana-labs/nirvana-go/storage"
)

func main() {
  client := nirvana.NewClient(
    option.WithAPIKey("My API Key"),
  )
  objectStorageKeyWithSecret, err := client.Storage.Keys.New(context.TODO(), storage.KeyNewParams{
    Name: "ci-uploads",
    ProjectID: "123e4567-e89b-12d3-a456-426614174000",
    Region: shared.RegionNameUsSva2,
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", objectStorageKeyWithSecret.ID)
}
```

#### Response

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "access_key": "0555B35654AD1656D804",
  "created_at": "2025-01-01T00:00:00Z",
  "name": "ci-uploads",
  "project_id": "123e4567-e89b-12d3-a456-426614174000",
  "region": "us-sva-2",
  "secret": "h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==",
  "status": "ready",
  "updated_at": "2025-01-01T00:00:00Z"
}
```

## Get Object Storage Key Details

`client.Storage.Keys.Get(ctx, keyID) (*ObjectStorageKey, error)`

**get** `/v1/storage/keys/{key_id}`

Get details about an Object Storage Key. The secret access key is not included.

### Parameters

- `keyID string`

### Returns

- `type ObjectStorageKey struct{…}`

  Object Storage Key details. The secret access key is only returned when the key is created.

  - `ID string`

    Unique identifier for the Object Storage Key.

  - `AccessKey string`

    S3 access key ID.

  - `CreatedAt Time`

    When the Object Storage Key was created.

  - `Name string`

    Name of the Object Storage Key.

  - `ProjectID string`

    Project ID the Object Storage Key belongs to.

  - `Region RegionName`

    Region the resource is in.

    - `const RegionNameUsSva2 RegionName = "us-sva-2"`

    - `const RegionNameUsWdc1 RegionName = "us-wdc-1"`

  - `Status ResourceStatus`

    Status of the resource.

    - `const ResourceStatusPending ResourceStatus = "pending"`

    - `const ResourceStatusCreating ResourceStatus = "creating"`

    - `const ResourceStatusUpdating ResourceStatus = "updating"`

    - `const ResourceStatusReady ResourceStatus = "ready"`

    - `const ResourceStatusDeleting ResourceStatus = "deleting"`

    - `const ResourceStatusDeleted ResourceStatus = "deleted"`

    - `const ResourceStatusError ResourceStatus = "error"`

    - `const ResourceStatusSuspended ResourceStatus = "suspended"`

  - `UpdatedAt Time`

    When the Object Storage Key was updated.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/nirvana-labs/nirvana-go"
  "github.com/nirvana-labs/nirvana-go/option"
)

func main() {
  client := nirvana.NewClient(
    option.WithAPIKey("My API Key"),
  )
  objectStorageKey, err := client.Storage.Keys.Get(context.TODO(), "key_id")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", objectStorageKey.ID)
}
```

#### Response

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "access_key": "0555B35654AD1656D804",
  "created_at": "2025-01-01T00:00:00Z",
  "name": "ci-uploads",
  "project_id": "123e4567-e89b-12d3-a456-426614174000",
  "region": "us-sva-2",
  "status": "ready",
  "updated_at": "2025-01-01T00:00:00Z"
}
```

## Update Object Storage Key

`client.Storage.Keys.Update(ctx, keyID, body) (*ObjectStorageKey, error)`

**patch** `/v1/storage/keys/{key_id}`

Rename an Object Storage Key. Its access key and secret do not change.

### Parameters

- `keyID string`

- `body KeyUpdateParams`

  - `Name param.Field[string]`

    Name of the Object Storage Key.

### Returns

- `type ObjectStorageKey struct{…}`

  Object Storage Key details. The secret access key is only returned when the key is created.

  - `ID string`

    Unique identifier for the Object Storage Key.

  - `AccessKey string`

    S3 access key ID.

  - `CreatedAt Time`

    When the Object Storage Key was created.

  - `Name string`

    Name of the Object Storage Key.

  - `ProjectID string`

    Project ID the Object Storage Key belongs to.

  - `Region RegionName`

    Region the resource is in.

    - `const RegionNameUsSva2 RegionName = "us-sva-2"`

    - `const RegionNameUsWdc1 RegionName = "us-wdc-1"`

  - `Status ResourceStatus`

    Status of the resource.

    - `const ResourceStatusPending ResourceStatus = "pending"`

    - `const ResourceStatusCreating ResourceStatus = "creating"`

    - `const ResourceStatusUpdating ResourceStatus = "updating"`

    - `const ResourceStatusReady ResourceStatus = "ready"`

    - `const ResourceStatusDeleting ResourceStatus = "deleting"`

    - `const ResourceStatusDeleted ResourceStatus = "deleted"`

    - `const ResourceStatusError ResourceStatus = "error"`

    - `const ResourceStatusSuspended ResourceStatus = "suspended"`

  - `UpdatedAt Time`

    When the Object Storage Key was updated.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/nirvana-labs/nirvana-go"
  "github.com/nirvana-labs/nirvana-go/option"
  "github.com/nirvana-labs/nirvana-go/storage"
)

func main() {
  client := nirvana.NewClient(
    option.WithAPIKey("My API Key"),
  )
  objectStorageKey, err := client.Storage.Keys.Update(
    context.TODO(),
    "key_id",
    storage.KeyUpdateParams{

    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", objectStorageKey.ID)
}
```

#### Response

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "access_key": "0555B35654AD1656D804",
  "created_at": "2025-01-01T00:00:00Z",
  "name": "ci-uploads",
  "project_id": "123e4567-e89b-12d3-a456-426614174000",
  "region": "us-sva-2",
  "status": "ready",
  "updated_at": "2025-01-01T00:00:00Z"
}
```

## Delete Object Storage Key

`client.Storage.Keys.Delete(ctx, keyID) error`

**delete** `/v1/storage/keys/{key_id}`

Delete an Object Storage Key. It stops working immediately.

### Parameters

- `keyID string`

### Example

```go
package main

import (
  "context"

  "github.com/nirvana-labs/nirvana-go"
  "github.com/nirvana-labs/nirvana-go/option"
)

func main() {
  client := nirvana.NewClient(
    option.WithAPIKey("My API Key"),
  )
  err := client.Storage.Keys.Delete(context.TODO(), "key_id")
  if err != nil {
    panic(err.Error())
  }
}
```

## List Object Storage Keys

`client.Storage.Keys.List(ctx, query) (*Cursor[ObjectStorageKey], error)`

**get** `/v1/storage/keys`

List all Object Storage Keys. Secret access keys are not included.

### Parameters

- `query KeyListParams`

  - `ProjectID param.Field[string]`

    Project ID of resources to request

  - `Cursor param.Field[string]`

    Pagination cursor returned by a previous request. Only valid for the same filters and sort order.

  - `Limit param.Field[int64]`

    Maximum number of items to return

  - `Name param.Field[string]`

    Filter by a case-insensitive substring of the Object Storage Key name

  - `Region param.Field[string]`

    Filter by region

  - `Sort param.Field[string]`

    Comma-separated sort terms in precedence order, each field:asc or field:desc. Fields: created_at, updated_at, name

### Returns

- `type ObjectStorageKey struct{…}`

  Object Storage Key details. The secret access key is only returned when the key is created.

  - `ID string`

    Unique identifier for the Object Storage Key.

  - `AccessKey string`

    S3 access key ID.

  - `CreatedAt Time`

    When the Object Storage Key was created.

  - `Name string`

    Name of the Object Storage Key.

  - `ProjectID string`

    Project ID the Object Storage Key belongs to.

  - `Region RegionName`

    Region the resource is in.

    - `const RegionNameUsSva2 RegionName = "us-sva-2"`

    - `const RegionNameUsWdc1 RegionName = "us-wdc-1"`

  - `Status ResourceStatus`

    Status of the resource.

    - `const ResourceStatusPending ResourceStatus = "pending"`

    - `const ResourceStatusCreating ResourceStatus = "creating"`

    - `const ResourceStatusUpdating ResourceStatus = "updating"`

    - `const ResourceStatusReady ResourceStatus = "ready"`

    - `const ResourceStatusDeleting ResourceStatus = "deleting"`

    - `const ResourceStatusDeleted ResourceStatus = "deleted"`

    - `const ResourceStatusError ResourceStatus = "error"`

    - `const ResourceStatusSuspended ResourceStatus = "suspended"`

  - `UpdatedAt Time`

    When the Object Storage Key was updated.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/nirvana-labs/nirvana-go"
  "github.com/nirvana-labs/nirvana-go/option"
  "github.com/nirvana-labs/nirvana-go/storage"
)

func main() {
  client := nirvana.NewClient(
    option.WithAPIKey("My API Key"),
  )
  page, err := client.Storage.Keys.List(context.TODO(), storage.KeyListParams{
    ProjectID: "project_id",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
```

#### Response

```json
{
  "items": [
    {
      "id": "123e4567-e89b-12d3-a456-426614174000",
      "access_key": "0555B35654AD1656D804",
      "created_at": "2025-01-01T00:00:00Z",
      "name": "ci-uploads",
      "project_id": "123e4567-e89b-12d3-a456-426614174000",
      "region": "us-sva-2",
      "status": "ready",
      "updated_at": "2025-01-01T00:00:00Z"
    }
  ],
  "pagination": {
    "next_cursor": "RhwniMT4B74siYZcPF8TnCdGI1l9rpPvg",
    "previous_cursor": "ARhwnmi1hA7wEbHbMjdYQlOB_ZusP4fYvw",
    "total_count": 125
  }
}
```

## Domain Types

### Object Storage Key

- `type ObjectStorageKey struct{…}`

  Object Storage Key details. The secret access key is only returned when the key is created.

  - `ID string`

    Unique identifier for the Object Storage Key.

  - `AccessKey string`

    S3 access key ID.

  - `CreatedAt Time`

    When the Object Storage Key was created.

  - `Name string`

    Name of the Object Storage Key.

  - `ProjectID string`

    Project ID the Object Storage Key belongs to.

  - `Region RegionName`

    Region the resource is in.

    - `const RegionNameUsSva2 RegionName = "us-sva-2"`

    - `const RegionNameUsWdc1 RegionName = "us-wdc-1"`

  - `Status ResourceStatus`

    Status of the resource.

    - `const ResourceStatusPending ResourceStatus = "pending"`

    - `const ResourceStatusCreating ResourceStatus = "creating"`

    - `const ResourceStatusUpdating ResourceStatus = "updating"`

    - `const ResourceStatusReady ResourceStatus = "ready"`

    - `const ResourceStatusDeleting ResourceStatus = "deleting"`

    - `const ResourceStatusDeleted ResourceStatus = "deleted"`

    - `const ResourceStatusError ResourceStatus = "error"`

    - `const ResourceStatusSuspended ResourceStatus = "suspended"`

  - `UpdatedAt Time`

    When the Object Storage Key was updated.

### Object Storage Key List

- `type ObjectStorageKeyList struct{…}`

  - `Items []ObjectStorageKey`

    - `ID string`

      Unique identifier for the Object Storage Key.

    - `AccessKey string`

      S3 access key ID.

    - `CreatedAt Time`

      When the Object Storage Key was created.

    - `Name string`

      Name of the Object Storage Key.

    - `ProjectID string`

      Project ID the Object Storage Key belongs to.

    - `Region RegionName`

      Region the resource is in.

      - `const RegionNameUsSva2 RegionName = "us-sva-2"`

      - `const RegionNameUsWdc1 RegionName = "us-wdc-1"`

    - `Status ResourceStatus`

      Status of the resource.

      - `const ResourceStatusPending ResourceStatus = "pending"`

      - `const ResourceStatusCreating ResourceStatus = "creating"`

      - `const ResourceStatusUpdating ResourceStatus = "updating"`

      - `const ResourceStatusReady ResourceStatus = "ready"`

      - `const ResourceStatusDeleting ResourceStatus = "deleting"`

      - `const ResourceStatusDeleted ResourceStatus = "deleted"`

      - `const ResourceStatusError ResourceStatus = "error"`

      - `const ResourceStatusSuspended ResourceStatus = "suspended"`

    - `UpdatedAt Time`

      When the Object Storage Key was updated.

  - `Pagination Pagination`

    Pagination response details.

    - `NextCursor string`

    - `PreviousCursor string`

    - `TotalCount int64`

### Object Storage Key With Secret

- `type ObjectStorageKeyWithSecret struct{…}`

  Object Storage Key details, including the secret access key. Returned only when the key is created.

  - `ID string`

    Unique identifier for the Object Storage Key.

  - `AccessKey string`

    S3 access key ID.

  - `CreatedAt Time`

    When the Object Storage Key was created.

  - `Name string`

    Name of the Object Storage Key.

  - `ProjectID string`

    Project ID the Object Storage Key belongs to.

  - `Region RegionName`

    Region the resource is in.

    - `const RegionNameUsSva2 RegionName = "us-sva-2"`

    - `const RegionNameUsWdc1 RegionName = "us-wdc-1"`

  - `Secret string`

    S3 secret access key. It is only returned here and cannot be retrieved
    again: store it securely, or delete the key and create a new one if it is
    lost.

  - `Status ResourceStatus`

    Status of the resource.

    - `const ResourceStatusPending ResourceStatus = "pending"`

    - `const ResourceStatusCreating ResourceStatus = "creating"`

    - `const ResourceStatusUpdating ResourceStatus = "updating"`

    - `const ResourceStatusReady ResourceStatus = "ready"`

    - `const ResourceStatusDeleting ResourceStatus = "deleting"`

    - `const ResourceStatusDeleted ResourceStatus = "deleted"`

    - `const ResourceStatusError ResourceStatus = "error"`

    - `const ResourceStatusSuspended ResourceStatus = "suspended"`

  - `UpdatedAt Time`

    When the Object Storage Key was updated.
