-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
255 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright © 2018 CloudODM Contributors | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/OpenDroneMap/CloudODM/internal/config" | ||
"github.com/OpenDroneMap/CloudODM/internal/logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var loginCmd = &cobra.Command{ | ||
Use: "login [--node default]", | ||
Short: "Login with a node", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
config.Initialize() | ||
|
||
if config.CheckLogin(nodeName) != nil { | ||
logger.Info("Logged in") | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
loginCmd.Flags().StringVarP(&nodeName, "node", "n", "default", "Processing node to use") | ||
|
||
rootCmd.AddCommand(loginCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright © 2018 CloudODM Contributors | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/OpenDroneMap/CloudODM/internal/config" | ||
"github.com/OpenDroneMap/CloudODM/internal/logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var logoutCmd = &cobra.Command{ | ||
Use: "logout [--node default]", | ||
Short: "Logout of a node", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
config.Initialize() | ||
|
||
node, err := config.User.GetNode(nodeName) | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
|
||
node.Token = "" | ||
config.User.UpdateNode(nodeName, *node) | ||
|
||
logger.Info("Logged out") | ||
}, | ||
} | ||
|
||
func init() { | ||
logoutCmd.Flags().StringVarP(&nodeName, "node", "n", "default", "Processing node to use") | ||
|
||
rootCmd.AddCommand(logoutCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/OpenDroneMap/CloudODM/internal/logger" | ||
"github.com/OpenDroneMap/CloudODM/internal/odm" | ||
) | ||
|
||
// CheckLogin checks if the node needs login | ||
// if it does, it attempts to login | ||
// it it doesn't, returns node.Info() | ||
// on error, it prints a message and exits | ||
func CheckLogin(nodeName string) *odm.InfoResponse { | ||
node, err := User.GetNode(nodeName) | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
|
||
info, err := node.Info() | ||
err = node.CheckAuthentication(err) | ||
if err != nil { | ||
if err == odm.ErrAuthRequired { | ||
token, err := node.TryLogin() | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
|
||
// Validate token | ||
node.Token = token | ||
info, err = node.Info() | ||
err = node.CheckAuthentication(err) | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
|
||
User.UpdateNode(nodeName, *node) | ||
} else { | ||
logger.Error(err) | ||
} | ||
} | ||
|
||
return info | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters