Skip to content
Merged
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
68 changes: 61 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,60 @@ func main() {
}
```

### HID Organizations

#### Create an HID org

```go
ctx := context.Background()
org, err := client.Console.HID.Orgs.Create(ctx, &accessgrid.CreateHIDOrgParams{
Name: "My Org",
FullAddress: "1 Main St, NY NY",
Phone: "+1-555-0000",
FirstName: "Ada",
LastName: "Lovelace",
})
if err != nil {
fmt.Printf("Error creating org: %v\n", err)
return
}

fmt.Printf("Created org: %s (ID: %s)\n", org.Name, org.ID)
fmt.Printf("Slug: %s\n", org.Slug)
```

#### List HID orgs

```go
ctx := context.Background()
orgs, err := client.Console.HID.Orgs.List(ctx)
if err != nil {
fmt.Printf("Error listing orgs: %v\n", err)
return
}

for _, org := range orgs {
fmt.Printf("Org ID: %s, Name: %s, Slug: %s\n", org.ID, org.Name, org.Slug)
}
```

#### Activate an HID org

```go
ctx := context.Background()
result, err := client.Console.HID.Orgs.Activate(ctx, &accessgrid.CompleteHIDOrgParams{
Email: "admin@example.com",
Password: "hid-password-123",
})
if err != nil {
fmt.Printf("Error completing registration: %v\n", err)
return
}

fmt.Printf("Completed registration for org: %s\n", result.Name)
fmt.Printf("Status: %s\n", result.Status)
```

## Configuration

The SDK can be configured with custom options:
Expand Down Expand Up @@ -498,14 +552,14 @@ Never expose your `secretKey` in source code. Always use environment variables o
| GET /v1/console/card-templates/{id} | `Console.ReadTemplate()` | Y |
| GET /v1/console/card-templates/{id}/logs | `Console.EventLog()` | Y |
| GET /v1/console/pass-template-pairs | `Console.ListPassTemplatePairs()` | Y |
| POST /v1/console/card-templates/{id}/ios_preflight | `Console.IosPreflight()` | - |
| POST /v1/console/card-templates/{id}/ios_preflight | `Console.IosPreflight()` | Y |
| GET /v1/console/ledger-items | `Console.ListLedgerItems()` | Y |
| GET /v1/console/webhooks | `Console.Webhooks.List()` | - |
| POST /v1/console/webhooks | `Console.Webhooks.Create()` | - |
| DELETE /v1/console/webhooks/{id} | `Console.Webhooks.Delete()` | - |
| POST /v1/console/hid/orgs | `Console.HID.Orgs.Create()` | - |
| POST /v1/console/hid/orgs/activate | `Console.HID.Orgs.Activate()` | - |
| GET /v1/console/hid/orgs | `Console.HID.Orgs.List()` | - |
| GET /v1/console/webhooks | `Console.Webhooks.List()` | Y |
| POST /v1/console/webhooks | `Console.Webhooks.Create()` | Y |
| DELETE /v1/console/webhooks/{id} | `Console.Webhooks.Delete()` | Y |
| POST /v1/console/hid/orgs | `Console.HID.Orgs.Create()` | Y |
| POST /v1/console/hid/orgs/activate | `Console.HID.Orgs.Activate()` | Y |
| GET /v1/console/hid/orgs | `Console.HID.Orgs.List()` | Y |

## License

Expand Down
24 changes: 24 additions & 0 deletions accessgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,28 @@ type (

// ListLedgerItemsParams defines parameters for listing ledger items
ListLedgerItemsParams = models.ListLedgerItemsParams

// IosPreflight represents an iOS In-App Provisioning preflight response
IosPreflight = models.IosPreflight

// IosPreflightParams defines parameters for iOS preflight
IosPreflightParams = models.IosPreflightParams

// Webhook represents a webhook configuration
Webhook = models.Webhook

// WebhooksResponse represents the response from listing webhooks
WebhooksResponse = models.WebhooksResponse

// CreateWebhookParams defines parameters for creating a webhook
CreateWebhookParams = models.CreateWebhookParams

// HIDOrg represents an HID organization
HIDOrg = models.HIDOrg

// CreateHIDOrgParams defines parameters for creating an HID organization
CreateHIDOrgParams = models.CreateHIDOrgParams

// CompleteHIDOrgParams defines parameters for completing HID org registration
CompleteHIDOrgParams = models.CompleteHIDOrgParams
)
69 changes: 69 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,72 @@ type ListLedgerItemsParams struct {
StartDate *time.Time `json:"start_date,omitempty"`
EndDate *time.Time `json:"end_date,omitempty"`
}

// IosPreflight represents an iOS In-App Provisioning preflight response
type IosPreflight struct {
ProvisioningCredentialIdentifier string `json:"provisioningCredentialIdentifier"`
SharingInstanceIdentifier string `json:"sharingInstanceIdentifier"`
CardTemplateIdentifier string `json:"cardTemplateIdentifier"`
EnvironmentIdentifier string `json:"environmentIdentifier"`
}

// IosPreflightParams defines parameters for iOS preflight
type IosPreflightParams struct {
CardTemplateID string `json:"card_template_id"`
AccessPassExID string `json:"access_pass_ex_id"`
}

// Webhook represents a webhook configuration
type Webhook struct {
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
AuthMethod string `json:"auth_method"`
SubscribedEvents []string `json:"subscribed_events"`
CreatedAt string `json:"created_at"`
PrivateKey string `json:"private_key,omitempty"`
ClientCert string `json:"client_cert,omitempty"`
CertExpiresAt string `json:"cert_expires_at,omitempty"`
}

// WebhooksResponse represents the response from listing webhooks
type WebhooksResponse struct {
Webhooks []Webhook `json:"webhooks"`
Pagination Pagination `json:"pagination"`
}

// CreateWebhookParams defines parameters for creating a webhook
type CreateWebhookParams struct {
Name string `json:"name"`
URL string `json:"url"`
SubscribedEvents []string `json:"subscribed_events"`
AuthMethod string `json:"auth_method,omitempty"`
}

// HIDOrg represents an HID organization
type HIDOrg struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Phone string `json:"phone"`
FullAddress string `json:"full_address"`
Status string `json:"status"`
CreatedAt string `json:"created_at"`
}

// CreateHIDOrgParams defines parameters for creating an HID organization
type CreateHIDOrgParams struct {
Name string `json:"name"`
FullAddress string `json:"full_address"`
Phone string `json:"phone"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}

