-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add command to upload ssh keys
- Loading branch information
1 parent
9ea69ee
commit 89504a2
Showing
5 changed files
with
127 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/jonathongardner/linuxhelp/setup/github" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var githubSSHPushCommand = &cli.Command{ | ||
Name: "push", | ||
Usage: "Github push public ssh keys for user", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "path", | ||
Aliases: []string{"p"}, | ||
Usage: "Path to public key", | ||
DefaultText: "~/.ssh/id_rsa.pub", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "title", | ||
Usage: "A description name for the key", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
path := c.String("path") | ||
if path == "" { | ||
homedir, err := os.UserHomeDir() | ||
if err != nil { | ||
return fmt.Errorf("error getting home dir (%v)", err) | ||
} | ||
path = filepath.Join(homedir, ".ssh/id_rsa.pub") | ||
} | ||
|
||
githubApi := github.NewApi(c.String("host"), c.String("user"), c.String("token")) | ||
|
||
key, err := os.ReadFile(path) | ||
if err != nil { | ||
return fmt.Errorf("error opening file %v (%v)", path, err) | ||
} | ||
|
||
fingerprint, err := githubApi.SSHSave(string(key), c.String("title")) | ||
if err != nil { | ||
return fmt.Errorf("error adding %v (%v)", fingerprint, err) | ||
} | ||
log.Infof("Added %v ssh", fingerprint) | ||
|
||
return nil | ||
}, | ||
} |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
v0.0.1 | ||
v0.1.0 |