Commit 5868185
authored
Implement admin APIs (#117)
## Problem
We need the admin APIs from `2025-04` implemented in Go to support both
the CLI and Terraform.
## Solution
Implement new `AdminClient` which encapsulates all of the network
operations for working with the admin API. This is a separate client
from the generic `Client`, and has it's own `NewAdminClientParams`
configuration struct. Additionally, there are two new functions for
authenticating and generating a new `AdminClient` pointer:
`NewAdminClient` and `NewAdminClientWithContext`.
The operations are broken across three interfaces:
- `ProjectClient`
- `OrganizationClient`
- `APIKeyClient`
Each of these has the relevant crud operations for the resources, so you
call them like `adminClient.Project.List()`, or
`adminClient.APIKey.List()`.
New files:
- `admin_client.go`
- `admin_client_test.go`
Added a new `AdminIntegrationTests` suite to wrap all of the integration
tests associated with the admin API. There's full end-to-end tests for
all crud operations except `DeleteOrganization` in the
`ademin_client_test.go` file.
Example usage:
```go
package main
import (
"context"
"fmt"
"log"
"github.com/pinecone-io/go-pinecone/v4/pinecone"
)
func main() {
ctx := context.Background()
// Create an AdminClient using your credentials
adminClient, err := pinecone.NewAdminClient(pinecone.NewAdminClientParams{
ClientId: "YOUR_CLIENT_ID",
ClientSecret: "YOUR_CLIENT_SECRET",
})
if err != nil {
log.Fatalf("failed to create AdminClient: %v", err)
}
// Create a new project
project, err := adminClient.Project.Create(ctx, &pinecone.CreateProjectParams{
Name: "example-project",
})
if err != nil {
log.Fatalf("failed to create project: %v", err)
}
fmt.Printf("Created project: %s\n", project.Name)
// Create a new API within that project
apiKey, err := adminClient.APIKey.Create(ctx, project.Id, &pinecone.CreateAPIKeyParams{
Name: "example-api-key",
})
if err != nil {
log.Fatalf("failed to create API key: %v", err)
}
fmt.Printf("Created API key: %s\n", apiKey.Id)
// List all projects
projects, err := adminClient.Project.List(ctx)
if err != nil {
log.Fatalf("failed to list projects: %v", err)
}
fmt.Printf("You have %d project(s)\n", len(projects))
// List API keys for the created project
apiKeys, err := adminClient.APIKey.List(ctx, project.Id)
if err != nil {
log.Fatalf("failed to list API keys: %v", err)
}
fmt.Printf("Project '%s' has %d API key(s)\n", project.Name, len(apiKeys))
}
```
## Type of Change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Infrastructure change (CI configs, etc)
- [ ] Non-code change (docs, etc)
- [ ] None of the above: (explain here)
## Test Plan
New integration tests for `AdminClient` and all operations added for CI.
You can pull this branch down locally and test against the built client
locally.1 parent 60a0fbb commit 5868185
File tree
12 files changed
+3828
-16
lines changed- .github/workflows
- codegen
- internal/gen
- admin
- db_data
- grpc
- rest
- pinecone
12 files changed
+3828
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
51 | | - | |
| 51 | + | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
116 | 186 | | |
117 | 187 | | |
118 | 188 | | |
| |||
Submodule apis updated from 97efd6c to 03d8829
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
112 | 120 | | |
113 | 121 | | |
114 | 122 | | |
| |||
0 commit comments