Skip to content
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
28 changes: 28 additions & 0 deletions docs/configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,34 @@ messages to any desired timezone.

The default value for `timestamp_timezone` is `utc`

### Git settings

Whenw working with git repositories, there are some global settings that should
be configured. This section provides a configuration settings for setting
global git options.

#### `name`

Configures the name to use when making commits using git. The name configured
here will be displayed in the commit message.

The default value for `name` is `null`

#### `email`

Configures the email address to use when making git commits. The email address
will be used in commit messages.

The default value for `email` is `null`

#### `user`

Sets the default user to use when connecting to a git repository over SSH.
Most git server implementations require this value to be `git` which is the
default; however it can be changed here if needed.

The default value for `user` is `git`.

### Profiles

Profiles provide server specific configuration settings for working with
Expand Down
5 changes: 3 additions & 2 deletions internal/runners/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ func (r Repository) Clone() (string, error) {
logger.Trace()

repo := repositories.Repository{
Url: r.Url,
Url: r.Url,
User: "git",
}
if r.PrivateKeyFile != "" {
pk, err := utils.ReadStringFromFile(r.PrivateKeyFile)
pk, err := utils.ReadFromFile(r.PrivateKeyFile)
if err != nil {
return "", err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (

defaultGitName = ""
defaultGitEmail = ""
defaultGitUser = "git"
)

type Config struct {
Expand Down Expand Up @@ -69,6 +70,7 @@ type Config struct {
// Git settings
GitName string `json:"git_name"`
GitEmail string `json:"git_email"`
GitUser string `json:"git_user"`
}

func NewConfig(defaults map[string]interface{}, envBinding map[string]string, appWorkingDir, sysConfigPath, fileName string) *Config {
Expand Down Expand Up @@ -200,6 +202,7 @@ func (ac *Config) populateFields() {

ac.GitName = viper.GetString("git.name")
ac.GitEmail = viper.GetString("git.email")
ac.GitUser = viper.GetString("git.user")
}

var defaultValues = map[string]interface{}{
Expand All @@ -221,6 +224,7 @@ var defaultValues = map[string]interface{}{

"git.name": defaultGitName,
"git.email": defaultGitEmail,
"git.user": defaultGitUser,
}

var defaultEnvVarBindings = map[string]string{
Expand All @@ -242,6 +246,7 @@ var defaultEnvVarBindings = map[string]string{

"git.name": "IPCTL_GIT_NAME",
"git.email": "IPCTL_GIT_EMAIL",
"git.user": "IPCTL_GIT_USER",
}

// getConfigFileFromFlag reads in the file passed in using the --config flag on the cli
Expand Down
23 changes: 21 additions & 2 deletions pkg/repositories/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
gitssh "github.com/go-git/go-git/v5/plumbing/transport/ssh"
"github.com/itential/ipctl/pkg/logger"
giturls "github.com/whilp/git-urls"
"golang.org/x/crypto/ssh"
)

type Repository struct {
Url string
Reference string
PrivateKey string
User string
PrivateKey []byte
}

func (r Repository) Clone() (string, error) {
Expand All @@ -36,7 +39,23 @@ func (r Repository) Clone() (string, error) {

cloneOptions := &git.CloneOptions{
URL: r.Url,
//Auth: r.PrivateKey,
}

if r.PrivateKey != nil {
logger.Debug("setting up auth using private key")

signer, err := ssh.ParsePrivateKey(r.PrivateKey)
if err != nil {
return "", err
}

cloneOptions.Auth = &gitssh.PublicKeys{
User: r.User,
Signer: signer,
HostKeyCallbackHelper: gitssh.HostKeyCallbackHelper{
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
},
}
}

// Git will default to main/master if no repo is specified
Expand Down