Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions v2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
- Add endpoint to fetch deployment id

## [2.1.6](https://github.com/arangodb/go-driver/tree/v2.1.6) (2025-11-06)
- Add missing endpoints from replication
Expand Down
8 changes: 8 additions & 0 deletions v2/arangodb/client_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type ClientAdmin interface {
// ReloadJWTSecrets forces the server to reload the JWT secrets from disk.
// Requires a superuser JWT for authorization.
ReloadJWTSecrets(ctx context.Context) (JWTSecretsResult, error)

// GetDeploymentId retrieves the unique deployment ID for the ArangoDB deployment.
GetDeploymentId(ctx context.Context) (DeploymentIdResponse, error)
}

type ClientAdminLog interface {
Expand Down Expand Up @@ -607,3 +610,8 @@ type JWTSecretsResult struct {
type JWTSecret struct {
SHA256 *string `json:"sha256,omitempty"` // SHA-256 hash of the JWT secret
}

type DeploymentIdResponse struct {
// Id represents the unique deployment identifier
Id *string `json:"id"`
}
22 changes: 22 additions & 0 deletions v2/arangodb/client_admin_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,25 @@ func (c *clientAdmin) ReloadJWTSecrets(ctx context.Context) (JWTSecretsResult, e
return JWTSecretsResult{}, response.AsArangoErrorWithCode(code)
}
}

// GetDeploymentId retrieves the unique deployment ID for the ArangoDB deployment.
func (c *clientAdmin) GetDeploymentId(ctx context.Context) (DeploymentIdResponse, error) {
url := connection.NewUrl("_admin", "deployment", "id")

var response struct {
shared.ResponseStruct `json:",inline"`
DeploymentIdResponse `json:",inline"`
}

resp, err := connection.CallGet(ctx, c.client.connection, url, &response)
if err != nil {
return DeploymentIdResponse{}, errors.WithStack(err)
}

switch code := resp.Code(); code {
case http.StatusOK:
return response.DeploymentIdResponse, nil
default:
return DeploymentIdResponse{}, response.AsArangoErrorWithCode(code)
}
}
37 changes: 37 additions & 0 deletions v2/tests/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,40 @@ func Test_HandleAdminVersion(t *testing.T) {
})
})
}

// Test_GetDeploymentId verifies that the deployment ID can be retrieved successfully.
func Test_GetDeploymentId(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
t.Run("Success case", func(t *testing.T) {
withContextT(t, time.Minute, func(ctx context.Context, t testing.TB) {
version := skipBelowVersion(client, ctx, "3.12.6", t)
t.Logf("Current Version %s", version.Version)

resp, err := client.GetDeploymentId(ctx)
require.NoError(t, err)
require.NotNil(t, resp.Id)

// Verify ID format (assuming it's UUID-like)
require.Regexp(t, `^[a-zA-Z0-9\-]+$`, *resp.Id, "Deployment ID should be alphanumeric with hyphens")
})
})

t.Run("Multiple calls consistency", func(t *testing.T) {
withContextT(t, time.Minute, func(ctx context.Context, t testing.TB) {
version := skipBelowVersion(client, ctx, "3.12.6", t)
t.Logf("Current Version %s", version.Version)

resp1, err := client.GetDeploymentId(ctx)
require.NoError(t, err)
require.NotNil(t, resp1.Id)

resp2, err := client.GetDeploymentId(ctx)
require.NoError(t, err)
require.NotNil(t, resp2.Id)

// IDs should be consistent across calls
require.Equal(t, *resp1.Id, *resp2.Id, "Deployment ID should be consistent across calls")
})
})
})
}