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() {
|
func init() {
|
||||||
rootCmd.AddCommand(registerDeviceCommand)
|
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{
|
var registerDeviceCommand = &cobra.Command{
|
||||||
|
|
@ -23,8 +24,11 @@ var registerDeviceCommand = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.Email == "" {
|
if cc.Email != "" {
|
||||||
return errors.New("you don't have an account configured for thist device")
|
email = cc.Email
|
||||||
|
}
|
||||||
|
if email == "" {
|
||||||
|
return errors.New("provide an email through your config file or with --email")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.DeviceId != "" {
|
if cc.DeviceId != "" {
|
||||||
|
|
@ -35,7 +39,7 @@ var registerDeviceCommand = &cobra.Command{
|
||||||
pbk := pvk.PublicKey()
|
pbk := pvk.PublicKey()
|
||||||
|
|
||||||
password := input.ReadPassword()
|
password := input.ReadPassword()
|
||||||
res, err := apiclient.RegisterDevice(cc.Email, password, pbk.Bytes())
|
res, err := apiclient.RegisterDevice(email, password, pbk.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +47,9 @@ var registerDeviceCommand = &cobra.Command{
|
||||||
// Write the key files first, if those fail to write then we should not
|
// Write the key files first, if those fail to write then we should not
|
||||||
// save the device Id.
|
// save the device Id.
|
||||||
cc.DeviceId = res.DeviceID
|
cc.DeviceId = res.DeviceID
|
||||||
|
if cc.Email == "" {
|
||||||
|
cc.Email = email
|
||||||
|
}
|
||||||
err = configfile.SavePrivateKey(pvk)
|
err = configfile.SavePrivateKey(pvk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ type ConfigFile struct {
|
||||||
var Path string
|
var Path string
|
||||||
|
|
||||||
func EnsureAndGet() (ConfigFile, error) {
|
func EnsureAndGet() (ConfigFile, error) {
|
||||||
err := os.MkdirAll(Path, os.FileMode(int(0660)))
|
err := os.MkdirAll(Path, os.FileMode(int(0770)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ConfigFile{}, fmt.Errorf("could not create config directory: %w", err)
|
return ConfigFile{}, fmt.Errorf("could not create config directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +38,7 @@ func EnsureAndGet() (ConfigFile, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Write(c 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue