2018-01-15 23:52:22 +03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2024-02-01 12:11:39 +01:00
|
|
|
"ely.by/chrly/internal/security"
|
2018-01-15 23:52:22 +03:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var tokenCmd = &cobra.Command{
|
|
|
|
Use: "token",
|
2018-02-14 23:49:22 +03:00
|
|
|
Short: "Creates a new token, which allows to interact with Chrly API",
|
2024-02-01 12:11:39 +01:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2020-04-19 02:31:09 +03:00
|
|
|
container := shouldGetContainer()
|
2024-02-01 12:11:39 +01:00
|
|
|
var auth *security.Jwt
|
2020-04-19 02:31:09 +03:00
|
|
|
err := container.Resolve(&auth)
|
|
|
|
if err != nil {
|
2024-02-01 12:11:39 +01:00
|
|
|
return err
|
2020-04-19 02:31:09 +03:00
|
|
|
}
|
|
|
|
|
2024-02-01 12:11:39 +01:00
|
|
|
token, err := auth.NewToken(security.ProfileScope)
|
2018-02-15 14:20:17 +03:00
|
|
|
if err != nil {
|
2024-02-01 12:11:39 +01:00
|
|
|
return fmt.Errorf("Unable to create a new token. The error is %v\n", err)
|
2018-01-15 23:52:22 +03:00
|
|
|
}
|
|
|
|
|
2024-02-01 12:11:39 +01:00
|
|
|
fmt.Println(token)
|
|
|
|
|
|
|
|
return nil
|
2018-01-15 23:52:22 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(tokenCmd)
|
|
|
|
}
|