diff --git a/v2/CHANGELOG.md b/v2/CHANGELOG.md index 755fcdac..f2279a5b 100644 --- a/v2/CHANGELOG.md +++ b/v2/CHANGELOG.md @@ -9,6 +9,7 @@ - Add missing endpoints from authentication to v2 - Add missing endpoints from general-request-handling to v2 - Add benchmark tests for v1 and v2 to compare performance +- Add endpoint to fetch deployment id ## [2.1.5](https://github.com/arangodb/go-driver/tree/v2.1.5) (2025-08-31) - Add tasks endpoints to v2 diff --git a/v2/arangodb/client_admin.go b/v2/arangodb/client_admin.go index 72b8904b..3cd5673b 100644 --- a/v2/arangodb/client_admin.go +++ b/v2/arangodb/client_admin.go @@ -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 { @@ -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"` +} diff --git a/v2/arangodb/client_admin_impl.go b/v2/arangodb/client_admin_impl.go index 1159f247..6c9a31a2 100644 --- a/v2/arangodb/client_admin_impl.go +++ b/v2/arangodb/client_admin_impl.go @@ -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) + } +} diff --git a/v2/tests/admin_test.go b/v2/tests/admin_test.go index 58c9a220..71908b52 100644 --- a/v2/tests/admin_test.go +++ b/v2/tests/admin_test.go @@ -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") + }) + }) + }) +}