From 4af2cb2acc7f77626b0f1d1045e9bba12aaea8d7 Mon Sep 17 00:00:00 2001 From: bluepal-prasanthi-moparthi Date: Wed, 29 Oct 2025 11:43:57 +0530 Subject: [PATCH 1/4] Add endpoint to fetch deployment id --- v2/CHANGELOG.md | 1 + v2/arangodb/client_admin.go | 8 ++++++++ v2/arangodb/client_admin_impl.go | 22 +++++++++++++++++++++ v2/tests/admin_test.go | 34 ++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) 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..49004100 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..4b4716b5 100644 --- a/v2/tests/admin_test.go +++ b/v2/tests/admin_test.go @@ -590,3 +590,37 @@ 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.NotEmpty(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) { + resp1, err := client.GetDeploymentId(ctx) + require.NoError(t, err) + require.NotEmpty(t, resp1.Id) + + resp2, err := client.GetDeploymentId(ctx) + require.NoError(t, err) + require.NotEmpty(t, resp2.Id) + + // IDs should be consistent across calls + require.Equal(t, resp1.Id, resp2.Id, "Deployment ID should be consistent across calls") + }) + }) + }) +} From bee83410464d4eb78ef35b01dd3fee553a8a5b55 Mon Sep 17 00:00:00 2001 From: bluepal-prasanthi-moparthi Date: Wed, 29 Oct 2025 11:46:15 +0530 Subject: [PATCH 2/4] Added pointer to the response struct --- v2/arangodb/client_admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/arangodb/client_admin.go b/v2/arangodb/client_admin.go index 49004100..3cd5673b 100644 --- a/v2/arangodb/client_admin.go +++ b/v2/arangodb/client_admin.go @@ -613,5 +613,5 @@ type JWTSecret struct { type DeploymentIdResponse struct { // Id represents the unique deployment identifier - Id string `json:"id"` + Id *string `json:"id"` } From e0880c7e3b34e3d4a7760bb66ced7eba3d29e21c Mon Sep 17 00:00:00 2001 From: bluepal-prasanthi-moparthi Date: Wed, 29 Oct 2025 11:53:50 +0530 Subject: [PATCH 3/4] modified test case --- v2/tests/admin_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/v2/tests/admin_test.go b/v2/tests/admin_test.go index 4b4716b5..35eea78f 100644 --- a/v2/tests/admin_test.go +++ b/v2/tests/admin_test.go @@ -601,10 +601,10 @@ func Test_GetDeploymentId(t *testing.T) { resp, err := client.GetDeploymentId(ctx) require.NoError(t, err) - require.NotEmpty(t, resp.Id) + 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") + require.Regexp(t, `^[a-zA-Z0-9\-]+$`, *resp.Id, "Deployment ID should be alphanumeric with hyphens") }) }) @@ -612,14 +612,14 @@ func Test_GetDeploymentId(t *testing.T) { withContextT(t, time.Minute, func(ctx context.Context, t testing.TB) { resp1, err := client.GetDeploymentId(ctx) require.NoError(t, err) - require.NotEmpty(t, resp1.Id) + require.NotNil(t, resp1.Id) resp2, err := client.GetDeploymentId(ctx) require.NoError(t, err) - require.NotEmpty(t, resp2.Id) + 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") + require.Equal(t, *resp1.Id, *resp2.Id, "Deployment ID should be consistent across calls") }) }) }) From eca4fe34a99e41d94454d53983897b43fafa176c Mon Sep 17 00:00:00 2001 From: bluepal-prasanthi-moparthi Date: Wed, 29 Oct 2025 11:57:59 +0530 Subject: [PATCH 4/4] added version check in the test case --- v2/tests/admin_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/v2/tests/admin_test.go b/v2/tests/admin_test.go index 35eea78f..71908b52 100644 --- a/v2/tests/admin_test.go +++ b/v2/tests/admin_test.go @@ -610,6 +610,9 @@ func Test_GetDeploymentId(t *testing.T) { 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)