Add 7 missing SDK methods and fix README type name
- Fix AgentKeyRequest → RegisterAgentKeyInput in README - Add ListAgents, UnfreezeAgent, DeleteAgent to agents.go - Add GetMe, IssueApiToken to auth.go - Add DownloadExport to exports.go - Add Health package-level function in health.go - Add corresponding types and document all exports in README Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
0fdedb7247
commit
c21e9fcfc6
6 files changed
+245
-3
No files matched your search
@@ -110,6 +110,13 @@ client, err := elydora.NewClient(&elydora.Config{
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Client Methods
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Update the JWT token at runtime
|
||||||
|
client.SetToken("new-jwt-token")
|
||||||
|
```
|
||||||
|
|
||||||
### Authentication
|
### Authentication
|
||||||
|
|
||||||
```go
|
```go
|
||||||
@@ -121,6 +128,14 @@ reg, err := elydora.Register(baseURL, email, password,
|
|||||||
|
|
||||||
// Login and receive a JWT
|
// Login and receive a JWT
|
||||||
auth, err := elydora.Login(baseURL, email, password)
|
auth, err := elydora.Login(baseURL, email, password)
|
||||||
|
|
||||||
|
// Get current authenticated user profile
|
||||||
|
me, err := client.GetMe()
|
||||||
|
|
||||||
|
// Issue a new API token (with optional TTL)
|
||||||
|
tokenResp, err := client.IssueApiToken(&elydora.IssueApiTokenRequest{
|
||||||
|
TTLSeconds: &ttlSeconds,
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Operations
|
### Operations
|
||||||
@@ -153,7 +168,7 @@ agent, err := client.RegisterAgent(&elydora.RegisterAgentRequest{
|
|||||||
AgentID: "my-agent",
|
AgentID: "my-agent",
|
||||||
DisplayName: "My Agent",
|
DisplayName: "My Agent",
|
||||||
ResponsibleEntity: "team@example.com",
|
ResponsibleEntity: "team@example.com",
|
||||||
Keys: []elydora.AgentKeyRequest{
|
Keys: []elydora.RegisterAgentKeyInput{
|
||||||
{KID: "key-v1", PublicKey: "<base64url>", Algorithm: "ed25519"},
|
{KID: "key-v1", PublicKey: "<base64url>", Algorithm: "ed25519"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -166,6 +181,15 @@ err := client.FreezeAgent(agentID, "security review")
|
|||||||
|
|
||||||
// Revoke a key
|
// Revoke a key
|
||||||
err := client.RevokeKey(agentID, kid, "key rotation")
|
err := client.RevokeKey(agentID, kid, "key rotation")
|
||||||
|
|
||||||
|
// List all agents in the organization
|
||||||
|
agents, err := client.ListAgents()
|
||||||
|
|
||||||
|
// Unfreeze a previously frozen agent
|
||||||
|
err := client.UnfreezeAgent(agentID, "review complete")
|
||||||
|
|
||||||
|
// Delete an agent permanently
|
||||||
|
deleted, err := client.DeleteAgent(agentID)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Audit
|
### Audit
|
||||||
@@ -198,6 +222,9 @@ export, err := client.CreateExport(&elydora.CreateExportRequest{
|
|||||||
|
|
||||||
exports, err := client.ListExports()
|
exports, err := client.ListExports()
|
||||||
detail, err := client.GetExport(exportID)
|
detail, err := client.GetExport(exportID)
|
||||||
|
|
||||||
|
// Download export file data
|
||||||
|
data, err := client.DownloadExport(exportID)
|
||||||
```
|
```
|
||||||
|
|
||||||
### JWKS
|
### JWKS
|
||||||
@@ -206,6 +233,32 @@ detail, err := client.GetExport(exportID)
|
|||||||
jwks, err := client.GetJWKS()
|
jwks, err := client.GetJWKS()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Health
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Check API health (no authentication required, does not need a client)
|
||||||
|
health, err := elydora.Health("https://api.elydora.com")
|
||||||
|
// health.Status, health.Version, health.ProtocolVersion, health.Timestamp
|
||||||
|
```
|
||||||
|
|
||||||
|
### Constants
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Genesis chain hash — initial prev_chain_hash for an agent's first operation
|
||||||
|
elydora.GenesisChainHash // "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Status Enums
|
||||||
|
|
||||||
|
| Type | Constants |
|
||||||
|
|------|-----------|
|
||||||
|
| `AgentStatus` | `AgentStatusActive`, `AgentStatusFrozen`, `AgentStatusRevoked` |
|
||||||
|
| `KeyStatus` | `KeyStatusActive`, `KeyStatusRetired`, `KeyStatusRevoked` |
|
||||||
|
| `ExportStatus` | `ExportStatusQueued`, `ExportStatusRunning`, `ExportStatusDone`, `ExportStatusFailed` |
|
||||||
|
| `ExportFormat` | `ExportFormatJSON`, `ExportFormatPDF` |
|
||||||
|
| `RbacRole` | `RbacRoleOrgOwner`, `RbacRoleSecurityAdmin`, `RbacRoleComplianceAuditor`, `RbacRoleReadonlyInvestigator`, `RbacRoleIntegrationEngineer` |
|
||||||
|
| `ErrorCode` | `ErrorCodeInvalidSignature`, `ErrorCodeUnknownAgent`, `ErrorCodeKeyRevoked`, `ErrorCodeAgentFrozen`, `ErrorCodeTTLExpired`, `ErrorCodeReplayDetected`, `ErrorCodePrevHashMismatch`, `ErrorCodePayloadTooLarge`, `ErrorCodeRateLimited`, `ErrorCodeInternalError`, `ErrorCodeUnauthorized`, `ErrorCodeForbidden`, `ErrorCodeNotFound`, `ErrorCodeValidationError` |
|
||||||
|
|
||||||
## Error Handling
|
## Error Handling
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package elydora
|
package elydora
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
// RegisterAgent registers a new AI agent within the organization.
|
// RegisterAgent registers a new AI agent within the organization.
|
||||||
func (c *Client) RegisterAgent(req *RegisterAgentRequest) (*RegisterAgentResponse, error) {
|
func (c *Client) RegisterAgent(req *RegisterAgentRequest) (*RegisterAgentResponse, error) {
|
||||||
@@ -34,3 +37,28 @@ func (c *Client) RevokeKey(agentID, kid, reason string) error {
|
|||||||
Reason: reason,
|
Reason: reason,
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListAgents retrieves all agents for the organization.
|
||||||
|
func (c *Client) ListAgents() (*ListAgentsResponse, error) {
|
||||||
|
var result ListAgentsResponse
|
||||||
|
if err := c.doGet("/v1/agents", &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnfreezeAgent unfreezes a previously frozen agent.
|
||||||
|
func (c *Client) UnfreezeAgent(agentID, reason string) error {
|
||||||
|
return c.doPost(fmt.Sprintf("/v1/agents/%s/unfreeze", agentID), &UnfreezeAgentRequest{
|
||||||
|
Reason: reason,
|
||||||
|
}, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteAgent permanently deletes an agent and all associated data.
|
||||||
|
func (c *Client) DeleteAgent(agentID string) (*DeleteAgentResponse, error) {
|
||||||
|
var result DeleteAgentResponse
|
||||||
|
if err := c.doRequest(http.MethodDelete, fmt.Sprintf("/v1/agents/%s", agentID), nil, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
@@ -122,3 +122,21 @@ func authPost(baseURL, path string, body interface{}, result interface{}) error
|
|||||||
Message: string(respBody),
|
Message: string(respBody),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMe retrieves the current authenticated user's profile.
|
||||||
|
func (c *Client) GetMe() (*GetMeResponse, error) {
|
||||||
|
var result GetMeResponse
|
||||||
|
if err := c.doGet("/v1/auth/me", &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueApiToken creates a new API token with an optional TTL.
|
||||||
|
func (c *Client) IssueApiToken(req *IssueApiTokenRequest) (*IssueApiTokenResponse, error) {
|
||||||
|
var result IssueApiTokenResponse
|
||||||
|
if err := c.doPost("/v1/auth/token", req, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
+50
-1
@@ -1,6 +1,11 @@
|
|||||||
package elydora
|
package elydora
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
// CreateExport creates a new compliance export job.
|
// CreateExport creates a new compliance export job.
|
||||||
func (c *Client) CreateExport(params *CreateExportRequest) (*CreateExportResponse, error) {
|
func (c *Client) CreateExport(params *CreateExportRequest) (*CreateExportResponse, error) {
|
||||||
@@ -28,3 +33,47 @@ func (c *Client) GetExport(exportID string) (*GetExportResponse, error) {
|
|||||||
}
|
}
|
||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DownloadExport downloads the raw file data for a completed export.
|
||||||
|
func (c *Client) DownloadExport(exportID string) ([]byte, error) {
|
||||||
|
u := c.baseURL + fmt.Sprintf("/v1/exports/%s/download", exportID)
|
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodGet, u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("elydora: create request: %w", err)
|
||||||
|
}
|
||||||
|
if c.token != "" {
|
||||||
|
req.Header.Set("Authorization", "Bearer "+c.token)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := c.httpClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("elydora: http request: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("elydora: read response body: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
var errResp errorResponse
|
||||||
|
if jsonErr := json.Unmarshal(body, &errResp); jsonErr == nil && errResp.Error.Code != "" {
|
||||||
|
return nil, &ElydoraError{
|
||||||
|
StatusCode: resp.StatusCode,
|
||||||
|
Code: errResp.Error.Code,
|
||||||
|
Message: errResp.Error.Message,
|
||||||
|
RequestID: errResp.Error.RequestID,
|
||||||
|
Details: errResp.Error.Details,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, &ElydoraError{
|
||||||
|
StatusCode: resp.StatusCode,
|
||||||
|
Code: ErrorCodeInternalError,
|
||||||
|
Message: string(body),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return body, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package elydora
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Health checks the health of the Elydora API. This is a public endpoint
|
||||||
|
// that does not require authentication.
|
||||||
|
func Health(baseURL string) (*HealthResponse, error) {
|
||||||
|
if baseURL == "" {
|
||||||
|
baseURL = defaultBaseURL
|
||||||
|
}
|
||||||
|
baseURL = strings.TrimRight(baseURL, "/")
|
||||||
|
|
||||||
|
client := &http.Client{Timeout: 30 * time.Second}
|
||||||
|
req, err := http.NewRequest(http.MethodGet, baseURL+"/v1/health", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("elydora: create request: %w", err)
|
||||||
|
}
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("elydora: http request: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
respBody, err := io.ReadAll(io.LimitReader(resp.Body, 10<<20))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("elydora: read response body: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||||
|
var result HealthResponse
|
||||||
|
if err := json.Unmarshal(respBody, &result); err != nil {
|
||||||
|
return nil, fmt.Errorf("elydora: unmarshal response: %w", err)
|
||||||
|
}
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var errResp errorResponse
|
||||||
|
if err := json.Unmarshal(respBody, &errResp); err == nil && errResp.Error.Code != "" {
|
||||||
|
return nil, &ElydoraError{
|
||||||
|
StatusCode: resp.StatusCode,
|
||||||
|
Code: errResp.Error.Code,
|
||||||
|
Message: errResp.Error.Message,
|
||||||
|
RequestID: errResp.Error.RequestID,
|
||||||
|
Details: errResp.Error.Details,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, &ElydoraError{
|
||||||
|
StatusCode: resp.StatusCode,
|
||||||
|
Code: ErrorCodeInternalError,
|
||||||
|
Message: string(respBody),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -230,6 +230,38 @@ type RevokeAgentRequest struct {
|
|||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UnfreezeAgentRequest struct {
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListAgentsResponse struct {
|
||||||
|
Agents []Agent `json:"agents"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteAgentResponse struct {
|
||||||
|
Deleted bool `json:"deleted"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetMeResponse struct {
|
||||||
|
User User `json:"user"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type IssueApiTokenRequest struct {
|
||||||
|
TTLSeconds *int `json:"ttl_seconds"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type IssueApiTokenResponse struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
ExpiresAt *int64 `json:"expires_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HealthResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
ProtocolVersion string `json:"protocol_version"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
}
|
||||||
|
|
||||||
type SubmitOperationResponse struct {
|
type SubmitOperationResponse struct {
|
||||||
Receipt EAR `json:"receipt"`
|
Receipt EAR `json:"receipt"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user