예제 #1
0
func offerConfig(c *cli.Context) (details *config.ArtifactoryDetails, err error) {
	var exists bool
	exists, err = config.IsArtifactoryConfExists()
	if err != nil {
		return
	}
	if exists {
		return
	}
	var val bool
	val, err = cliutils.GetBoolEnvValue("JFROG_CLI_OFFER_CONFIG", true)
	if err != nil {
		return
	}
	if !val {
		config.SaveArtifactoryConf(new(config.ArtifactoryDetails))
		return
	}
	msg := "The CLI commands require the Artifactory URL and authentication details\n" +
		"Configuring JFrog CLI with these parameters now will save you having to include them as command options.\n" +
		"You can also configure these parameters later using the 'config' command.\n" +
		"Configure now? (y/n): "
	fmt.Print(msg)
	var confirm string
	fmt.Scanln(&confirm)
	if !cliutils.ConfirmAnswer(confirm) {
		config.SaveArtifactoryConf(new(config.ArtifactoryDetails))
		return
	}
	details, err = createArtifactoryDetails(c, false)
	if err != nil {
		return
	}
	encPassword := cliutils.GetBoolFlagValue(c, "enc-password", true)
	details, err = commands.Config(nil, details, true, encPassword)
	return
}
예제 #2
0
func Config(details, defaultDetails *config.ArtifactoryDetails, interactive,
	shouldEncPassword bool) (*config.ArtifactoryDetails, error) {

	if details == nil {
		details = new(config.ArtifactoryDetails)
	}
	var err error
	if interactive {
		if defaultDetails == nil {
			defaultDetails, err = config.ReadArtifactoryConf()
			if err != nil {
				return nil, err
			}
		}
		if details.Url == "" {
			ioutils.ScanFromConsole("Artifactory URL", &details.Url, defaultDetails.Url)
		}
		if strings.Index(details.Url, "ssh://") == 0 || strings.Index(details.Url, "SSH://") == 0 {
			err = readSshKeyPathFromConsole(details, defaultDetails)
			if err != nil {
				return nil, err
			}
		} else {
			if details.ApiKey == "" && details.Password == "" {
				ioutils.ScanFromConsole("API key (leave empty for basic authentication)", &details.ApiKey, "")
			}
			if details.ApiKey == "" {
				ioutils.ReadCredentialsFromConsole(details, defaultDetails)
			}
		}
	}
	err = checkSingleAuthMethod(details)
	if err != nil {
		return nil, err
	}

	details.Url = cliutils.AddTrailingSlashIfNeeded(details.Url)
	if shouldEncPassword {
		details, err = encryptPassword(details)
		if err != nil {
			return nil, err
		}
	}
	config.SaveArtifactoryConf(details)
	return details, nil
}
예제 #3
0
func ClearConfig() {
	config.SaveArtifactoryConf(new(config.ArtifactoryDetails))
}