Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Form, Flow, and Flow Vault Connection Managers #444

Merged
merged 18 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
183 changes: 183 additions & 0 deletions management/flow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package management

import (
"context"
"encoding/json"
"time"
)

// Flow represents an Auth0 flow for flow resource.
//
// See: https://auth0.com/docs/customize/forms/intro-to-flows
type Flow struct {
// Flow identifier
ID *string `json:"id,omitempty"`

// Flow name
Name *string `json:"name,omitempty"`

// Flow description
Description *string `json:"description,omitempty"`

// Sync or Async flow type
Synchronous *bool `json:"synchronous,omitempty"`

// Flow actions
Actions []interface{} `json:"actions,omitempty"`

// Flow triggers to execute flows
Triggers *map[string]interface{} `json:"triggers,omitempty"`

// Security configuration for flow executions
Security *map[string]interface{} `json:"security,omitempty"`

// Number of flows linked to this flow
FlowCount *int `json:"flow_count,omitempty"`
developerkunal marked this conversation as resolved.
Show resolved Hide resolved

CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
ExecutedAt *time.Time `json:"executed_at,omitempty"`
}

// FlowList holds a list of Flow.
type FlowList struct {
List
Flows []*Flow `json:"flows"`
}

// MarshalJSON implements the json.Marshaller interface.
func (f *Flow) MarshalJSON() ([]byte, error) {
type FlowSubset struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Synchronous *bool `json:"synchronous,omitempty"`
Actions []interface{} `json:"actions,omitempty"`
Triggers *map[string]interface{} `json:"triggers,omitempty"`
Security *map[string]interface{} `json:"security,omitempty"`
}

return json.Marshal(&FlowSubset{
Name: f.Name,
Description: f.Description,
Synchronous: f.Synchronous,
Actions: f.Actions,
Triggers: f.Triggers,
Security: f.Security,
})
}

// FlowVaultConnection represents an Auth0 flow vault connection resource.
//
// See: https://auth0.com/docs/customize/forms/vault
type FlowVaultConnection struct {
// Flow vault connection identifier
ID *string `json:"id,omitempty"`

// Flow vault connection app identifier
AppID *string `json:"app_id,omitempty"`

// Flow vault connection environment
Environment *string `json:"environment,omitempty"`

// Flow vault connection name
Name *string `json:"name,omitempty"`

// Flow vault connection configuration
Setup *map[string]interface{} `json:"setup,omitempty"`

// Flow vault connection custom account name
AccountName *string `json:"account_name,omitempty"`

// When Flow vault connection is configured
Ready *bool `json:"ready,omitempty"`

CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
RefreshedAt *time.Time `json:"refreshed_at,omitempty"`
}

// FlowVaultConnectionList holds a list of flow vault connections.
type FlowVaultConnectionList struct {
List
Connections []*FlowVaultConnection `json:"connections"`
}

// MarshalJSON implements the json.Marshaller interface.
func (f *FlowVaultConnection) MarshalJSON() ([]byte, error) {
type FlowVaultConnectionSubset struct {
AppID *string `json:"app_id,omitempty"`
Name *string `json:"name,omitempty"`
Setup *map[string]interface{} `json:"setup,omitempty"`
}

return json.Marshal(&FlowVaultConnectionSubset{
AppID: f.AppID,
Name: f.Name,
Setup: f.Setup,
})
}

// FlowManager manages Auth0 Flow resources.
type FlowManager struct {
management *Management
developerkunal marked this conversation as resolved.
Show resolved Hide resolved

// FlowVaultConnection manages flow vault connection resources.
Vault *flowVaultConnectionManager
}

// Create a new flow.
func (m *FlowManager) Create(ctx context.Context, r *Flow, opts ...RequestOption) error {
return m.management.Request(ctx, "POST", m.management.URI("flows"), r, opts...)
}

// Retrieve flow details.
func (m *FlowManager) Read(ctx context.Context, id string, opts ...RequestOption) (r *Flow, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("flows", id), &r, opts...)
return
}

// Update an existing flow.
func (m *FlowManager) Update(ctx context.Context, id string, r *Flow, opts ...RequestOption) error {
return m.management.Request(ctx, "PATCH", m.management.URI("flows", id), r, opts...)
}

// Delete a flow.
func (m *FlowManager) Delete(ctx context.Context, id string, opts ...RequestOption) error {
return m.management.Request(ctx, "DELETE", m.management.URI("flows", id), nil, opts...)
}

// List flow.
func (m *FlowManager) List(ctx context.Context, opts ...RequestOption) (r *FlowList, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("flows"), &r, applyListDefaults(opts))
return
}

// FlowVaultConnectionManager manages flow vault connection resources.
type flowVaultConnectionManager manager

// CreateConnection Create a new flow vault connection.
func (m *flowVaultConnectionManager) CreateConnection(ctx context.Context, r *FlowVaultConnection, opts ...RequestOption) error {
return m.management.Request(ctx, "POST", m.management.URI("flows", "vault", "connections"), r, opts...)
}

// GetConnection Retrieve flow vault connection details.
func (m *flowVaultConnectionManager) GetConnection(ctx context.Context, id string, opts ...RequestOption) (r *FlowVaultConnection, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("flows", "vault", "connections", id), &r, opts...)
return
}

// UpdateConnection Update an existing flow vault connection.
func (m *flowVaultConnectionManager) UpdateConnection(ctx context.Context, id string, r *FlowVaultConnection, opts ...RequestOption) error {
return m.management.Request(ctx, "PATCH", m.management.URI("flows", "vault", "connections", id), r, opts...)
}

// DeleteConnection Delete a flow vault connection.
func (m *flowVaultConnectionManager) DeleteConnection(ctx context.Context, id string, opts ...RequestOption) error {
return m.management.Request(ctx, "DELETE", m.management.URI("flows", "vault", "connections", id), nil, opts...)
}

// GetConnectionList List flow vault connections.
func (m *flowVaultConnectionManager) GetConnectionList(ctx context.Context, opts ...RequestOption) (r *FlowVaultConnectionList, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("flows", "vault", "connections"), &r, applyListDefaults(opts))
return
}
Loading