diff --git a/Gopkg.lock b/Gopkg.lock index 77bbb77571f..1ac80bd420f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -60,14 +60,6 @@ pruneopts = "UT" revision = "ed041402e83b924251a5d65b4dfeb727c480c359" -[[projects]] - branch = "master" - digest = "1:37011b20a70e205b93ebea5287e1afa5618db54bf3998c36ff5a8e4b146a170a" - name = "github.com/bgentry/go-netrc" - packages = ["netrc"] - pruneopts = "UT" - revision = "9fd32a8b3d3d3f9d43c341bfe098430e07609480" - [[projects]] digest = "1:d8abdc866ebbe05fa3bce50863e23afd4c73c804b90c908caa864e86df1db8a1" name = "github.com/bouk/monkey" @@ -527,7 +519,6 @@ "github.com/arduino/go-paths-helper", "github.com/arduino/go-properties-orderedmap", "github.com/arduino/go-win32-utils", - "github.com/bgentry/go-netrc/netrc", "github.com/bouk/monkey", "github.com/codeclysm/extract", "github.com/fatih/color", diff --git a/Gopkg.toml b/Gopkg.toml index aa7c7979dbe..d46748b7972 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -47,10 +47,6 @@ branch = "master" name = "go.bug.st/serial.v1" -[[constraint]] - branch = "master" - name = "github.com/bgentry/go-netrc" - [[constraint]] branch = "master" name = "github.com/mitchellh/go-homedir" diff --git a/commands/config/config.go b/cli/config/config.go similarity index 100% rename from commands/config/config.go rename to cli/config/config.go diff --git a/commands/config/dump.go b/cli/config/dump.go similarity index 100% rename from commands/config/dump.go rename to cli/config/dump.go diff --git a/commands/config/init.go b/cli/config/init.go similarity index 100% rename from commands/config/init.go rename to cli/config/init.go diff --git a/commands/generatedocs/generatedocs.go b/cli/generatedocs/generatedocs.go similarity index 100% rename from commands/generatedocs/generatedocs.go rename to cli/generatedocs/generatedocs.go diff --git a/cli/root/root.go b/cli/root/root.go index 9260900c78d..20c6aff6e62 100644 --- a/cli/root/root.go +++ b/cli/root/root.go @@ -25,14 +25,14 @@ import ( "github.com/arduino/arduino-cli/cli" "github.com/arduino/arduino-cli/cli/board" "github.com/arduino/arduino-cli/cli/compile" + "github.com/arduino/arduino-cli/cli/config" "github.com/arduino/arduino-cli/cli/core" "github.com/arduino/arduino-cli/cli/daemon" + "github.com/arduino/arduino-cli/cli/generatedocs" "github.com/arduino/arduino-cli/cli/lib" "github.com/arduino/arduino-cli/cli/sketch" "github.com/arduino/arduino-cli/cli/upload" "github.com/arduino/arduino-cli/cli/version" - "github.com/arduino/arduino-cli/commands/config" - "github.com/arduino/arduino-cli/commands/generatedocs" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/configs" paths "github.com/arduino/go-paths-helper" diff --git a/commands/login/login.go b/commands/login/login.go deleted file mode 100644 index 34dc16fc495..00000000000 --- a/commands/login/login.go +++ /dev/null @@ -1,144 +0,0 @@ -/* - * This file is part of arduino-cli. - * - * Copyright 2018 ARDUINO SA (http://www.arduino.cc/) - * - * This software is released under the GNU General Public License version 3, - * which covers the main part of arduino-cli. - * The terms of this license can be found at: - * https://www.gnu.org/licenses/gpl-3.0.en.html - * - * You can be released from the requirements of the above licenses by purchasing - * a commercial license. Buying such a license is mandatory if you want to modify or - * otherwise use the software for commercial activities involving the Arduino - * software without disclosing the source code of your own applications. To purchase - * a commercial license, send an email to license@arduino.cc. - */ - -package login - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - "syscall" - - "github.com/arduino/arduino-cli/auth" - "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/common/formatter" - "github.com/bgentry/go-netrc/netrc" - homedir "github.com/mitchellh/go-homedir" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "golang.org/x/crypto/ssh/terminal" -) - -// InitCommand prepares the command. -func InitCommand() *cobra.Command { - loginCommand := &cobra.Command{ - Use: "login [username] [password]", - Short: "Creates default credentials for an Arduino Create Session.", - Long: "Creates default credentials for an Arduino Create Session.", - Example: "" + - " " + cli.AppName + " login # Asks for all credentials.\n" + - " " + cli.AppName + " login myUser MySecretPassword # Provide all credentials.\n" + - " " + cli.AppName + " login myUser # Asks for just the password instead of having it in clear.", - Args: cobra.RangeArgs(0, 2), - Run: run, - } - return loginCommand -} - -func run(cmd *cobra.Command, args []string) { - logrus.Info("Executing `arduino login`") - - userEmpty, passwordEmpty := true, true - if len(args) > 0 { - userEmpty = false - if len(args) == 2 { - passwordEmpty = false - } - } - isTextMode := formatter.IsCurrentFormat("text") - if !isTextMode && (userEmpty || passwordEmpty) { - formatter.PrintErrorMessage("User and password must be specified outside of text format.") - return - } - - var user, password string - logrus.Info("Using/Asking credentials") - if userEmpty { - fmt.Print("Username: ") - fmt.Scanln(&user) - } else { - user = args[0] - } - // Username is always lowercase. - user = strings.ToLower(user) - - if passwordEmpty { - fmt.Print("Password: ") - pass, err := terminal.ReadPassword(int(syscall.Stdin)) // nolint:unconvert - if err != nil { - formatter.PrintError(err, "Cannot read password, login aborted.") - return - } - password = string(pass) - fmt.Println() - } else { - password = args[1] - } - - logrus.Info("Getting ~/.netrc file") - - // Save into netrc. - netRCHome, err := homedir.Dir() - if err != nil { - formatter.PrintError(err, "Cannot get current home directory.") - os.Exit(cli.ErrGeneric) - } - - netRCFile := filepath.Join(netRCHome, ".netrc") - file, err := os.OpenFile(netRCFile, os.O_RDONLY|os.O_CREATE, 0600) - if err != nil { - formatter.PrintError(err, "Cannot parse .netrc file.") - return - } - defer file.Close() - netRC, err := netrc.Parse(file) - if err != nil { - formatter.PrintError(err, "Cannot parse .netrc file.") - os.Exit(cli.ErrGeneric) - } - - logrus.Info("Trying to login") - - authConf := auth.New() - - token, err := authConf.Token(user, password) - if err != nil { - formatter.PrintError(err, "Cannot login.") - os.Exit(cli.ErrNetwork) - } - - netRC.RemoveMachine("arduino.cc") - netRC.NewMachine("arduino.cc", user, token.Access, token.Refresh) - content, err := netRC.MarshalText() - if err != nil { - formatter.PrintError(err, "Cannot parse new .netrc file.") - os.Exit(cli.ErrGeneric) - } - - err = ioutil.WriteFile(netRCFile, content, 0600) - if err != nil { - formatter.PrintError(err, "Cannot write new .netrc file.") - os.Exit(cli.ErrGeneric) - } - - formatter.PrintResult("" + - "Successfully logged into the system.\n" + - "The session will continue to be refreshed with every call of the CLI and will expire if not used.") - logrus.Info("Done") -} diff --git a/commands/logout/logout.go b/commands/logout/logout.go deleted file mode 100644 index 34e6a2b6041..00000000000 --- a/commands/logout/logout.go +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of arduino-cli. - * - * Copyright 2018 ARDUINO SA (http://www.arduino.cc/) - * - * This software is released under the GNU General Public License version 3, - * which covers the main part of arduino-cli. - * The terms of this license can be found at: - * https://www.gnu.org/licenses/gpl-3.0.en.html - * - * You can be released from the requirements of the above licenses by purchasing - * a commercial license. Buying such a license is mandatory if you want to modify or - * otherwise use the software for commercial activities involving the Arduino - * software without disclosing the source code of your own applications. To purchase - * a commercial license, send an email to license@arduino.cc. - */ - -package logout - -import ( - "io/ioutil" - "os" - "path/filepath" - - "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/common/formatter" - "github.com/bgentry/go-netrc/netrc" - homedir "github.com/mitchellh/go-homedir" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" -) - -// InitCommand prepares the command. -func InitCommand() *cobra.Command { - logoutCommand := &cobra.Command{ - Use: "logout", - Short: "Clears credentials for the Arduino Create Session.", - Long: "Clears credentials for the Arduino Create Session.", - Example: " " + cli.AppName + " logout", - Args: cobra.NoArgs, - Run: run, - } - return logoutCommand -} - -func run(cmd *cobra.Command, args []string) { - logrus.Info("Executing `arduino logout`") - - logrus.Info("Getting ~/.netrc file") - netRCHome, err := homedir.Dir() - if err != nil { - formatter.PrintError(err, "Cannot get current home directory.") - os.Exit(cli.ErrGeneric) - } - - netRCFile := filepath.Join(netRCHome, ".netrc") - file, err := os.OpenFile(netRCFile, os.O_RDONLY|os.O_CREATE, 0600) - if err != nil { - formatter.PrintError(err, "Cannot parse .netrc file.") - return - } - defer file.Close() - - netRC, err := netrc.Parse(file) - if err != nil { - formatter.PrintError(err, "Cannot parse .netrc file.") - os.Exit(cli.ErrGeneric) - } - - netRC.RemoveMachine("arduino.cc") - content, err := netRC.MarshalText() - if err != nil { - formatter.PrintError(err, "Cannot parse new .netrc file.") - os.Exit(cli.ErrGeneric) - } - - err = ioutil.WriteFile(netRCFile, content, 0600) - if err != nil { - formatter.PrintError(err, "Cannot write new .netrc file.") - os.Exit(cli.ErrGeneric) - } - - formatter.PrintResult("Successfully logged out.") - logrus.Info("Done") -} diff --git a/commands/validate/validate.go b/commands/validate/validate.go deleted file mode 100644 index b4037f8def9..00000000000 --- a/commands/validate/validate.go +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is part of arduino-cli. - * - * Copyright 2018 ARDUINO SA (http://www.arduino.cc/) - * - * This software is released under the GNU General Public License version 3, - * which covers the main part of arduino-cli. - * The terms of this license can be found at: - * https://www.gnu.org/licenses/gpl-3.0.en.html - * - * You can be released from the requirements of the above licenses by purchasing - * a commercial license. Buying such a license is mandatory if you want to modify or - * otherwise use the software for commercial activities involving the Arduino - * software without disclosing the source code of your own applications. To purchase - * a commercial license, send an email to license@arduino.cc. - */ - -package validate - -import ( - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/arduino/arduino-cli/arduino/resources" - "github.com/arduino/arduino-cli/cli" - "github.com/arduino/arduino-cli/common/formatter" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" -) - -// InitCommand prepares the command. -func InitCommand() *cobra.Command { - var validateCommand = &cobra.Command{ - Use: "validate", - Short: "Validates Arduino installation.", - Long: "Checks installed cores and tools for corruption.", - Example: " " + cli.AppName + " validate", - Args: cobra.NoArgs, - Run: run, - } - return validateCommand -} - -func run(cmd *cobra.Command, args []string) { - logrus.Info("Executing `arduino validate`") - packagesDir := cli.Config.PackagesDir().String() - err := filepath.Walk(packagesDir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - return nil - } - relativePath, err := filepath.Rel(packagesDir, path) - if err != nil { - return err - } - pathParts := strings.Split(relativePath, string(filepath.Separator)) - if len(pathParts) == 4 { - isValid, err := resources.CheckDirChecksum(path) - if err != nil { - return err - } - if !isValid { - formatter.PrintErrorMessage(fmt.Sprintf("Corrupted %s", path)) - } - return filepath.SkipDir - } - return nil - }) - if err != nil { - formatter.PrintError(err, "Failed to perform validation.") - os.Exit(cli.ErrBadCall) - } -}