diff --git a/internal/config/config.go b/internal/config/config.go index d858c1f..a7e8300 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -27,6 +27,10 @@ func Read(path string) (config types.Configuration, err error) { } config.Remotes[i].Auth.AccessToken = string(content) } + // On GitLab and GitHub, any non blank username is working + if remote.Auth.Username == "" { + config.Remotes[i].Auth.Username = "comin" + } if remote.Timeout == 0 { config.Remotes[i].Timeout = 300 } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 0ffa661..10a5c9c 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -19,6 +19,7 @@ func TestConfig(t *testing.T) { Auth: types.Auth{ AccessToken: "my-secret", AccessTokenPath: "./secret", + Username: "comin", }, Timeout: 300, }, @@ -28,6 +29,7 @@ func TestConfig(t *testing.T) { Auth: types.Auth{ AccessToken: "", AccessTokenPath: "", + Username: "comin", }, Timeout: 300, }, diff --git a/internal/repository/git.go b/internal/repository/git.go index 6bed7f4..98b20f9 100644 --- a/internal/repository/git.go +++ b/internal/repository/git.go @@ -121,9 +121,7 @@ func fetch(r repository, remote types.Remote) (err error) { // TODO: support several authentication methods if remote.Auth.AccessToken != "" { fetchOptions.Auth = &http.BasicAuth{ - // On GitLab, any non blank username is - // working. - Username: "comin", + Username: remote.Auth.Username, Password: remote.Auth.AccessToken, } } diff --git a/internal/types/types.go b/internal/types/types.go index 91b6a42..7d4b644 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -24,6 +24,7 @@ type GitConfig struct { type Auth struct { AccessToken string AccessTokenPath string `yaml:"access_token_path"` + Username string } type Branch struct { diff --git a/nix/module-options.nix b/nix/module-options.nix index 8b64af2..94e29af 100644 --- a/nix/module-options.nix +++ b/nix/module-options.nix @@ -75,6 +75,15 @@ The path of the auth file. ''; }; + username = mkOption { + type = str; + default = "comin"; + description = '' + The username used to authenticate to the Git + remote repository. Note that any non empty + username is valid on GitLab and GitHub. + ''; + }; }; }; };