2018-05-16 18:59:35 +00:00
package main
import (
"context"
"os"
2019-01-08 00:37:16 +00:00
platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/cmd/influx/internal"
"github.com/influxdata/influxdb/http"
2018-05-16 18:59:35 +00:00
"github.com/spf13/cobra"
)
var authorizationCmd = & cobra . Command {
Use : "auth" ,
Aliases : [ ] string { "authorization" } ,
Short : "Authorization management commands" ,
Run : func ( cmd * cobra . Command , args [ ] string ) {
cmd . Usage ( )
} ,
}
// AuthorizationCreateFlags are command line args used when creating a authorization
type AuthorizationCreateFlags struct {
user string
2019-01-10 21:21:59 +00:00
org string
2018-05-16 18:59:35 +00:00
2019-01-10 21:21:59 +00:00
writeUserPermission bool
readUserPermission bool
writeBucketsPermission bool
readBucketsPermission bool
2018-05-16 18:59:35 +00:00
writeBucketPermissions [ ] string
2019-01-10 21:21:59 +00:00
readBucketPermissions [ ] string
2019-01-10 23:38:07 +00:00
writeTasksPermission bool
readTasksPermission bool
writeTelegrafsPermission bool
readTelegrafsPermission bool
writeOrganizationsPermission bool
readOrganizationsPermission bool
writeDashboardsPermission bool
readDashboardsPermission bool
2018-05-16 18:59:35 +00:00
}
var authorizationCreateFlags AuthorizationCreateFlags
func init ( ) {
authorizationCreateCmd := & cobra . Command {
Use : "create" ,
Short : "Create authorization" ,
2019-01-22 18:19:26 +00:00
RunE : wrapCheckSetup ( authorizationCreateF ) ,
2018-05-16 18:59:35 +00:00
}
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . StringVarP ( & authorizationCreateFlags . org , "org" , "o" , "" , "The organization name (required)" )
2019-01-10 21:21:59 +00:00
authorizationCreateCmd . MarkFlagRequired ( "org" )
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . StringVarP ( & authorizationCreateFlags . user , "user" , "u" , "" , "The user name" )
2018-05-16 18:59:35 +00:00
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . writeUserPermission , "write-user" , "" , false , "Grants the permission to perform mutative actions against organization users" )
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . readUserPermission , "read-user" , "" , false , "Grants the permission to perform read actions against organization users" )
2019-01-10 21:21:59 +00:00
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . writeBucketsPermission , "write-buckets" , "" , false , "Grants the permission to perform mutative actions against organization buckets" )
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . readBucketsPermission , "read-buckets" , "" , false , "Grants the permission to perform read actions against organization buckets" )
2018-05-16 18:59:35 +00:00
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . StringArrayVarP ( & authorizationCreateFlags . writeBucketPermissions , "write-bucket" , "" , [ ] string { } , "The bucket id" )
authorizationCreateCmd . Flags ( ) . StringArrayVarP ( & authorizationCreateFlags . readBucketPermissions , "read-bucket" , "" , [ ] string { } , "The bucket id" )
2018-05-16 18:59:35 +00:00
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . writeTasksPermission , "write-tasks" , "" , false , "Grants the permission to create tasks" )
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . readTasksPermission , "read-tasks" , "" , false , "Grants the permission to read tasks" )
2019-01-10 23:38:07 +00:00
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . writeTelegrafsPermission , "write-telegrafs" , "" , false , "Grants the permission to create telegraf configs" )
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . readTelegrafsPermission , "read-telegrafs" , "" , false , "Grants the permission to read telegraf configs" )
2019-01-10 23:38:07 +00:00
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . writeOrganizationsPermission , "write-orgs" , "" , false , "Grants the permission to create organizations" )
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . readOrganizationsPermission , "read-orgs" , "" , false , "Grants the permission to read organizations" )
2019-01-10 23:38:07 +00:00
2019-01-14 18:54:53 +00:00
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . writeDashboardsPermission , "write-dashboards" , "" , false , "Grants the permission to create dashboards" )
authorizationCreateCmd . Flags ( ) . BoolVarP ( & authorizationCreateFlags . readDashboardsPermission , "read-dashboards" , "" , false , "Grants the permission to read dashboards" )
2019-01-10 23:38:07 +00:00
2018-05-16 18:59:35 +00:00
authorizationCmd . AddCommand ( authorizationCreateCmd )
}
2018-12-28 23:02:19 +00:00
func authorizationCreateF ( cmd * cobra . Command , args [ ] string ) error {
2018-05-16 18:59:35 +00:00
var permissions [ ] platform . Permission
2019-01-10 21:21:59 +00:00
orgSvc , err := newOrganizationService ( flags )
if err != nil {
return err
}
ctx := context . Background ( )
orgFilter := platform . OrganizationFilter { Name : & authorizationCreateFlags . org }
o , err := orgSvc . FindOrganization ( ctx , orgFilter )
if err != nil {
return err
}
if authorizationCreateFlags . writeUserPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . WriteAction , platform . UsersResourceType , o . ID )
2019-01-10 21:21:59 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . readUserPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . ReadAction , platform . UsersResourceType , o . ID )
2019-01-10 21:21:59 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . writeBucketsPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . WriteAction , platform . BucketsResourceType , o . ID )
2018-12-28 23:02:19 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
2018-05-16 18:59:35 +00:00
}
2018-12-28 23:02:19 +00:00
2019-01-10 21:21:59 +00:00
if authorizationCreateFlags . readBucketsPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . ReadAction , platform . BucketsResourceType , o . ID )
2018-12-28 23:02:19 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
2018-05-16 18:59:35 +00:00
}
for _ , p := range authorizationCreateFlags . writeBucketPermissions {
var id platform . ID
if err := id . DecodeFromString ( p ) ; err != nil {
2018-12-28 23:02:19 +00:00
return err
}
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermissionAtID ( id , platform . WriteAction , platform . BucketsResourceType , o . ID )
2018-12-28 23:02:19 +00:00
if err != nil {
return err
2018-05-16 18:59:35 +00:00
}
2018-12-28 23:02:19 +00:00
permissions = append ( permissions , * p )
2018-05-16 18:59:35 +00:00
}
2018-12-28 23:02:19 +00:00
2018-05-16 18:59:35 +00:00
for _ , p := range authorizationCreateFlags . readBucketPermissions {
var id platform . ID
if err := id . DecodeFromString ( p ) ; err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
2018-12-28 23:02:19 +00:00
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermissionAtID ( id , platform . ReadAction , platform . BucketsResourceType , o . ID )
2018-12-28 23:02:19 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
2018-05-16 18:59:35 +00:00
}
2019-01-10 23:38:07 +00:00
if authorizationCreateFlags . writeTasksPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . WriteAction , platform . TasksResourceType , o . ID )
2019-01-10 23:38:07 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . readTasksPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . ReadAction , platform . TasksResourceType , o . ID )
2019-01-10 23:38:07 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . writeTelegrafsPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . WriteAction , platform . TelegrafsResourceType , o . ID )
2019-01-10 23:38:07 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . readTelegrafsPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . ReadAction , platform . TelegrafsResourceType , o . ID )
2019-01-10 23:38:07 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . writeOrganizationsPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . WriteAction , platform . OrgsResourceType , o . ID )
2019-01-10 23:38:07 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . readOrganizationsPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . ReadAction , platform . OrgsResourceType , o . ID )
2019-01-10 23:38:07 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . writeDashboardsPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . WriteAction , platform . DashboardsResourceType , o . ID )
2019-01-10 23:38:07 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
if authorizationCreateFlags . readDashboardsPermission {
2019-01-15 16:09:58 +00:00
p , err := platform . NewPermission ( platform . ReadAction , platform . DashboardsResourceType , o . ID )
2019-01-10 23:38:07 +00:00
if err != nil {
return err
}
permissions = append ( permissions , * p )
}
2018-05-16 18:59:35 +00:00
authorization := & platform . Authorization {
Permissions : permissions ,
2019-01-10 21:21:59 +00:00
OrgID : o . ID ,
2018-05-16 18:59:35 +00:00
}
2018-10-25 19:28:33 +00:00
s , err := newAuthorizationService ( flags )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
2018-10-25 19:28:33 +00:00
if err := s . CreateAuthorization ( context . Background ( ) , authorization ) ; err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
w := internal . NewTabWriter ( os . Stdout )
w . WriteHeaders (
"ID" ,
"Token" ,
2018-08-28 17:58:38 +00:00
"Status" ,
2018-05-16 18:59:35 +00:00
"UserID" ,
"Permissions" ,
)
ps := [ ] string { }
for _ , p := range authorization . Permissions {
ps = append ( ps , p . String ( ) )
}
w . Write ( map [ string ] interface { } {
"ID" : authorization . ID . String ( ) ,
"Token" : authorization . Token ,
2018-08-28 17:58:38 +00:00
"Status" : authorization . Status ,
2018-05-16 18:59:35 +00:00
"UserID" : authorization . UserID . String ( ) ,
"Permissions" : ps ,
} )
2018-12-28 23:02:19 +00:00
2018-05-16 18:59:35 +00:00
w . Flush ( )
2018-12-28 23:02:19 +00:00
return nil
2018-05-16 18:59:35 +00:00
}
// AuthorizationFindFlags are command line args used when finding a authorization
type AuthorizationFindFlags struct {
user string
userID string
id string
}
var authorizationFindFlags AuthorizationFindFlags
func init ( ) {
authorizationFindCmd := & cobra . Command {
Use : "find" ,
Short : "Find authorization" ,
2019-01-22 18:19:26 +00:00
RunE : wrapCheckSetup ( authorizationFindF ) ,
2018-05-16 18:59:35 +00:00
}
2019-01-14 18:54:53 +00:00
authorizationFindCmd . Flags ( ) . StringVarP ( & authorizationFindFlags . user , "user" , "u" , "" , "The user" )
authorizationFindCmd . Flags ( ) . StringVarP ( & authorizationFindFlags . userID , "user-id" , "" , "" , "The user ID" )
authorizationFindCmd . Flags ( ) . StringVarP ( & authorizationFindFlags . id , "id" , "i" , "" , "The authorization ID" )
2018-05-16 18:59:35 +00:00
authorizationCmd . AddCommand ( authorizationFindCmd )
}
2018-10-25 19:28:33 +00:00
func newAuthorizationService ( f Flags ) ( platform . AuthorizationService , error ) {
if flags . local {
2019-03-28 08:42:38 +00:00
return newLocalKVService ( )
2018-10-25 19:28:33 +00:00
}
return & http . AuthorizationService {
2018-05-16 18:59:35 +00:00
Addr : flags . host ,
Token : flags . token ,
2018-10-25 19:28:33 +00:00
} , nil
}
2018-12-28 23:02:19 +00:00
func authorizationFindF ( cmd * cobra . Command , args [ ] string ) error {
2018-10-25 19:28:33 +00:00
s , err := newAuthorizationService ( flags )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
filter := platform . AuthorizationFilter { }
if authorizationFindFlags . id != "" {
2018-07-20 10:24:07 +00:00
fID , err := platform . IDFromString ( authorizationFindFlags . id )
2018-05-16 18:59:35 +00:00
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
2018-07-20 10:24:07 +00:00
filter . ID = fID
2018-05-16 18:59:35 +00:00
}
if authorizationFindFlags . user != "" {
filter . User = & authorizationFindFlags . user
}
if authorizationFindFlags . userID != "" {
2018-07-20 10:24:07 +00:00
uID , err := platform . IDFromString ( authorizationFindFlags . userID )
2018-05-16 18:59:35 +00:00
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
2018-07-20 10:24:07 +00:00
filter . UserID = uID
2018-05-16 18:59:35 +00:00
}
authorizations , _ , err := s . FindAuthorizations ( context . Background ( ) , filter )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
w := internal . NewTabWriter ( os . Stdout )
w . WriteHeaders (
"ID" ,
"Token" ,
2018-08-28 17:58:38 +00:00
"Status" ,
2018-05-16 18:59:35 +00:00
"User" ,
"UserID" ,
"Permissions" ,
)
for _ , a := range authorizations {
var permissions [ ] string
for _ , p := range a . Permissions {
permissions = append ( permissions , p . String ( ) )
}
w . Write ( map [ string ] interface { } {
"ID" : a . ID ,
"Token" : a . Token ,
2018-08-28 17:58:38 +00:00
"Status" : a . Status ,
2018-05-16 18:59:35 +00:00
"UserID" : a . UserID . String ( ) ,
"Permissions" : permissions ,
} )
}
2018-12-28 23:02:19 +00:00
2018-05-16 18:59:35 +00:00
w . Flush ( )
2018-12-28 23:02:19 +00:00
return nil
2018-05-16 18:59:35 +00:00
}
// AuthorizationDeleteFlags are command line args used when deleting a authorization
type AuthorizationDeleteFlags struct {
id string
}
var authorizationDeleteFlags AuthorizationDeleteFlags
func init ( ) {
authorizationDeleteCmd := & cobra . Command {
Use : "delete" ,
Short : "Delete authorization" ,
2019-01-22 18:19:26 +00:00
RunE : wrapCheckSetup ( authorizationDeleteF ) ,
2018-05-16 18:59:35 +00:00
}
2019-01-14 18:54:53 +00:00
authorizationDeleteCmd . Flags ( ) . StringVarP ( & authorizationDeleteFlags . id , "id" , "i" , "" , "The authorization ID (required)" )
2018-05-16 18:59:35 +00:00
authorizationDeleteCmd . MarkFlagRequired ( "id" )
authorizationCmd . AddCommand ( authorizationDeleteCmd )
}
2018-12-28 23:02:19 +00:00
func authorizationDeleteF ( cmd * cobra . Command , args [ ] string ) error {
2018-10-25 19:28:33 +00:00
s , err := newAuthorizationService ( flags )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
2018-07-20 10:24:07 +00:00
id , err := platform . IDFromString ( authorizationDeleteFlags . id )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
ctx := context . TODO ( )
2018-07-20 10:24:07 +00:00
a , err := s . FindAuthorizationByID ( ctx , * id )
2018-05-16 18:59:35 +00:00
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
2018-07-20 10:24:07 +00:00
if err := s . DeleteAuthorization ( context . Background ( ) , * id ) ; err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-05-16 18:59:35 +00:00
}
w := internal . NewTabWriter ( os . Stdout )
w . WriteHeaders (
"ID" ,
"Token" ,
"User" ,
"UserID" ,
"Permissions" ,
"Deleted" ,
)
ps := [ ] string { }
for _ , p := range a . Permissions {
ps = append ( ps , p . String ( ) )
}
w . Write ( map [ string ] interface { } {
"ID" : a . ID . String ( ) ,
"Token" : a . Token ,
"UserID" : a . UserID . String ( ) ,
"Permissions" : ps ,
"Deleted" : true ,
} )
2018-12-28 23:02:19 +00:00
2018-05-16 18:59:35 +00:00
w . Flush ( )
2018-12-28 23:02:19 +00:00
return nil
2018-05-16 18:59:35 +00:00
}
2018-08-27 19:29:50 +00:00
2018-08-28 17:58:38 +00:00
// AuthorizationActiveFlags are command line args used when enabling an authorization
type AuthorizationActiveFlags struct {
2018-08-27 19:29:50 +00:00
id string
}
2018-08-28 17:58:38 +00:00
var authorizationActiveFlags AuthorizationActiveFlags
2018-08-27 19:29:50 +00:00
func init ( ) {
2018-08-28 17:58:38 +00:00
authorizationActiveCmd := & cobra . Command {
Use : "active" ,
2019-01-14 18:54:53 +00:00
Short : "Active authorization" ,
2019-01-22 18:19:26 +00:00
RunE : wrapCheckSetup ( authorizationActiveF ) ,
2018-08-27 19:29:50 +00:00
}
2019-01-14 18:54:53 +00:00
authorizationActiveCmd . Flags ( ) . StringVarP ( & authorizationActiveFlags . id , "id" , "i" , "" , "The authorization ID (required)" )
2018-08-28 17:58:38 +00:00
authorizationActiveCmd . MarkFlagRequired ( "id" )
2018-08-27 19:29:50 +00:00
2018-08-28 17:58:38 +00:00
authorizationCmd . AddCommand ( authorizationActiveCmd )
2018-08-27 19:29:50 +00:00
}
2018-12-28 23:02:19 +00:00
func authorizationActiveF ( cmd * cobra . Command , args [ ] string ) error {
2018-10-25 19:28:33 +00:00
s , err := newAuthorizationService ( flags )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-08-27 19:29:50 +00:00
}
2018-09-27 11:00:25 +00:00
var id platform . ID
2018-08-28 17:58:38 +00:00
if err := id . DecodeFromString ( authorizationActiveFlags . id ) ; err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-08-27 19:29:50 +00:00
}
ctx := context . TODO ( )
a , err := s . FindAuthorizationByID ( ctx , id )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-08-27 19:29:50 +00:00
}
2019-03-27 19:02:45 +00:00
if err := s . UpdateAuthorization ( context . Background ( ) , id , & platform . AuthorizationUpdate {
Status : platform . Active . Ptr ( ) ,
} ) ; err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-08-27 19:29:50 +00:00
}
w := internal . NewTabWriter ( os . Stdout )
w . WriteHeaders (
"ID" ,
"Token" ,
2018-08-28 17:58:38 +00:00
"Status" ,
2018-08-27 19:29:50 +00:00
"User" ,
"UserID" ,
"Permissions" ,
)
ps := [ ] string { }
for _ , p := range a . Permissions {
ps = append ( ps , p . String ( ) )
}
w . Write ( map [ string ] interface { } {
"ID" : a . ID . String ( ) ,
"Token" : a . Token ,
2018-08-28 17:58:38 +00:00
"Status" : a . Status ,
2018-08-27 19:29:50 +00:00
"UserID" : a . UserID . String ( ) ,
"Permissions" : ps ,
} )
2018-12-28 23:02:19 +00:00
2018-08-27 19:29:50 +00:00
w . Flush ( )
2018-12-28 23:02:19 +00:00
return nil
2018-08-27 19:29:50 +00:00
}
2018-08-28 17:58:38 +00:00
// AuthorizationInactiveFlags are command line args used when disabling an authorization
type AuthorizationInactiveFlags struct {
2018-08-27 19:29:50 +00:00
id string
}
2018-08-28 17:58:38 +00:00
var authorizationInactiveFlags AuthorizationInactiveFlags
2018-08-27 19:29:50 +00:00
func init ( ) {
2018-08-28 17:58:38 +00:00
authorizationInactiveCmd := & cobra . Command {
Use : "inactive" ,
2019-01-14 18:54:53 +00:00
Short : "Inactive authorization" ,
2019-01-22 18:19:26 +00:00
RunE : wrapCheckSetup ( authorizationInactiveF ) ,
2018-08-27 19:29:50 +00:00
}
2019-01-14 18:54:53 +00:00
authorizationInactiveCmd . Flags ( ) . StringVarP ( & authorizationInactiveFlags . id , "id" , "i" , "" , "The authorization ID (required)" )
2018-08-28 17:58:38 +00:00
authorizationInactiveCmd . MarkFlagRequired ( "id" )
2018-08-27 19:29:50 +00:00
2018-08-28 17:58:38 +00:00
authorizationCmd . AddCommand ( authorizationInactiveCmd )
2018-08-27 19:29:50 +00:00
}
2018-12-28 23:02:19 +00:00
func authorizationInactiveF ( cmd * cobra . Command , args [ ] string ) error {
2018-10-25 19:28:33 +00:00
s , err := newAuthorizationService ( flags )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-08-27 19:29:50 +00:00
}
2018-09-27 11:00:25 +00:00
var id platform . ID
2018-08-28 17:58:38 +00:00
if err := id . DecodeFromString ( authorizationInactiveFlags . id ) ; err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-08-27 19:29:50 +00:00
}
ctx := context . TODO ( )
a , err := s . FindAuthorizationByID ( ctx , id )
if err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-08-27 19:29:50 +00:00
}
2019-03-27 19:02:45 +00:00
if err := s . UpdateAuthorization ( context . Background ( ) , id , & platform . AuthorizationUpdate {
Status : platform . Inactive . Ptr ( ) ,
} ) ; err != nil {
2018-12-28 23:02:19 +00:00
return err
2018-08-27 19:29:50 +00:00
}
w := internal . NewTabWriter ( os . Stdout )
w . WriteHeaders (
"ID" ,
"Token" ,
2018-08-28 17:58:38 +00:00
"Status" ,
2018-08-27 19:29:50 +00:00
"User" ,
"UserID" ,
"Permissions" ,
)
ps := [ ] string { }
for _ , p := range a . Permissions {
ps = append ( ps , p . String ( ) )
}
w . Write ( map [ string ] interface { } {
"ID" : a . ID . String ( ) ,
"Token" : a . Token ,
2018-08-28 17:58:38 +00:00
"Status" : a . Status ,
2018-08-27 19:29:50 +00:00
"UserID" : a . UserID . String ( ) ,
"Permissions" : ps ,
} )
2018-12-28 23:02:19 +00:00
2018-08-27 19:29:50 +00:00
w . Flush ( )
2018-12-28 23:02:19 +00:00
return nil
2018-08-27 19:29:50 +00:00
}