Example #1
0
func Config(details, defaultDetails *config.MissionControlDetails, interactive bool) (conf *config.MissionControlDetails, err error) {
	conf = details
	if conf == nil {
		conf = new(config.MissionControlDetails)
	}
	if interactive {
		if defaultDetails == nil {
			defaultDetails, err = config.ReadMissionControlConf()
			if err != nil {
				return
			}
		}
		if conf.Url == "" {
			ioutils.ScanFromConsole("Mission Control URL", &conf.Url, defaultDetails.Url)
			var u *url.URL
			u, err = url.Parse(conf.Url)
			err = cliutils.CheckError(err)
			if err != nil {
				return
			}
			if u.Scheme != "http" && u.Scheme != "https" {
				err = cliutils.CheckError(errors.New("URL scheme is not valid " + u.Scheme))
				if err != nil {
					return
				}
			}
		}
		ioutils.ReadCredentialsFromConsole(conf, defaultDetails)
	}
	conf.Url = cliutils.AddTrailingSlashIfNeeded(conf.Url)
	config.SaveMissionControlConf(conf)
	return
}
Example #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
}