Allow registering device without requiring the creation of the config file.
Some checks failed
Fly Deploy / Deploy app (push) Has been cancelled
Some checks failed
Fly Deploy / Deploy app (push) Has been cancelled
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
c041a5feee
commit
8445a7546e
2 changed files with 12 additions and 5 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
func init() {
|
||||
rootCmd.AddCommand(registerDeviceCommand)
|
||||
registerDeviceCommand.Flags().StringVarP(&email, "email", "e", "", "email is your login identifier, ignored if your config file has has an email")
|
||||
}
|
||||
|
||||
var registerDeviceCommand = &cobra.Command{
|
||||
|
|
@ -23,8 +24,11 @@ var registerDeviceCommand = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
|
||||
if cc.Email == "" {
|
||||
return errors.New("you don't have an account configured for thist device")
|
||||
if cc.Email != "" {
|
||||
email = cc.Email
|
||||
}
|
||||
if email == "" {
|
||||
return errors.New("provide an email through your config file or with --email")
|
||||
}
|
||||
|
||||
if cc.DeviceId != "" {
|
||||
|
|
@ -35,7 +39,7 @@ var registerDeviceCommand = &cobra.Command{
|
|||
pbk := pvk.PublicKey()
|
||||
|
||||
password := input.ReadPassword()
|
||||
res, err := apiclient.RegisterDevice(cc.Email, password, pbk.Bytes())
|
||||
res, err := apiclient.RegisterDevice(email, password, pbk.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -43,6 +47,9 @@ var registerDeviceCommand = &cobra.Command{
|
|||
// Write the key files first, if those fail to write then we should not
|
||||
// save the device Id.
|
||||
cc.DeviceId = res.DeviceID
|
||||
if cc.Email == "" {
|
||||
cc.Email = email
|
||||
}
|
||||
err = configfile.SavePrivateKey(pvk)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ type ConfigFile struct {
|
|||
var Path string
|
||||
|
||||
func EnsureAndGet() (ConfigFile, error) {
|
||||
err := os.MkdirAll(Path, os.FileMode(int(0660)))
|
||||
err := os.MkdirAll(Path, os.FileMode(int(0770)))
|
||||
if err != nil {
|
||||
return ConfigFile{}, fmt.Errorf("could not create config directory: %w", err)
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ func EnsureAndGet() (ConfigFile, error) {
|
|||
}
|
||||
|
||||
func Write(c ConfigFile) error {
|
||||
err := os.MkdirAll(Path, os.FileMode(int(0660)))
|
||||
err := os.MkdirAll(Path, os.FileMode(int(0770)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue