Skip to content

Commit 5868185

Browse files
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

12 files changed

+3828
-16
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ jobs:
2929
- name: Setup Go
3030
uses: actions/setup-go@v5
3131
with:
32-
go-version: "1.21.x"
32+
go-version: '1.21.x'
3333
- name: Install dependencies
3434
run: |
3535
go get ./pinecone
3636
- name: Run tests
3737
run: go test -count=1 -v ./pinecone
3838
env:
3939
PINECONE_API_KEY: ${{ secrets.API_KEY }}
40+
PINECONE_CLIENT_ID: ${{ secrets.CLIENT_ID }}
41+
PINECONE_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
4042
- name: Run local integration tests
4143
run: go test -count=1 -v ./pinecone -run TestRunLocalIntegrationSuite -tags=localServer
4244
env:

README.md

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ visit https://pkg.go.dev/github.com/pinecone-io/go-pinecone/v4/pinecone.
1313

1414
go-pinecone contains
1515

16-
- gRPC bindings for [Data Plane](https://docs.pinecone.io/reference/api/2024-07/data-plane) operations
17-
- REST bindings for [Control Plane](https://docs.pinecone.io/reference/api/2024-07/control-plane)
16+
- gRPC bindings for [Data Plane](https://docs.pinecone.io/reference/api/2025-04/data-plane) operations
17+
- REST bindings for [Control Plane](https://docs.pinecone.io/reference/api/2025-04/control-plane)
1818
operations
19+
- REST bindings for [Admin API](https://docs.pinecone.io/reference/api/2025-04/admin/)
1920

2021
See the [Pinecone API Docs](https://docs.pinecone.io/reference/) for more information.
2122

@@ -43,12 +44,12 @@ For more information on setting up a Go project, see the [Go documentation](http
4344

4445
## Usage
4546

46-
### Initializing the client
47+
### Initializing a Client
4748

4849
**Authenticating via an API key**
4950

50-
When initializing the client with a Pinecone API key, you must construct a `NewClientParams` object and pass it to the
51-
`NewClient` function.
51+
When initializing a `Client` with a Pinecone API key, you must construct a `NewClientParams` object and pass it to the
52+
`NewClient` function which returns `Client`.
5253

5354
It's recommended that you set your Pinecone API key as an environment variable (`"PINECONE_API_KEY"`) and access it that
5455
way. Alternatively, you can pass it in your code directly.
@@ -113,6 +114,75 @@ func main() {
113114
}
114115
```
115116

117+
### Initializing an AdminClient (Admin API)
118+
119+
When initializing an `AdminClient` you must construct a `NewAdminClientParams` object and pass it to the
120+
`NewAdminClient` or `NewAdminClientWithContext` functions which return `AdminClient`.
121+
122+
`AdminClient` is a struct used for accessing the Pinecone Admin API. A prerequisite for using this class is to have a [service account](https://docs.pinecone.io/guides/organizations/manage-service-accounts). To create a service
123+
account, visit the [Pinecone web console](https://app.pinecone.io) and navigate to the `Access > Service Accounts` section.
124+
125+
**Authenticating via client ID and secret**
126+
127+
After creating a service account, you will be provided with a client ID and secret. These values can be passed via the `NewAdminClientParams` struct, or by setting the `PINECONE_CLIENT_ID` and `PINECONE_CLIENT_SECRET` environment variables. The `NewAdminClient` function handles the authentication handshake, and returns an authenticated `AdminClient`.
128+
129+
```go
130+
package main
131+
132+
import (
133+
"context"
134+
"fmt"
135+
"log"
136+
137+
"github.com/pinecone-io/go-pinecone/v4/pinecone"
138+
)
139+
140+
func main() {
141+
ctx := context.Background()
142+
143+
// Create an AdminClient using your credentials
144+
adminClient, err := pinecone.NewAdminClient(pinecone.NewAdminClientParams{
145+
ClientId: "YOUR_CLIENT_ID",
146+
ClientSecret: "YOUR_CLIENT_SECRET",
147+
})
148+
if err != nil {
149+
log.Fatalf("failed to create AdminClient: %v", err)
150+
}
151+
152+
// Create a new project
153+
project, err := adminClient.Project.Create(ctx, &pinecone.CreateProjectParams{
154+
Name: "example-project",
155+
})
156+
if err != nil {
157+
log.Fatalf("failed to create project: %v", err)
158+
}
159+
fmt.Printf("Created project: %s\n", project.Name)
160+
161+
// Create a new API within that project
162+
apiKey, err := adminClient.APIKey.Create(ctx, project.Id, &pinecone.CreateAPIKeyParams{
163+
Name: "example-api-key",
164+
})
165+
if err != nil {
166+
log.Fatalf("failed to create API key: %v", err)
167+
}
168+
fmt.Printf("Created API key: %s\n", apiKey.Id)
169+
170+
// List all projects
171+
projects, err := adminClient.Project.List(ctx)
172+
if err != nil {
173+
log.Fatalf("failed to list projects: %v", err)
174+
}
175+
fmt.Printf("You have %d project(s)\n", len(projects))
176+
177+
// List API keys for the created project
178+
apiKeys, err := adminClient.APIKey.List(ctx, project.Id)
179+
if err != nil {
180+
log.Fatalf("failed to list API keys: %v", err)
181+
}
182+
fmt.Printf("Project '%s' has %d API key(s)\n", project.Name, len(apiKeys))
183+
}
184+
```
185+
116186
## Indexes
117187

118188
### Create indexes

codegen/apis

Submodule apis updated from 97efd6c to 03d8829

codegen/build-clients.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ version=$1 # e.g. 2024-07
66
db_control_module="db_control"
77
db_data_module="db_data"
88
inference_module="inference"
9+
admin_module="admin"
910

1011
# generated grpc output destination paths
1112
# db_data_destination must align with the option go_package in the proto file:
1213
# https://github.com/pinecone-io/apis/blob/d1d005e75cc9fe9a5c486ef9218fe87b57765961/src/release/db/data/data.proto#L3
1314
db_data_destination="internal/gen/${db_data_module}"
1415
db_control_destination="internal/gen/${db_control_module}"
1516
inference_destination="internal/gen/${inference_module}"
17+
admin_destination="internal/gen/${admin_module}"
1618

1719
# version file
1820
version_file="internal/gen/api_version.go"
@@ -22,6 +24,7 @@ db_data_rest_destination="${db_data_destination}/rest"
2224
db_data_oas_file="${db_data_rest_destination}/${db_data_module}_${version}.oas.go"
2325
db_control_oas_file="${db_control_destination}/${db_control_module}_${version}.oas.go"
2426
inference_oas_file="${inference_destination}/${inference_module}_${version}.oas.go"
27+
admin_oas_file="${admin_destination}/${admin_module}_${version}.oas.go"
2528

2629
set -eux -o pipefail
2730

@@ -109,6 +112,11 @@ rm -rf "${inference_destination}"
109112
mkdir -p "${inference_destination}"
110113
generate_oas_client $inference_module $inference_oas_file
111114

115+
# Generate admin oas client
116+
rm -rf "${admin_destination}"
117+
mkdir -p "${admin_destination}"
118+
generate_oas_client $admin_module $admin_oas_file
119+
112120
# Generate db_data oas and proto clients
113121
rm -rf "${db_data_destination}"
114122
mkdir -p "${db_data_destination}"

0 commit comments

Comments
 (0)