// CompleteHIDOrgParams defines parameters for completing HID org registration
type CompleteHIDOrgParams struct {
Email string `json:"email"`
Password string `json:"password"`
}
119 changes: 116 additions & 3 deletions services/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,125 @@ import (

// ConsoleService handles operations related to the enterprise console
type ConsoleService struct {
client *client.Client
client *client.Client
HID *HIDService
Webhooks *WebhooksService
}

// NewConsoleService creates a new ConsoleService
func NewConsoleService(client *client.Client) *ConsoleService {
return &ConsoleService{client: client}
func NewConsoleService(c *client.Client) *ConsoleService {
return &ConsoleService{
client: c,
HID: NewHIDService(c),
Webhooks: NewWebhooksService(c),
}
}

// IosPreflight retrieves iOS In-App Provisioning identifiers
func (s *ConsoleService) IosPreflight(ctx context.Context, params models.IosPreflightParams) (*models.IosPreflight, error) {
var result models.IosPreflight
path := fmt.Sprintf("/v1/console/card-templates/%s/ios_preflight", url.PathEscape(params.CardTemplateID))
body := map[string]string{"access_pass_ex_id": params.AccessPassExID}
err := s.client.Request(ctx, http.MethodPost, path, body, &result)
if err != nil {
return nil, fmt.Errorf("error fetching iOS preflight: %w", err)
}
return &result, nil
}

// WebhooksService handles webhook operations
type WebhooksService struct {
client *client.Client
}

// NewWebhooksService creates a new WebhooksService
func NewWebhooksService(c *client.Client) *WebhooksService {
return &WebhooksService{client: c}
}

// Create creates a new webhook
func (s *WebhooksService) Create(ctx context.Context, params models.CreateWebhookParams) (*models.Webhook, error) {
if params.AuthMethod == "" {
params.AuthMethod = "bearer_token"
}
var webhook models.Webhook
err := s.client.Request(ctx, http.MethodPost, "/v1/console/webhooks", params, &webhook)
if err != nil {
return nil, fmt.Errorf("error creating webhook: %w", err)
}
return &webhook, nil
}

// List retrieves all webhooks
func (s *WebhooksService) List(ctx context.Context) (*models.WebhooksResponse, error) {
var response models.WebhooksResponse
err := s.client.Request(ctx, http.MethodGet, "/v1/console/webhooks", nil, &response)
if err != nil {
return nil, fmt.Errorf("error listing webhooks: %w", err)
}
return &response, nil
}

// Delete deletes a webhook by ID
func (s *WebhooksService) Delete(ctx context.Context, webhookID string) error {
path := fmt.Sprintf("/v1/console/webhooks/%s", url.PathEscape(webhookID))
err := s.client.Request(ctx, http.MethodDelete, path, nil, nil)
if err != nil {
return fmt.Errorf("error deleting webhook: %w", err)
}
return nil
}

// HIDService provides access to HID-related services
type HIDService struct {
Orgs *HIDOrgsService
}

// NewHIDService creates a new HIDService
func NewHIDService(c *client.Client) *HIDService {
return &HIDService{
Orgs: NewHIDOrgsService(c),
}
}

// HIDOrgsService handles HID organization operations
type HIDOrgsService struct {
client *client.Client
}

// NewHIDOrgsService creates a new HIDOrgsService
func NewHIDOrgsService(c *client.Client) *HIDOrgsService {
return &HIDOrgsService{client: c}
}

// Create creates a new HID organization
func (s *HIDOrgsService) Create(ctx context.Context, params *models.CreateHIDOrgParams) (*models.HIDOrg, error) {
var org models.HIDOrg
err := s.client.Request(ctx, http.MethodPost, "/v1/console/hid/orgs", params, &org)
if err != nil {
return nil, fmt.Errorf("error creating HID org: %w", err)
}
return &org, nil
}

// List retrieves all HID organizations
func (s *HIDOrgsService) List(ctx context.Context) ([]models.HIDOrg, error) {
var orgs []models.HIDOrg
err := s.client.Request(ctx, http.MethodGet, "/v1/console/hid/orgs", nil, &orgs)
if err != nil {
return nil, fmt.Errorf("error listing HID orgs: %w", err)
}
return orgs, nil
}

// Activate completes HID org registration with credentials
func (s *HIDOrgsService) Activate(ctx context.Context, params *models.CompleteHIDOrgParams) (*models.HIDOrg, error) {
var org models.HIDOrg
err := s.client.Request(ctx, http.MethodPost, "/v1/console/hid/orgs/activate", params, &org)
if err != nil {
return nil, fmt.Errorf("error activating HID org: %w", err)
}
return &org, nil
}

// CreateTemplate creates a new card template
Expand Down
Loading
Loading