Skip to content

Commit

Permalink
Merge pull request #7 from caring/AOS-62
Browse files Browse the repository at this point in the history
AOS-62
  • Loading branch information
odv-caring authored Oct 11, 2021
2 parents bd73c7f + 6bd1f66 commit 0f3bb1b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac // indirect
github.com/kevinburke/bump_version v0.0.0-20210302192000-902db8f7bcaa // indirect
github.com/kevinburke/differ v0.0.0-20210601202324-818729efca6c // indirect
github.com/kevinburke/go-types v0.0.0-20201208005256-aee49f568a20
github.com/kevinburke/go.uuid v1.2.0 // indirect
github.com/kevinburke/handlers v0.0.0-20210518180840-51ec5c83f704
github.com/kevinburke/rest v0.0.0-20210506044642-5611499aa33c
github.com/kevinburke/write_mailmap v0.0.0-20180427174204-754cdd25e871 // indirect
github.com/matryer/is v1.4.0
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac h1:n1DqxAo4oWPMvH1+v+DLYlMCecgumhhgnxAPdqDIFHI=
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o=
github.com/kevinburke/bump_version v0.0.0-20210302192000-902db8f7bcaa h1:LfILGuEuU8ZY36uE6ypUbW7okpFvdf6GtQzl3yCUyaA=
github.com/kevinburke/bump_version v0.0.0-20210302192000-902db8f7bcaa/go.mod h1:6oDzOLM43f86c4+Q0gC3FJ05wil+azlUfsauV5I4FGs=
github.com/kevinburke/differ v0.0.0-20210601202324-818729efca6c h1:ym3EjqHyXWGbxCzG4Y+9RfheMU7PjYagX2E4JyDY6WE=
github.com/kevinburke/differ v0.0.0-20210601202324-818729efca6c/go.mod h1:I7eBHoOOU9N76qKli6iiqWZqh7iyxraK7SgR+kbDgW4=
github.com/kevinburke/go-types v0.0.0-20201208005256-aee49f568a20 h1:Tux1t20gPWp4zkjCCdv2rLAwp+T3jCEROsEuvXp50FI=
Expand All @@ -23,6 +25,8 @@ github.com/kevinburke/handlers v0.0.0-20210518180840-51ec5c83f704 h1:MYSZJtrEcm4
github.com/kevinburke/handlers v0.0.0-20210518180840-51ec5c83f704/go.mod h1:wOuHsUtSfRb2irqcjH8V3/hrPZq9wKy+NxX+hbfY0uI=
github.com/kevinburke/rest v0.0.0-20210506044642-5611499aa33c h1:hnbwWED5rIu+UaMkLR3JtnscMVGqp35lfzQwLuZAAUY=
github.com/kevinburke/rest v0.0.0-20210506044642-5611499aa33c/go.mod h1:pD+iEcdAGVXld5foVN4e24zb/6fnb60tgZPZ3P/3T/I=
github.com/kevinburke/write_mailmap v0.0.0-20180427174204-754cdd25e871 h1:YAZ3mLsX6zKcYnJiGHi7nuOtopod/Ob74lCA8Ak/TGo=
github.com/kevinburke/write_mailmap v0.0.0-20180427174204-754cdd25e871/go.mod h1:+ihufSEPx0Y279fkMJarLnP+GYtpwg5lodhkrZb1ZF0=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
37 changes: 37 additions & 0 deletions token/access_token_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const (
conversationsGrant = "rtc"
voiceGrant = "voice"
videoGrant = "video"
taskrouterGrant = "task_router"
keyWorkspaceSid = "workspace_sid"
keyWorkerSid = "worker_sid"
keyRole = "role"
keyServiceSid = "service_sid"
keyEndpointId = "endpoint_id"
keyDepRoleSide = "deployment_role_sid"
Expand All @@ -28,6 +32,39 @@ type Grant interface {
Key() string
}

// TaskrouterGrant is a grant for accessing Taskrouter
type TaskrouterGrant struct {
workspaceSid string
workerSid string
role string
}

func NewTaskRouterGrant(workspaceSid, workerSid, role string) *TaskrouterGrant {
return &TaskrouterGrant{
workspaceSid: workspaceSid,
workerSid: workerSid,
role: role,
}
}

func (gr *TaskrouterGrant) ToPayload() map[string]interface{} {
grant := make(map[string]interface{})
if len(gr.workspaceSid) > 0 {
grant[keyWorkspaceSid] = gr.workspaceSid
}
if len(gr.workerSid) > 0 {
grant[keyWorkerSid] = gr.workerSid
}
if len(gr.role) > 0 {
grant[keyRole] = gr.role
}
return grant
}

func (gr *TaskrouterGrant) Key() string {
return taskrouterGrant
}

// IPMessageGrant is a grant for accessing Twilio IP Messaging
type IPMessageGrant struct {
serviceSid string
Expand Down

0 comments on commit 0f3bb1b

Please sign in to comment.