Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
[ttnctl] Add commands to manage components collaborators
Browse files Browse the repository at this point in the history
  • Loading branch information
gomezjdaniel committed Jun 23, 2017
1 parent 77f98c0 commit f92f632
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 26 deletions.
18 changes: 18 additions & 0 deletions ttnctl/cmd/components_collaborators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package cmd

import (
"github.com/spf13/cobra"
)

var componentsCollaboratorsCmd = &cobra.Command{
Use: "collaborators",
Short: "Manage collaborators of a network component.",
Long: `components collaborators can be used to manage the collaborators of a network component.`,
}

func init() {
componentsCmd.AddCommand(componentsCollaboratorsCmd)
}
38 changes: 38 additions & 0 deletions ttnctl/cmd/components_collaborators_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package cmd

import (
ttnlog "github.com/TheThingsNetwork/go-utils/log"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)

var componentsCollaboratorsDeleteCmd = &cobra.Command{
Use: "delete [Type] [ComponentID] [Username]",
Short: "Retracts an user as component collaborator.",
Long: `components collaborators delete can be used to retract users as collaborators.`,
Example: `$ ttnctl components collaborators delete handler ttn-handler-dev gomezjdaniel
INFO Successfully user retracted as component collaborator ComponentID=dev-handler Type=handler Username=gomezjdaniel
`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 3, 3)

account := util.GetAccount(ctx)

if err := account.RetractComponentRights(args[0], args[1], args[2]); err != nil {
ctx.WithError(err).Fatal("Could not retract user as component collaborator")
}

ctx.WithFields(ttnlog.Fields{
"Type": args[0],
"ComponentID": args[1],
"Username": args[2],
}).Info("Successfully user retracted as component collaborator")
},
}

func init() {
componentsCollaboratorsCmd.AddCommand(componentsCollaboratorsDeleteCmd)
}
53 changes: 53 additions & 0 deletions ttnctl/cmd/components_collaborators_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package cmd

import (
ttnlog "github.com/TheThingsNetwork/go-utils/log"
"github.com/TheThingsNetwork/ttn/core/types"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)

var componentsCollaboratorsSetCmd = &cobra.Command{
Use: "set [Type] [ComponentID] [Username]",
Short: "Grant an user with rights over a network component.",
Long: `components collaborators set can be used to add an username as collaborator or edit his rights.`,
Example: `$ ttnctl components collaborators set handler ttn-handler-dev gomezjdaniel --rights='component:settings,component:delete'
INFO Successfully user granted with collaborator rights ComponentID=ttn-dev-handler Type=handler Username=gomezjdaniel
`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 3, 3)

var rights []types.Right
rightsStrings, err := cmd.Flags().GetStringSlice("rights")
if err != nil {
ctx.WithError(err).Fatal("Could not read rights options")
}
if len(rightsStrings) == 0 {
ctx.Fatal("Rights has not been provided through --rights flag")
}

for _, rightString := range rightsStrings {
rights = append(rights, types.Right(rightString))
}

account := util.GetAccount(ctx)

if err := account.GrantComponentRights(args[0], args[1], args[2], rights); err != nil {
ctx.WithError(err).Fatal("Could not grant user with collaborator rights")
}

ctx.WithFields(ttnlog.Fields{
"Type": args[0],
"ComponentID": args[1],
"Username": args[2],
}).Info("Successfully user granted with component rights")
},
}

func init() {
componentsCollaboratorsCmd.AddCommand(componentsCollaboratorsSetCmd)
componentsCollaboratorsSetCmd.Flags().StringSlice("rights", []string{}, "Rights to be granted")
}
13 changes: 13 additions & 0 deletions ttnctl/cmd/components_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ Created: 2016-10-06 09:52:28.766 +0000 UTC
fmt.Printf("Type: %s\n", component.Type)
fmt.Printf("Created: %s\n", component.Created)
fmt.Println()
fmt.Println("Collaborators:")
for _, collaborator := range component.Collaborators {
fmt.Printf(" - Name: %s\n", collaborator.Username)
fmt.Print(" Rights: ")
for i, right := range collaborator.Rights {
if i != 0 {
fmt.Print(", ")
}
fmt.Print(right)
}
fmt.Println()
}
fmt.Println()
},
}

Expand Down
52 changes: 26 additions & 26 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,70 @@
"revisionTime": "2017-03-15T15:57:52Z"
},
{
"checksumSHA1": "4fq6cBb+tonPGxaeHk96H7dKOd4=",
"checksumSHA1": "t0RI2WKlx2C+y/BNqHPrhPcYOPE=",
"path": "github.com/TheThingsNetwork/go-account-lib/account",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "19b357898a9bd97e2524230ada193653c2bcd283",
"revisionTime": "2017-06-23T09:06:20Z"
},
{
"checksumSHA1": "b6pCShOzSh4N9LujOUFzQDzqhz8=",
"path": "github.com/TheThingsNetwork/go-account-lib/auth",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "d1nFTGUlP4sNEf1lelyh6L59mjE=",
"path": "github.com/TheThingsNetwork/go-account-lib/cache",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "8LlsoZGpmrUfqDNDJKU/IJ/x6TM=",
"path": "github.com/TheThingsNetwork/go-account-lib/claims",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "3IiXhWt/UvtK73ANnQVxm0g9uGU=",
"path": "github.com/TheThingsNetwork/go-account-lib/keys",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "6B3ymo3fpzd5+rjQDViPKBiOf+M=",
"path": "github.com/TheThingsNetwork/go-account-lib/oauth",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "z3nvCzyF6t4c68evbgXRvB+O1ws=",
"checksumSHA1": "KrmYdSt7rX8Pwk2f8Fp1z/js8QQ=",
"path": "github.com/TheThingsNetwork/go-account-lib/rights",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "19b357898a9bd97e2524230ada193653c2bcd283",
"revisionTime": "2017-06-23T09:06:20Z"
},
{
"checksumSHA1": "SvUkgVuVVVssqpXbE8OfeWCm0KU=",
"checksumSHA1": "RKuX3Wg2m7yvFsFoitY7hL9HcMA=",
"path": "github.com/TheThingsNetwork/go-account-lib/scope",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "RpKXQd5sp9/jsWM991S7OhE9/ME=",
"path": "github.com/TheThingsNetwork/go-account-lib/tokenkey",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "48WYq5L+4Gkl5NXlhDJM0Uzt/7o=",
"path": "github.com/TheThingsNetwork/go-account-lib/tokens",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "ceMHzBTkbEJGWevGmCq+QwSLRDE=",
"checksumSHA1": "3+2Kl1Qvj59+FAPHDEMXzOACNI0=",
"path": "github.com/TheThingsNetwork/go-account-lib/util",
"revision": "86e678eea1166541fcc5f1139f8885b4230120fc",
"revisionTime": "2017-04-26T07:51:35Z"
"revision": "6a7a9b98119263221521cd4ef444c651b855ff26",
"revisionTime": "2017-06-21T10:58:03Z"
},
{
"checksumSHA1": "i9DF5eLNL67Prly9HZQ1jUe776I=",
Expand Down

0 comments on commit f92f632

Please sign in to comment.