diff --git a/go.mod b/go.mod index 8214c64..e1f2bd3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ca733e4..988c62c 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/token/access_token_grant.go b/token/access_token_grant.go index cf43564..509d99c 100644 --- a/token/access_token_grant.go +++ b/token/access_token_grant.go @@ -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" @@ -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