Skip to content

Commit

Permalink
Merge pull request #5 from skilld-labs/allow_to_pass_credentials_options
Browse files Browse the repository at this point in the history
add username and password as command options
  • Loading branch information
davidferlay authored Mar 4, 2024
2 parents c7c7912 + dd6bef5 commit 6a8eb6a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,28 @@ func (p *Plugin) OnAppInit(app launchr.App) error {

// CobraAddCommands implements launchr.CobraPlugin interface to provide bump functionality.
func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
var username string
var password string

var pblCmd = &cobra.Command{
Use: "publish",
Short: "Upload local artifact archive to private repository",
RunE: func(cmd *cobra.Command, args []string) error {
// Don't show usage help on a runtime error.
cmd.SilenceUsage = true

return publish(p.k)
return publish(username, password, p.k)
},
}

pblCmd.Flags().StringVarP(&username, "username", "", "", "Username for artifact repository")
pblCmd.Flags().StringVarP(&password, "password", "", "", "Password for artifact repository")

rootCmd.AddCommand(pblCmd)
return nil
}

func publish(k keyring.Keyring) error {
func publish(username, password string, k keyring.Keyring) error {
// Get repository information
repoName, lastCommitShortSHA, err := getRepoInfo()
if err != nil {
Expand Down Expand Up @@ -111,7 +117,7 @@ func publish(k keyring.Keyring) error {
}

cli.Println("Getting credentials")
ci, save, err := getCredentials(artifactsRepositoryDomain, k)
ci, save, err := getCredentials(artifactsRepositoryDomain, username, password, k)
if err != nil {
return err
}
Expand Down Expand Up @@ -143,7 +149,7 @@ func publish(k keyring.Keyring) error {
return nil
}

func getCredentials(url string, k keyring.Keyring) (keyring.CredentialsItem, bool, error) {
func getCredentials(url, username, password string, k keyring.Keyring) (keyring.CredentialsItem, bool, error) {
ci, err := k.GetForURL(url)
save := false
if err != nil {
Expand All @@ -155,7 +161,9 @@ func getCredentials(url string, k keyring.Keyring) (keyring.CredentialsItem, boo
}
ci = keyring.CredentialsItem{}
ci.URL = url
if ci.URL != "" {
ci.Username = username
ci.Password = password
if ci.URL != "" && (ci.Username == "" || ci.Password == "") {
cli.Println("Please add login and password for URL - %s", ci.URL)
}
err = keyring.RequestCredentialsFromTty(&ci)
Expand Down

0 comments on commit 6a8eb6a

Please sign in to comment.