cmds

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateKey = &cobra.Command{
	Use:   "create-key",
	Short: "create a SSH key",
	Long: `Perform secure SSH key generation.
`,
	Run: func(cmd *cobra.Command, args []string) {
		p, err := utils.LoadPersona(cmd)
		if err != nil {
			ui.Fatal(err, 1)
		}

		passphrase := utils.GeneratePassphrase()
		ui.Infof(fmt.Sprintf("Generated passphrase: %s", passphrase))

		genCmd := "ssh-keygen"
		genArgs := []string{
			"-t", "ed25519",
			"-a", "100",
			"-N", passphrase,
			"-C", p.Config.GetString("identity.email"),
			"-f", path.Join(p.Location(), pluginName, "id_rsa"),
		}

		c := exec.Command(genCmd, genArgs...)

		out, err := c.Output()
		if err != nil {
			ui.Error(err)

			var eerr *exec.ExitError
			if errors.As(err, &eerr) {
				ui.Error(err)
			}
			os.Exit(1)
		}

		ui.Outputf(string(out))
	},
}
View Source
var PrintPubKey = &cobra.Command{
	Use:   "print-pubkey",
	Short: "Print public key",
	Long: `Print SSH public key to be reused or copied outside of devid.
`,
	Run: func(cmd *cobra.Command, args []string) {
		p, err := utils.LoadPersona(cmd)
		if err != nil {
			ui.Fatal(err, 1)
		}

		pubKeyLocatin := path.Join(p.Location(), pluginName, "id_rsa.pub")
		dat, err := os.ReadFile(pubKeyLocatin)
		if err != nil {
			ui.Error(err)
		}

		ui.Outputf(string(dat))
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL