Skip to content
This repository was archived by the owner on Feb 16, 2022. It is now read-only.

Commit 0ec90a9

Browse files
authored
Merge pull request #247 from go-auth0/update-actions
Update actions fields and methods
2 parents 25384ce + f0f8568 commit 0ec90a9

File tree

3 files changed

+120
-74
lines changed

3 files changed

+120
-74
lines changed

management/actions.go

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,33 @@ const (
4848
)
4949

5050
type Action struct {
51-
ID *string `json:"id,omitempty"`
51+
// ID of the action
52+
ID *string `json:"id,omitempty"`
53+
// The name of an action
5254
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"`
55+
// List of triggers that this action supports. At this time, an action can
56+
// only target a single trigger at a time.
57+
SupportedTriggers []*ActionTrigger `json:"supported_triggers"`
58+
// The source code of the action.
59+
Code *string `json:"code,omitempty"`
60+
// List of third party npm modules, and their versions, that this action
61+
// depends on.
62+
Dependencies []*ActionDependency `json:"dependencies,omitempty"`
63+
// The Node runtime. For example `node16`, defaults to `node12`
64+
Runtime *string `json:"runtime,omitempty"`
65+
// List of secrets that are included in an action or a version of an action.
66+
Secrets []*ActionSecret `json:"secrets,omitempty"`
67+
// Version of the action that is currently deployed.
68+
DeployedVersion *ActionVersion `json:"deployed_version,omitempty"`
69+
// The build status of this action.
70+
Status *string `json:"status,omitempty"`
71+
// True if all of an Action's contents have been deployed.
72+
AllChangesDeployed bool `json:"all_changes_deployed,omitempty"`
73+
// The time when this action was built successfully.
74+
BuiltAt *time.Time `json:"built_at,omitempty"`
75+
// The time when this action was created.
6476
CreatedAt *time.Time `json:"created_at,omitempty"`
77+
// The time when this action was updated.
6578
UpdatedAt *time.Time `json:"updated_at,omitempty"`
6679
}
6780

@@ -71,15 +84,15 @@ type ActionList struct {
7184
}
7285

7386
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"`
87+
ID *string `json:"id,omitempty"`
88+
Code *string `json:"code"`
89+
Dependencies []*ActionDependency `json:"dependencies,omitempty"`
90+
Deployed bool `json:"deployed"`
91+
Status *string `json:"status,omitempty"`
92+
Number int `json:"number,omitempty"`
8093

81-
Errors []ActionVersionError `json:"errors,omitempty"`
82-
Action *Action `json:"action,omitempty"`
94+
Errors []*ActionVersionError `json:"errors,omitempty"`
95+
Action *Action `json:"action,omitempty"`
8396

