Skip to content

Commit 80492ee

Browse files
Add deployment id endpoint in V2 (#712)
1 parent b78456c commit 80492ee

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

v2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

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

56
## [2.1.6](https://github.com/arangodb/go-driver/tree/v2.1.6) (2025-11-06)
67
- Add missing endpoints from replication

v2/arangodb/client_admin.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type ClientAdmin interface {
9393
// ReloadJWTSecrets forces the server to reload the JWT secrets from disk.
9494
// Requires a superuser JWT for authorization.
9595
ReloadJWTSecrets(ctx context.Context) (JWTSecretsResult, error)
96+
97+
// GetDeploymentId retrieves the unique deployment ID for the ArangoDB deployment.
98+
GetDeploymentId(ctx context.Context) (DeploymentIdResponse, error)
9699
}
97100

98101
type ClientAdminLog interface {
@@ -607,3 +610,8 @@ type JWTSecretsResult struct {
607610
type JWTSecret struct {
608611
SHA256 *string `json:"sha256,omitempty"` // SHA-256 hash of the JWT secret
609612
}
613+
614+
type DeploymentIdResponse struct {
615+
// Id represents the unique deployment identifier
616+
Id *string `json:"id"`
617+
}

v2/arangodb/client_admin_impl.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,25 @@ func (c *clientAdmin) ReloadJWTSecrets(ctx context.Context) (JWTSecretsResult, e
490490
return JWTSecretsResult{}, response.AsArangoErrorWithCode(code)
491491
}
492492
}
493+
494+
// GetDeploymentId retrieves the unique deployment ID for the ArangoDB deployment.
495+
func (c *clientAdmin) GetDeploymentId(ctx context.Context) (DeploymentIdResponse, error) {
496+
url := connection.NewUrl("_admin", "deployment", "id")
497+
498+
var response struct {
499+
shared.ResponseStruct `json:",inline"`
500+
DeploymentIdResponse `json:",inline"`
501+
}
502+
503+
resp, err := connection.CallGet(ctx, c.client.connection, url, &response)
504+
if err != nil {
505+
return DeploymentIdResponse{}, errors.WithStack(err)
506+
}
507+
508+
switch code := resp.Code(); code {
509+
case http.StatusOK:
510+
return response.DeploymentIdResponse, nil
511+
default:
512+
return DeploymentIdResponse{}, response.AsArangoErrorWithCode(code)
513+
}
514+
}

v2/tests/admin_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,40 @@ func Test_HandleAdminVersion(t *testing.T) {
590590
})
591591
})
592592
}
593+
594+
// Test_GetDeploymentId verifies that the deployment ID can be retrieved successfully.
595+
func Test_GetDeploymentId(t *testing.T) {
596+
Wrap(t, func(t *testing.T, client arangodb.Client) {
597+
t.Run("Success case", func(t *testing.T) {
598+
withContextT(t, time.Minute, func(ctx context.Context, t testing.TB) {
599+
version := skipBelowVersion(client, ctx, "3.12.6", t)
600+
t.Logf("Current Version %s", version.Version)
601+
602+
resp, err := client.GetDeploymentId(ctx)
603+
require.NoError(t, err)
604+
require.NotNil(t, resp.Id)
605+
606+
// Verify ID format (assuming it's UUID-like)
607+
require.Regexp(t, `^[a-zA-Z0-9\-]+$`, *resp.Id, "Deployment ID should be alphanumeric with hyphens")
608+
})
609+
})
610+
611+
t.Run("Multiple calls consistency", func(t *testing.T) {
612+
withContextT(t, time.Minute, func(ctx context.Context, t testing.TB) {
613+
version := skipBelowVersion(client, ctx, "3.12.6", t)
614+
t.Logf("Current Version %s", version.Version)
615+
616+
resp1, err := client.GetDeploymentId(ctx)
617+
require.NoError(t, err)
618+
require.NotNil(t, resp1.Id)
619+
620+
resp2, err := client.GetDeploymentId(ctx)
621+
require.NoError(t, err)
622+
require.NotNil(t, resp2.Id)
623+
624+
// IDs should be consistent across calls
625+
require.Equal(t, *resp1.Id, *resp2.Id, "Deployment ID should be consistent across calls")
626+
})
627+
})
628+
})
629+
}

0 commit comments

Comments
 (0)