Skip to content

Commit

Permalink
feat: Specify how to authenticate outbound IntervalActions
Browse files Browse the repository at this point in the history
Outbound HTTP requests must be authenticated if they call
EdgeX services (for example, event aging).  This commit
extends the model to allow users to specify the AuthMethod
of outbound HTTP requests.

Signed-off-by: Bryon Nevis <bryon.nevis@intel.com>
  • Loading branch information
bnevis-i committed Mar 6, 2023
1 parent 9073418 commit b2c2176
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dtos/intervalaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type IntervalAction struct {
Content string `json:"content,omitempty"`
ContentType string `json:"contentType,omitempty"`
AdminState string `json:"adminState" validate:"oneof='LOCKED' 'UNLOCKED'"`
AuthMethod string `json:"authMethod" validate:"oneof='' 'NONE' 'JWT'"`
}

// NewIntervalAction creates intervalAction DTO with required fields
Expand All @@ -42,6 +43,7 @@ type UpdateIntervalAction struct {
ContentType *string `json:"contentType"`
Address *Address `json:"address"`
AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"`
AuthMethod *string `json:"authMethod" validate:"omitempty,oneof='' 'NONE' 'JWT'"`
}

// NewUpdateIntervalAction creates updateIntervalAction DTO with required field
Expand All @@ -59,6 +61,7 @@ func ToIntervalActionModel(dto IntervalAction) models.IntervalAction {
model.ContentType = dto.ContentType
model.Address = ToAddressModel(dto.Address)
model.AdminState = models.AdminState(dto.AdminState)
model.AuthMethod = models.AuthMethod(dto.AuthMethod)
return model
}

Expand All @@ -73,5 +76,6 @@ func FromIntervalActionModelToDTO(model models.IntervalAction) IntervalAction {
dto.ContentType = model.ContentType
dto.Address = FromAddressModelToDTO(model.Address)
dto.AdminState = string(model.AdminState)
dto.AuthMethod = string(model.AuthMethod)
return dto
}
6 changes: 6 additions & 0 deletions models/intervalaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"github.com/edgexfoundry/go-mod-core-contracts/v3/errors"
)

// AuthMethod controls the authentication method to be applied to outbound http requests for interval actions
type AuthMethod string

// IntervalAction and its properties are defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/support-scheduler/2.x#/IntervalAction
// Model fields are same as the DTOs documented by this swagger. Exceptions, if any, are noted below.
Expand All @@ -23,6 +26,7 @@ type IntervalAction struct {
ContentType string
Address Address
AdminState AdminState
AuthMethod AuthMethod
}

func (intervalAction *IntervalAction) UnmarshalJSON(b []byte) error {
Expand All @@ -35,6 +39,7 @@ func (intervalAction *IntervalAction) UnmarshalJSON(b []byte) error {
ContentType string
Address interface{}
AdminState AdminState
AuthMethod AuthMethod
}
if err := json.Unmarshal(b, &alias); err != nil {
return errors.NewCommonEdgeX(errors.KindContractInvalid, "Failed to unmarshal intervalAction.", err)
Expand All @@ -53,6 +58,7 @@ func (intervalAction *IntervalAction) UnmarshalJSON(b []byte) error {
ContentType: alias.ContentType,
Address: address,
AdminState: alias.AdminState,
AuthMethod: alias.AuthMethod,
}
return nil
}

0 comments on commit b2c2176

Please sign in to comment.