Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd(remotes): add ability to generate token over SSH #643

Merged
merged 1 commit into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (root *RemoteCmd) attachSetCmd() {
func (root *RemoteCmd) attachConfigPathCmd() {
var cfgPath = &cobra.Command{
Use: "config-path",
Short: "Output path to remote configuration.",
Short: "Output path to remote configuration file",
Long: `Outputs where remotes are stored. Note that the configuration directory
can be set using INERTIA_PATH.`,
Run: func(cmd *cobra.Command, args []string) {
Expand Down
33 changes: 25 additions & 8 deletions cmd/remotes/remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import (
// AttachRemotesCmds reads configuration to attach a child command for each
// configured remote in the configuration
func AttachRemotesCmds(root *core.Cmd) {
project, err := local.GetProject(root.ProjectConfigPath)
if err != nil {
return
}
project, _ := local.GetProject(root.ProjectConfigPath)
cfg, err := local.GetRemotes()
if err != nil {
return
Expand Down Expand Up @@ -113,9 +110,12 @@ If the SSH key for your remote requires a passphrase, it can be provided via 'ID

Run 'inertia [remote] init' to gather this information.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if host.client == nil || host.project == nil {
if host.client == nil {
out.Fatal("failed to read configuration")
}
if host.project == nil {
out.Fatal("no project found in current directory - try 'inertia init'")
}
if host.getRemote().Version != inertia.Version {
out.Printf("[WARNING] Remote configuration version '%s' does not match your Inertia CLI version '%s'\n",
host.getRemote().Version, inertia.Version)
Expand Down Expand Up @@ -455,19 +455,36 @@ directory (~/inertia) from your remote host.`,
}

func (root *HostCmd) attachTokenCmd() {
var token = &cobra.Command{
var tokenCmd = &cobra.Command{
Use: "token",
Short: "Generate tokens associated with permission levels for admin to share.",
Long: `Generate tokens associated with permission levels for team leads to share`,
Run: func(cmd *cobra.Command, args []string) {
token, err := root.client.Token(root.ctx)
useSSH, err := cmd.Flags().GetBool("ssh")
if err != nil {
out.Fatal(err)
}
var token string
if useSSH {
sshc, err := root.client.GetSSHClient()
if err != nil {
out.Fatal(err.Error())
}
if err = sshc.AssignAPIToken(); err != nil {
out.Fatal(err.Error())
}
token = root.client.Remote.Daemon.Token
} else {
token, err = root.client.Token(root.ctx)
if err != nil {
out.Fatal(err)
}
}
out.Println(token)
},
}
root.AddCommand(token)
tokenCmd.Flags().Bool("ssh", false, "generate token over SSH")
root.AddCommand(tokenCmd)
}

func (root *HostCmd) attachUpgradeCmd() {
Expand Down