deploykeys

package
v0.0.0-...-493bf59 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: Apache-2.0 Imports: 18 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddSubCmd = models.Command{
	Name:      "add",
	ShortHelp: "Add a new deploy key",
	LongHelp: "<code>deploy-keys add</code> allows you to upload an SSH public key in OpenSSH format. " +
		"These keys are used for pushing code to your code services but are not required. " +
		"You should be using personal SSH keys with the keys command unless you are pushing code from Continuous Integration or Continuous Deployment scenarios. " +
		"Deploy keys are intended to be shared among an organization. Here are some sample commands\n\n" +
		"<pre>\ndatica -E \"<your_env_name>\" deploy-keys add app01_public ~/.ssh/app01_rsa.pub app01\n</pre>",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			name := subCmd.StringArg("NAME", "", "The name for the new key, for your own purposes")
			path := subCmd.StringArg("KEY_PATH", "", "Relative path to the SSH key file")
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the code service to add this deploy key to")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdAdd(*name, *path, *serviceName, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "NAME KEY_PATH SERVICE_NAME"
		}
	},
}
View Source
var Cmd = models.Command{
	Name:      "deploy-keys",
	ShortHelp: "Tasks for SSH deploy keys",
	LongHelp:  "The <code>deploy-keys</code> command gives access to SSH deploy keys for environment services. The deploy-keys command can not be run directly but has subcommands.",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(cmd *cli.Cmd) {
			cmd.CommandLong(AddSubCmd.Name, AddSubCmd.ShortHelp, AddSubCmd.LongHelp, AddSubCmd.CmdFunc(settings))
			cmd.CommandLong(ListSubCmd.Name, ListSubCmd.ShortHelp, ListSubCmd.LongHelp, ListSubCmd.CmdFunc(settings))
			cmd.CommandLong(RmSubCmd.Name, RmSubCmd.ShortHelp, RmSubCmd.LongHelp, RmSubCmd.CmdFunc(settings))
		}
	},
}
View Source
var ListSubCmd = models.Command{
	Name:      "list",
	ShortHelp: "List all deploy keys",
	LongHelp: "<code>deploy-keys list</code> will list all of your previously uploaded deploy keys by name including the key's fingerprint in SHA256 format. Here is a sample command\n\n" +
		"<pre>\ndatica -E \"<your_env_name>\" deploy-keys list app01\n</pre>",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the code service to list deploy keys")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdList(*serviceName, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "SERVICE_NAME"
		}
	},
}
View Source
var RmSubCmd = models.Command{
	Name:      "rm",
	ShortHelp: "Remove a deploy key",
	LongHelp: "<code>deploy-keys rm</code> will remove a previously created deploy key by name. " +
		"It is a good idea to rotate deploy keys on a set schedule as they are intended to be shared among an organization. " +
		"Here are some sample commands\n\n" +
		"<pre>\ndatica -E \"<your_env_name>\" deploy-keys rm app01_public app01\n</pre>",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			name := subCmd.StringArg("NAME", "", "The name of the key to remove")
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the code service to remove this deploy key from")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdRm(*name, *serviceName, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "NAME SERVICE_NAME"
		}
	},
}

Functions

func CmdAdd

func CmdAdd(name, keyPath, svcName string, id IDeployKeys, is services.IServices) error

func CmdList

func CmdList(svcName string, id IDeployKeys, is services.IServices) error

func CmdRm

func CmdRm(name, svcName string, id IDeployKeys, is services.IServices) error

Types

type IDeployKeys

type IDeployKeys interface {
	Add(name, keyType, key, svcID string) error
	ExtractPublicKey(privKey *rsa.PrivateKey) (ssh.PublicKey, error)
	List(svcID string) (*[]models.DeployKey, error)
	ParsePrivateKey(b []byte) (*rsa.PrivateKey, error)
	ParsePublicKey(b []byte) (ssh.PublicKey, error)
	Rm(name, keyType, svcID string) error
}

func New

func New(settings *models.Settings) IDeployKeys

type SDeployKeys

type SDeployKeys struct {
	Settings *models.Settings
}

func (*SDeployKeys) Add

func (d *SDeployKeys) Add(name, keyType, key, svcID string) error

Add adds a new public key to the authenticated user's account

func (*SDeployKeys) ExtractPublicKey

func (d *SDeployKeys) ExtractPublicKey(privKey *rsa.PrivateKey) (ssh.PublicKey, error)

func (*SDeployKeys) List

func (d *SDeployKeys) List(svcID string) (*[]models.DeployKey, error)

func (*SDeployKeys) ParsePrivateKey

func (d *SDeployKeys) ParsePrivateKey(b []byte) (*rsa.PrivateKey, error)

func (*SDeployKeys) ParsePublicKey

func (d *SDeployKeys) ParsePublicKey(b []byte) (ssh.PublicKey, error)

func (*SDeployKeys) Rm

func (d *SDeployKeys) Rm(name, keyType, svcID string) error

Jump to

Keyboard shortcuts

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