| 
 | 1 | +package management  | 
 | 2 | + | 
 | 3 | +import (  | 
 | 4 | +	"net/http"  | 
 | 5 | +	"time"  | 
 | 6 | +)  | 
 | 7 | + | 
 | 8 | +const (  | 
 | 9 | +	ActionTriggerPostLogin         string = "post-login"  | 
 | 10 | +	ActionTriggerClientCredentials string = "client-credentials"  | 
 | 11 | +)  | 
 | 12 | + | 
 | 13 | +type ActionTrigger struct {  | 
 | 14 | +	ID      *string `json:"id"`  | 
 | 15 | +	Version *string `json:"version"`  | 
 | 16 | +	Status  *string `json:"status,omitempty"`  | 
 | 17 | +}  | 
 | 18 | + | 
 | 19 | +type ActionTriggerList struct {  | 
 | 20 | +	Triggers []*ActionTrigger `json:"triggers"`  | 
 | 21 | +}  | 
 | 22 | + | 
 | 23 | +type ActionDependency struct {  | 
 | 24 | +	Name        *string `json:"name"`  | 
 | 25 | +	Version     *string `json:"version,omitempty"`  | 
 | 26 | +	RegistryURL *string `json:"registry_url,omitempty"`  | 
 | 27 | +}  | 
 | 28 | + | 
 | 29 | +type ActionSecret struct {  | 
 | 30 | +	Name      *string    `json:"name"`  | 
 | 31 | +	Value     *string    `json:"value,omitempty"`  | 
 | 32 | +	UpdatedAt *time.Time `json:"updated_at,omitempty"`  | 
 | 33 | +}  | 
 | 34 | + | 
 | 35 | +type ActionVersionError struct {  | 
 | 36 | +	ID      *string `json:"id"`  | 
 | 37 | +	Message *string `json:"msg"`  | 
 | 38 | +	Url     *string `json:"url"`  | 
 | 39 | +}  | 
 | 40 | + | 
 | 41 | +const (  | 
 | 42 | +	ActionStatusPending  string = "pending"  | 
 | 43 | +	ActionStatusBuilding string = "building"  | 
 | 44 | +	ActionStatusPackaged string = "packaged"  | 
 | 45 | +	ActionStatusBuilt    string = "built"  | 
 | 46 | +	ActionStatusRetrying string = "retrying"  | 
 | 47 | +	ActionStatusFailed   string = "failed"  | 
 | 48 | +)  | 
 | 49 | + | 
 | 50 | +type Action struct {  | 
 | 51 | +	ID   *string `json:"id,omitempty"`  | 
 | 52 | +	Name *string `json:"name"`  | 
 | 53 | +	Code *string `json:"code,omitempty"` // nil in embedded Action in ActionVersion  | 
 | 54 | + | 
 | 55 | +	SupportedTriggers []ActionTrigger    `json:"supported_triggers"`  | 
 | 56 | +	Dependencies      []ActionDependency `json:"dependencies,omitempty"`  | 
 | 57 | +	Secrets           []ActionSecret     `json:"secrets,omitempty"`  | 
 | 58 | + | 
 | 59 | +	DeployedVersion    *ActionVersion `json:"deployed_version,omitempty"`  | 
 | 60 | +	Status             *string        `json:"status,omitempty"`  | 
 | 61 | +	AllChangesDeployed bool           `json:"all_changes_deployed,omitempty"`  | 
 | 62 | + | 
 | 63 | +	BuiltAt   *time.Time `json:"built_at,omitempty"`  | 
 | 64 | +	CreatedAt *time.Time `json:"created_at,omitempty"`  | 
 | 65 | +	UpdatedAt *time.Time `json:"updated_at,omitempty"`  | 
 | 66 | +}  | 
 | 67 | + | 
 | 68 | +type ActionList struct {  | 
 | 69 | +	List  | 
 | 70 | +	Actions []*Action `json:"actions"`  | 
 | 71 | +}  | 
 | 72 | + | 
 | 73 | +type ActionVersion struct {  | 
 | 74 | +	ID           *string            `json:"id,omitempty"`  | 
 | 75 | +	Code         *string            `json:"code"`  | 
 | 76 | +	Dependencies []ActionDependency `json:"dependencies,omitempty"`  | 
 | 77 | +	Deployed     bool               `json:"deployed"`  | 
 | 78 | +	Status       *string            `json:"status,omitempty"`  | 
 | 79 | +	Number       int                `json:"number,omitempty"`  | 
 | 80 | + | 
 | 81 | +	Errors []ActionVersionError `json:"errors,omitempty"`  | 
 | 82 | +	Action *Action              `json:"action,omitempty"`  | 
 | 83 | + | 
 | 84 | +	BuiltAt   *time.Time `json:"built_at,omitempty"`  | 
 | 85 | +	CreatedAt *time.Time `json:"created_at,omitempty"`  | 
 | 86 | +	UpdatedAt *time.Time `json:"updated_at,omitempty"`  | 
 | 87 | +}  | 
 | 88 | + | 
 | 89 | +type ActionVersionList struct {  | 
 | 90 | +	List  | 
 | 91 | +	Versions []*ActionVersion `json:"versions"`  | 
 | 92 | +}  | 
 | 93 | + | 
 | 94 | +const (  | 
 | 95 | +	ActionBindingReferenceByName string = "action_name"  | 
 | 96 | +	ActionBindingReferenceById   string = "action_id"  | 
 | 97 | +)  | 
 | 98 | + | 
 | 99 | +type ActionBindingReference struct {  | 
 | 100 | +	Type  *string `json:"type"`  | 
 | 101 | +	Value *string `json:"value"`  | 
 | 102 | +}  | 
 | 103 | + | 
 | 104 | +type ActionBinding struct {  | 
 | 105 | +	ID          *string `json:"id,omitempty"`  | 
 | 106 | +	TriggerID   *string `json:"trigger_id,omitempty"`  | 
 | 107 | +	DisplayName *string `json:"display_name,omitempty"`  | 
 | 108 | + | 
 | 109 | +	Ref     *ActionBindingReference `json:"ref,omitempty"`  | 
 | 110 | +	Action  *Action                 `json:"action,omitempty"`  | 
 | 111 | +	Secrets []ActionSecret          `json:"secrets,omitempty"`  | 
 | 112 | + | 
 | 113 | +	CreatedAt *time.Time `json:"created_at,omitempty"`  | 
 | 114 | +	UpdatedAt *time.Time `json:"updated_at,omitempty"`  | 
 | 115 | +}  | 
 | 116 | + | 
 | 117 | +type ActionBindingList struct {  | 
 | 118 | +	List  | 
 | 119 | +	Bindings []*ActionBinding `json:"bindings"`  | 
 | 120 | +}  | 
 | 121 | + | 
 | 122 | +type actionBindingsPerTrigger struct {  | 
 | 123 | +	Bindings []*ActionBinding `json:"bindings"`  | 
 | 124 | +}  | 
 | 125 | + | 
 | 126 | +type ActionTestPayload map[string]interface{}  | 
 | 127 | + | 
 | 128 | +type ActionTestRequest struct {  | 
 | 129 | +	Payload *ActionTestPayload `json:"payload"`  | 
 | 130 | +}  | 
 | 131 | + | 
 | 132 | +type ActionExecutionResult struct {  | 
 | 133 | +	ActionName *string            `json:"action_name,omitempty"`  | 
 | 134 | +	Error      *map[string]string `json:"error,omitempty"`  | 
 | 135 | + | 
 | 136 | +	StartedAt *time.Time `json:"started_at,omitempty"`  | 
 | 137 | +	EndedAt   *time.Time `json:"ended_at,omitempty"`  | 
 | 138 | +}  | 
 | 139 | + | 
 | 140 | +type ActionExecution struct {  | 
 | 141 | +	ID        *string                  `json:"id"`  | 
 | 142 | +	TriggerID *string                  `json:"trigger_id"`  | 
 | 143 | +	Status    *string                  `json:"status"`  | 
 | 144 | +	Results   []*ActionExecutionResult `json:"results"`  | 
 | 145 | + | 
 | 146 | +	CreatedAt *time.Time `json:"created_at"`  | 
 | 147 | +	UpdatedAt *time.Time `json:"updated_at"`  | 
 | 148 | +}  | 
 | 149 | + | 
 | 150 | +type ActionManager struct {  | 
 | 151 | +	*Management  | 
 | 152 | +}  | 
 | 153 | + | 
 | 154 | +func newActionManager(m *Management) *ActionManager {  | 
 | 155 | +	return &ActionManager{m}  | 
 | 156 | +}  | 
 | 157 | + | 
 | 158 | +func applyActionsListDefaults(options []RequestOption) RequestOption {  | 
 | 159 | +	return newRequestOption(func(r *http.Request) {  | 
 | 160 | +		PerPage(50).apply(r)  | 
 | 161 | +		for _, option := range options {  | 
 | 162 | +			option.apply(r)  | 
 | 163 | +		}  | 
 | 164 | +	})  | 
 | 165 | +}  | 
 | 166 | + | 
 | 167 | +// ListTriggers available.  | 
 | 168 | +//  | 
 | 169 | +// https://auth0.com/docs/api/management/v2/#!/Actions/get_triggers  | 
 | 170 | +func (m *ActionManager) ListTriggers(opts ...RequestOption) (l *ActionTriggerList, err error) {  | 
 | 171 | +	err = m.Request("GET", m.URI("actions", "triggers"), &l, opts...)  | 
 | 172 | +	return  | 
 | 173 | +}  | 
 | 174 | + | 
 | 175 | +// Create a new action.  | 
 | 176 | +//  | 
 | 177 | +// See: https://auth0.com/docs/api/management/v2#!/Actions/post_action  | 
 | 178 | +func (m *ActionManager) Create(a *Action, opts ...RequestOption) error {  | 
 | 179 | +	return m.Request("POST", m.URI("actions", "actions"), a, opts...)  | 
 | 180 | +}  | 
 | 181 | + | 
 | 182 | +// Retrieve action details.  | 
 | 183 | +//  | 
 | 184 | +// See: https://auth0.com/docs/api/management/v2#!/Actions/get_action  | 
 | 185 | +func (m *ActionManager) Read(id string, opts ...RequestOption) (a *Action, err error) {  | 
 | 186 | +	err = m.Request("GET", m.URI("actions", "actions", id), &a, opts...)  | 
 | 187 | +	return  | 
 | 188 | +}  | 
 | 189 | + | 
 | 190 | +// Update an existing action.  | 
 | 191 | +//  | 
 | 192 | +// See: https://auth0.com/docs/api/management/v2#!/Actions/patch_action  | 
 | 193 | +func (m *ActionManager) Update(id string, a *Action, opts ...RequestOption) error {  | 
 | 194 | +	return m.Request("PATCH", m.URI("actions", "actions", id), &a, opts...)  | 
 | 195 | +}  | 
 | 196 | + | 
 | 197 | +// Delete an action  | 
 | 198 | +//  | 
 | 199 | +// See: https://auth0.com/docs/api/management/v2#!/Actions/delete_action  | 
 | 200 | +func (m *ActionManager) Delete(id string, opts ...RequestOption) error {  | 
 | 201 | +	return m.Request("DELETE", m.URI("actions", "actions", id), nil, opts...)  | 
 | 202 | +}  | 
 | 203 | + | 
 | 204 | +// List all actions.  | 
 | 205 | +//  | 
 | 206 | +// See: https://auth0.com/docs/api/management/v2#!/Actions/get_actions  | 
 | 207 | +func (m *ActionManager) List(opts ...RequestOption) (l *ActionList, err error) {  | 
 | 208 | +	err = m.Request("GET", m.URI("actions", "actions"), &l, applyActionsListDefaults(opts))  | 
 | 209 | +	return  | 
 | 210 | +}  | 
 | 211 | + | 
 | 212 | +// ReadVersion of an action.  | 
 | 213 | +//  | 
 | 214 | +// See: https://auth0.com/docs/api/management/v2/#!/Actions/get_action_version  | 
 | 215 | +func (m *ActionManager) ReadVersion(id string, versionId string, opts ...RequestOption) (v *ActionVersion, err error) {  | 
 | 216 | +	err = m.Request("GET", m.URI("actions", "actions", id, "versions", versionId), &v, opts...)  | 
 | 217 | +	return  | 
 | 218 | +}  | 
 | 219 | + | 
 | 220 | +// ListVersions of an action.  | 
 | 221 | +//  | 
 | 222 | +// See: https://auth0.com/docs/api/management/v2/#!/Actions/get_action_versions  | 
 | 223 | +func (m *ActionManager) ListVersions(id string, opts ...RequestOption) (c *ActionVersionList, err error) {  | 
 | 224 | +	err = m.Request("GET", m.URI("actions", "actions", id, "versions"), &c, applyActionsListDefaults(opts))  | 
 | 225 | +	return  | 
 | 226 | +}  | 
 | 227 | + | 
 | 228 | +// UpdateBindings of a trigger  | 
 | 229 | +//  | 
 | 230 | +// See: https://auth0.com/docs/api/management/v2/#!/Actions/patch_bindings  | 
 | 231 | +func (m *ActionManager) UpdateBindings(triggerID string, b []*ActionBinding, opts ...RequestOption) error {  | 
 | 232 | +	bl := &actionBindingsPerTrigger{  | 
 | 233 | +		Bindings: b,  | 
 | 234 | +	}  | 
 | 235 | +	return m.Request("PATCH", m.URI("actions", "triggers", triggerID, "bindings"), &bl, opts...)  | 
 | 236 | +}  | 
 | 237 | + | 
 | 238 | +// ListBindings of a trigger  | 
 | 239 | +//  | 
 | 240 | +// See: https://auth0.com/docs/api/management/v2/#!/Actions/get_bindings  | 
 | 241 | +func (m *ActionManager) ListBindings(triggerID string, opts ...RequestOption) (bl *ActionBindingList, err error) {  | 
 | 242 | +	err = m.Request("GET", m.URI("actions", "triggers", triggerID, "bindings"), &bl, applyActionsListDefaults(opts))  | 
 | 243 | +	return  | 
 | 244 | +}  | 
 | 245 | + | 
 | 246 | +// Deploy an action  | 
 | 247 | +//  | 
 | 248 | +// See: https://auth0.com/docs/api/management/v2/#!/Actions/post_deploy_action  | 
 | 249 | +func (m *ActionManager) Deploy(id string, opts ...RequestOption) (v *ActionVersion, err error) {  | 
 | 250 | +	err = m.Request("POST", m.URI("actions", "actions", id, "deploy"), &v, opts...)  | 
 | 251 | +	return  | 
 | 252 | +}  | 
 | 253 | + | 
 | 254 | +// DeployVersion of an action  | 
 | 255 | +//  | 
 | 256 | +// See: https://auth0.com/docs/api/management/v2/#!/Actions/post_deploy_draft_version  | 
 | 257 | +func (m *ActionManager) DeployVersion(id string, versionId string, opts ...RequestOption) (v *ActionVersion, err error) {  | 
 | 258 | +	err = m.Request("POST", m.URI("actions", "actions", id, "versions", versionId, "deploy"), &v, opts...)  | 
 | 259 | +	return  | 
 | 260 | +}  | 
 | 261 | + | 
 | 262 | +// Test an action  | 
 | 263 | +//  | 
 | 264 | +// See: https://auth0.com/docs/api/management/v2/#!/Actions/post_test_action  | 
 | 265 | +func (m *ActionManager) Test(id string, payload *ActionTestPayload, opts ...RequestOption) (err error) {  | 
 | 266 | +	r := &ActionTestRequest{  | 
 | 267 | +		Payload: payload,  | 
 | 268 | +	}  | 
 | 269 | +	err = m.Request("POST", m.URI("actions", "actions", id, "test"), &r, opts...)  | 
 | 270 | +	return  | 
 | 271 | +}  | 
 | 272 | + | 
 | 273 | +// ReadExecution of an action  | 
 | 274 | +//  | 
 | 275 | +// See: https://auth0.com/docs/api/management/v2/#!/Actions/get_execution  | 
 | 276 | +func (m *ActionManager) ReadExecution(executionId string, opts ...RequestOption) (v *ActionExecution, err error) {  | 
 | 277 | +	err = m.Request("GET", m.URI("actions", "executions", executionId), &v, opts...)  | 
 | 278 | +	return  | 
 | 279 | +}  | 
0 commit comments