2018-01-16 02:22:22 +05:30
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
2020-02-16 15:53:47 +05:30
|
|
|
"github.com/elyby/chrly/http"
|
2018-01-16 02:22:22 +05:30
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var tokenCmd = &cobra.Command{
|
|
|
|
Use: "token",
|
2018-02-15 02:19:22 +05:30
|
|
|
Short: "Creates a new token, which allows to interact with Chrly API",
|
2018-01-16 02:22:22 +05:30
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2020-04-19 05:01:09 +05:30
|
|
|
container := shouldGetContainer()
|
|
|
|
var auth *http.JwtAuth
|
|
|
|
err := container.Resolve(&auth)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
token, err := auth.NewToken(http.SkinScope)
|
2018-02-15 16:50:17 +05:30
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Unable to create new token. The error is %v\n", err)
|
2018-01-16 02:22:22 +05:30
|
|
|
}
|
|
|
|
|
2018-02-15 16:50:17 +05:30
|
|
|
fmt.Printf("%s\n", token)
|
2018-01-16 02:22:22 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(tokenCmd)
|
|
|
|
}
|