8497
BuiltAt *time.Time `json:"built_at,omitempty"`
8598
CreatedAt *time.Time `json:"created_at,omitempty"`
@@ -108,7 +121,7 @@ type ActionBinding struct {
108121

109122
Ref *ActionBindingReference `json:"ref,omitempty"`
110123
Action *Action `json:"action,omitempty"`
111-
Secrets []ActionSecret `json:"secrets,omitempty"`
124+
Secrets []*ActionSecret `json:"secrets,omitempty"`
112125

113126
CreatedAt *time.Time `json:"created_at,omitempty"`
114127
UpdatedAt *time.Time `json:"updated_at,omitempty"`
@@ -125,13 +138,13 @@ type actionBindingsPerTrigger struct {
125138

126139
type ActionTestPayload map[string]interface{}
127140

128-
type ActionTestRequest struct {
141+
type actionTestRequest struct {
129142
Payload *ActionTestPayload `json:"payload"`
130143
}
131144

132145
type ActionExecutionResult struct {
133-
ActionName *string `json:"action_name,omitempty"`
134-
Error *map[string]string `json:"error,omitempty"`
146+
ActionName *string `json:"action_name,omitempty"`
147+
Error map[string]interface{} `json:"error,omitempty"`
135148

136149
StartedAt *time.Time `json:"started_at,omitempty"`
137150
EndedAt *time.Time `json:"ended_at,omitempty"`
@@ -164,14 +177,21 @@ func applyActionsListDefaults(options []RequestOption) RequestOption {
164177
})
165178
}
166179

167-
// ListTriggers available.
180+
// Triggers lists the available triggers.
168181
//
169182
// https://auth0.com/docs/api/management/v2/#!/Actions/get_triggers
170-
func (m *ActionManager) ListTriggers(opts ...RequestOption) (l *ActionTriggerList, err error) {
183+
func (m *ActionManager) Triggers(opts ...RequestOption) (l *ActionTriggerList, err error) {
171184
err = m.Request("GET", m.URI("actions", "triggers"), &l, opts...)
172185
return
173186
}
174187

188+
// ListTriggers lists the available triggers.
189+
//
190+
// Deprecated: use Triggers() instead
191+
func (m *ActionManager) ListTriggers(opts ...RequestOption) (l *ActionTriggerList, err error) {
192+
return m.Triggers(opts...)
193+
}
194+
175195
// Create a new action.
176196
//
177197
// See: https://auth0.com/docs/api/management/v2#!/Actions/post_action
@@ -209,23 +229,37 @@ func (m *ActionManager) List(opts ...RequestOption) (l *ActionList, err error) {
209229
return
210230
}
211231

212-
// ReadVersion of an action.
232+
// Version retrieves the version of an action.
213233
//
214234
// 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) {
235+
func (m *ActionManager) Version(id string, versionId string, opts ...RequestOption) (v *ActionVersion, err error) {
216236
err = m.Request("GET", m.URI("actions", "actions", id, "versions", versionId), &v, opts...)
217237
return
218238
}
219239

220-
// ListVersions of an action.
240+
// ReadVersion retrieves the version of an action.
241+
//
242+
// Deprecated: use Version() instead.
243+
func (m *ActionManager) ReadVersion(id string, versionId string, opts ...RequestOption) (v *ActionVersion, err error) {
244+
return m.Version(id, versionId, opts...)
245+
}
246+
247+
// Versions lists all versions of an action.
221248
//
222249
// 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) {
250+
func (m *ActionManager) Versions(id string, opts ...RequestOption) (c *ActionVersionList, err error) {
224251
err = m.Request("GET", m.URI("actions", "actions", id, "versions"), &c, applyActionsListDefaults(opts))
225252
return
226253
}
227254

228-
// UpdateBindings of a trigger
255+
// ListVersions of an action.
256+
//
257+
// Deprecated: use Versions() instead.
258+
func (m *ActionManager) ListVersions(id string, opts ...RequestOption) (c *ActionVersionList, err error) {
259+
return m.Versions(id, opts...)
260+
}
261+
262+
// UpdateBindings of a trigger.
229263
//
230264
// See: https://auth0.com/docs/api/management/v2/#!/Actions/patch_bindings
231265
func (m *ActionManager) UpdateBindings(triggerID string, b []*ActionBinding, opts ...RequestOption) error {
@@ -235,14 +269,21 @@ func (m *ActionManager) UpdateBindings(triggerID string, b []*ActionBinding, opt
235269
return m.Request("PATCH", m.URI("actions", "triggers", triggerID, "bindings"), &bl, opts...)
236270
}
237271

238-
// ListBindings of a trigger
272+
// Bindings lists the bindings of a trigger.
239273
//
240274
// See: https://auth0.com/docs/api/management/v2/#!/Actions/get_bindings
241-
func (m *ActionManager) ListBindings(triggerID string, opts ...RequestOption) (bl *ActionBindingList, err error) {
275+
func (m *ActionManager) Bindings(triggerID string, opts ...RequestOption) (bl *ActionBindingList, err error) {
242276
err = m.Request("GET", m.URI("actions", "triggers", triggerID, "bindings"), &bl, applyActionsListDefaults(opts))
243277
return
244278
}
245279

280+
// ListBindings lists the bindings of a trigger.
281+
//
282+
// Deprecated: use Bindings() instead.
283+
func (m *ActionManager) ListBindings(triggerID string, opts ...RequestOption) (bl *ActionBindingList, err error) {
284+
return m.Bindings(triggerID, opts...)
285+
}
286+
246287
// Deploy an action
247288
//
248289
// See: https://auth0.com/docs/api/management/v2/#!/Actions/post_deploy_action
@@ -263,17 +304,24 @@ func (m *ActionManager) DeployVersion(id string, versionId string, opts ...Reque
263304
//
264305
// See: https://auth0.com/docs/api/management/v2/#!/Actions/post_test_action
265306
func (m *ActionManager) Test(id string, payload *ActionTestPayload, opts ...RequestOption) (err error) {
266-
r := &ActionTestRequest{
307+
r := &actionTestRequest{
267308
Payload: payload,
268309
}
269310
err = m.Request("POST", m.URI("actions", "actions", id, "test"), &r, opts...)
270311
return
271312
}
272313

273-
// ReadExecution of an action
314+
// Execution retrieves the details of an action execution
274315
//
275316
// See: https://auth0.com/docs/api/management/v2/#!/Actions/get_execution
276-
func (m *ActionManager) ReadExecution(executionId string, opts ...RequestOption) (v *ActionExecution, err error) {
317+
func (m *ActionManager) Execution(executionId string, opts ...RequestOption) (v *ActionExecution, err error) {
277318
err = m.Request("GET", m.URI("actions", "executions", executionId), &v, opts...)
278319
return
279320
}
321+
322+
// ReadExecution retrieves the details of an action execution
323+
//
324+
// Deprecated: use Execution() instead
325+
func (m *ActionManager) ReadExecution(executionId string, opts ...RequestOption) (v *ActionExecution, err error) {
326+
return m.Execution(executionId, opts...)
327+
}

management/actions_test.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package management
22

33
import (
44
"errors"
5-
"gopkg.in/auth0.v5"
65
"testing"
76
"time"
7+
8+
"gopkg.in/auth0.v5"
89
)
910

1011
func ensureActionBuilt(a *Action) (err error) {
@@ -32,23 +33,33 @@ func TestActions(t *testing.T) {
3233
r := &Action{
3334
Name: auth0.String("test-action"),
3435
Code: auth0.String("exports.onExecutePostLogin = async (event, api) =\u003e {}"),
35-
SupportedTriggers: []ActionTrigger{
36-
{ID: auth0.String(ActionTriggerPostLogin), Version: auth0.String("v2")},
36+
SupportedTriggers: []*ActionTrigger{
37+
{
38+
ID: auth0.String(ActionTriggerPostLogin),
39+
Version: auth0.String("v2"),
40+
},
3741
},
38-
Dependencies: []ActionDependency{
39-
{Name: auth0.String("lodash"), Version: auth0.String("4.0.0"), RegistryURL: auth0.String("https://www.npmjs.com/package/lodash")},
42+
Dependencies: []*ActionDependency{
43+
{
44+
Name: auth0.String("lodash"),
45+
Version: auth0.String("4.0.0"),
46+
RegistryURL: auth0.String("https://www.npmjs.com/package/lodash"),
47+
},
4048
},
41-
Secrets: []ActionSecret{
42-
{Name: auth0.String("mySecretName"), Value: auth0.String("mySecretValue")},
49+
Secrets: []*ActionSecret{
50+
{
51+
Name: auth0.String("mySecretName"),
52+
Value: auth0.String("mySecretValue"),
53+
},
4354
},
4455
}
4556

4657
var err error
4758
var v *ActionVersion
4859
var vl *ActionVersionList
4960

50-
t.Run("ListTriggers", func(t *testing.T) {
51-
l, err := m.Action.ListTriggers()
61+
t.Run("Triggers", func(t *testing.T) {
62+
l, err := m.Action.Triggers()
5263
if err != nil {
5364
t.Error(err)
5465
}
@@ -119,16 +130,16 @@ func TestActions(t *testing.T) {
119130
t.Logf("%v\n", v)
120131
})
121132

122-
t.Run("ReadVersion", func(t *testing.T) {
123-
v, err := m.Action.ReadVersion(r.GetID(), v.GetID())
133+
t.Run("Version", func(t *testing.T) {
134+
v, err := m.Action.Version(r.GetID(), v.GetID())
124135
if err != nil {
125136
t.Error(err)
126137
}
127138
t.Logf("%v\n", v)
128139
})
129140

130-
t.Run("ListVersions", func(t *testing.T) {
131-
vl, err = m.Action.ListVersions(r.GetID())
141+
t.Run("Versions", func(t *testing.T) {
142+
vl, err = m.Action.Versions(r.GetID())
132143
if err != nil {
133144
t.Error(err)
134145
}
@@ -160,8 +171,8 @@ func TestActions(t *testing.T) {
160171
t.Logf("%v\n", b)
161172
})
162173

163-
t.Run("ListBindings", func(t *testing.T) {
164-
bl, err := m.Action.ListBindings(ActionTriggerPostLogin)
174+
t.Run("Bindings", func(t *testing.T) {
175+
bl, err := m.Action.Bindings(ActionTriggerPostLogin)
165176
if err != nil {
166177
t.Fatal(err)
167178
}
@@ -185,8 +196,8 @@ func TestActions(t *testing.T) {
185196
t.Logf("%v\n", p)
186197
})
187198

188-
t.Run("ReadExecution", func(t *testing.T) {
189-
_, err := m.Action.ReadExecution("M9IqRp9wQLaYNrSwz6YPTTIwMjEwNDA0")
199+
t.Run("Execution", func(t *testing.T) {
200+
_, err := m.Action.Execution("M9IqRp9wQLaYNrSwz6YPTTIwMjEwNDA0")
190201
if err != nil {
191202
mgmtError, _ := err.(*managementError)
192203
if mgmtError.StatusCode != 404 {

management/management.gen.go

Lines changed: 8 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)