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

DXCDT-218: Allow empty fields through pointers #112

Closed
wants to merge 2 commits into from
Closed
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
36 changes: 18 additions & 18 deletions management/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ActionTrigger struct {

// ActionTriggerList is a list of ActionTriggers.
type ActionTriggerList struct {
Triggers []*ActionTrigger `json:"triggers"`
Triggers *[]ActionTrigger `json:"triggers"`
}

// ActionDependency is used to allow the use of packages from the npm registry.
Expand Down Expand Up @@ -74,25 +74,25 @@ type Action struct {
// ID of the action
ID *string `json:"id,omitempty"`
// The name of an action
Name *string `json:"name"`
Name *string `json:"name,omitempty"`
// List of triggers that this action supports. At this time, an action can
// only target a single trigger at a time.
SupportedTriggers []*ActionTrigger `json:"supported_triggers"`
SupportedTriggers *[]ActionTrigger `json:"supported_triggers,omitempty"`
// The source code of the action.
Code *string `json:"code,omitempty"`
// List of third party npm modules, and their versions, that this action
// depends on.
Dependencies []*ActionDependency `json:"dependencies,omitempty"`
Dependencies *[]ActionDependency `json:"dependencies,omitempty"`
// The Node runtime. For example `node16`, defaults to `node12`
Runtime *string `json:"runtime,omitempty"`
// List of secrets that are included in an action or a version of an action.
Secrets []*ActionSecret `json:"secrets,omitempty"`
Secrets *[]ActionSecret `json:"secrets,omitempty"`
// Version of the action that is currently deployed.
DeployedVersion *ActionVersion `json:"deployed_version,omitempty"`
// The build status of this action.
Status *string `json:"status,omitempty"`
// True if all of an Action's contents have been deployed.
AllChangesDeployed bool `json:"all_changes_deployed,omitempty"`
AllChangesDeployed *bool `json:"all_changes_deployed,omitempty"`
// The time when this action was built successfully.
BuiltAt *time.Time `json:"built_at,omitempty"`
// The time when this action was created.
Expand All @@ -104,7 +104,7 @@ type Action struct {
// ActionList is a list of Actions.
type ActionList struct {
List
Actions []*Action `json:"actions"`
Actions *[]Action `json:"actions"`
}

// ActionVersion is used to manage Actions version history.
Expand All @@ -113,12 +113,12 @@ type ActionList struct {
type ActionVersion struct {
ID *string `json:"id,omitempty"`
Code *string `json:"code"`
Dependencies []*ActionDependency `json:"dependencies,omitempty"`
Dependencies *[]ActionDependency `json:"dependencies,omitempty"`
Deployed bool `json:"deployed"`
Status *string `json:"status,omitempty"`
Number int `json:"number,omitempty"`
Number *int `json:"number,omitempty"`

Errors []*ActionVersionError `json:"errors,omitempty"`
Errors *[]ActionVersionError `json:"errors,omitempty"`
Action *Action `json:"action,omitempty"`

BuiltAt *time.Time `json:"built_at,omitempty"`
Expand All @@ -129,7 +129,7 @@ type ActionVersion struct {
// ActionVersionList is a list of ActionVersions.
type ActionVersionList struct {
List
Versions []*ActionVersion `json:"versions"`
Versions []ActionVersion `json:"versions"`
}

const (
Expand All @@ -154,7 +154,7 @@ type ActionBinding struct {

Ref *ActionBindingReference `json:"ref,omitempty"`
Action *Action `json:"action,omitempty"`
Secrets []*ActionSecret `json:"secrets,omitempty"`
Secrets *[]ActionSecret `json:"secrets,omitempty"`

CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Expand All @@ -163,11 +163,11 @@ type ActionBinding struct {
// ActionBindingList is a list of ActionBindings.
type ActionBindingList struct {
List
Bindings []*ActionBinding `json:"bindings"`
Bindings *[]ActionBinding `json:"bindings"`
}

type actionBindingsPerTrigger struct {
Bindings []*ActionBinding `json:"bindings"`
Bindings *[]ActionBinding `json:"bindings"`
}

// ActionTestPayload is used for testing Actions prior to being deployed.
Expand All @@ -181,8 +181,8 @@ type actionTestRequest struct {

// ActionExecutionResult holds the results of an ActionExecution.
type ActionExecutionResult struct {
ActionName *string `json:"action_name,omitempty"`
Error map[string]interface{} `json:"error,omitempty"`
ActionName *string `json:"action_name,omitempty"`
Error *map[string]interface{} `json:"error,omitempty"`

StartedAt *time.Time `json:"started_at,omitempty"`
EndedAt *time.Time `json:"ended_at,omitempty"`
Expand All @@ -194,7 +194,7 @@ type ActionExecution struct {
ID *string `json:"id"`
TriggerID *string `json:"trigger_id"`
Status *string `json:"status"`
Results []*ActionExecutionResult `json:"results"`
Results *[]ActionExecutionResult `json:"results"`

CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
Expand Down Expand Up @@ -282,7 +282,7 @@ func (m *ActionManager) Versions(id string, opts ...RequestOption) (c *ActionVer
// UpdateBindings of a trigger.
//
// See: https://auth0.com/docs/api/management/v2/#!/Actions/patch_bindings
func (m *ActionManager) UpdateBindings(triggerID string, b []*ActionBinding, opts ...RequestOption) error {
func (m *ActionManager) UpdateBindings(triggerID string, b *[]ActionBinding, opts ...RequestOption) error {
bl := &actionBindingsPerTrigger{
Bindings: b,
}
Expand Down
27 changes: 14 additions & 13 deletions management/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ func TestActionManager_Create(t *testing.T) {
expectedAction := &Action{
Name: auth0.Stringf("Test Action (%s)", time.Now().Format(time.StampMilli)),
Code: auth0.String("exports.onExecutePostLogin = async (event, api) =\u003e {}"),
SupportedTriggers: []*ActionTrigger{
SupportedTriggers: &[]ActionTrigger{
{
ID: auth0.String(ActionTriggerPostLogin),
Version: auth0.String("v2"),
},
},
Dependencies: []*ActionDependency{
Dependencies: &[]ActionDependency{
{
Name: auth0.String("lodash"),
Version: auth0.String("4.0.0"),
RegistryURL: auth0.String("https://www.npmjs.com/package/lodash"),
},
},
Secrets: []*ActionSecret{
Secrets: &[]ActionSecret{
{
Name: auth0.String("mySecretName"),
Value: auth0.String("mySecretValue"),
Expand Down Expand Up @@ -103,7 +103,8 @@ func TestActionManager_List(t *testing.T) {
actionList, err := m.Action.List(Parameter("actionName", expectedAction.GetName()))

assert.NoError(t, err)
assert.Equal(t, expectedAction.GetID(), actionList.Actions[0].GetID())

assert.Equal(t, expectedAction.GetID(), actionList.GetActions()[0].GetID())
}

func TestActionManager_Triggers(t *testing.T) {
Expand Down Expand Up @@ -181,11 +182,11 @@ func TestActionManager_Bindings(t *testing.T) {
_, err := m.Action.Deploy(action.GetID())
require.NoError(t, err)

emptyBinding := make([]*ActionBinding, 0)
err = m.Action.UpdateBindings(ActionTriggerPostLogin, emptyBinding)
emptyBinding := make([]ActionBinding, 0)
err = m.Action.UpdateBindings(ActionTriggerPostLogin, &emptyBinding)
assert.NoError(t, err)

binding := []*ActionBinding{
binding := []ActionBinding{
{
Ref: &ActionBindingReference{
Type: auth0.String(ActionBindingReferenceByName),
Expand All @@ -195,16 +196,16 @@ func TestActionManager_Bindings(t *testing.T) {
},
}

err = m.Action.UpdateBindings(ActionTriggerPostLogin, binding)
err = m.Action.UpdateBindings(ActionTriggerPostLogin, &binding)
assert.NoError(t, err)

bindingList, err := m.Action.Bindings(ActionTriggerPostLogin)

assert.NoError(t, err)
assert.Len(t, bindingList.Bindings, 1)
assert.Len(t, bindingList.GetBindings(), 1)

t.Cleanup(func() {
err = m.Action.UpdateBindings(ActionTriggerPostLogin, emptyBinding)
err = m.Action.UpdateBindings(ActionTriggerPostLogin, &emptyBinding)
assert.NoError(t, err)
})
}
Expand Down Expand Up @@ -255,20 +256,20 @@ func givenAnAction(t *testing.T) *Action {
action := &Action{
Name: auth0.Stringf("Test Action (%s)", time.Now().Format(time.StampMilli)),
Code: auth0.String("exports.onExecutePostLogin = async (event, api) =\u003e {}"),
SupportedTriggers: []*ActionTrigger{
SupportedTriggers: &[]ActionTrigger{
{
ID: auth0.String(ActionTriggerPostLogin),
Version: auth0.String("v2"),
},
},
Dependencies: []*ActionDependency{
Dependencies: &[]ActionDependency{
{
Name: auth0.String("lodash"),
Version: auth0.String("4.0.0"),
RegistryURL: auth0.String("https://www.npmjs.com/package/lodash"),
},
},
Secrets: []*ActionSecret{
Secrets: &[]ActionSecret{
{
Name: auth0.String("mySecretName"),
Value: auth0.String("mySecretValue"),
Expand Down
Loading