func()

in cmd/resource/utils.go [165:260]


func (c *Clients) getChartDetails(m *Model) (*Chart, error) {
	cd := &Chart{}
	// Parse chart
	switch m.Chart {
	case nil:
		return nil, errors.New("chart is required")
	default:
		// Check if chart is remote url
		u, err := url.Parse(*m.Chart)
		if err != nil {
			return nil, genericError("Process chart", err)
		}
		switch {
		case u.Host != "", strings.ToLower(u.Scheme) == "oci":
			cd.ChartType = aws.String("Local")
			cd.Chart = aws.String(chartLocalPath)
			cd.ChartPath = m.Chart
			var chart string
			sa := strings.Split(u.Path, "/")
			switch {
			case len(sa) > 1:
				chart = sa[len(sa)-1]
			default:
				chart = strings.TrimLeft(u.RequestURI(), "/")
			}
			re := regexp.MustCompile(`[A-Za-z]+`)
			cd.ChartName = aws.String(re.FindAllString(chart, 1)[0])
			if !IsZero(m.RepositoryOptions) {
				if !IsZero(m.RepositoryOptions.Username) && !IsZero(m.RepositoryOptions.Password) {
					log.Printf("Using basic authentication with username: %s for repository", *m.RepositoryOptions.Username)
					cd.ChartUsername = m.RepositoryOptions.Username
					cd.ChartPassword = m.RepositoryOptions.Password
				}
			}
		default:
			// Get repo name and chart
			sa := strings.Split(*m.Chart, "/")
			switch {
			case len(sa) > 1:
				cd.ChartRepo = aws.String(sa[0])
				cd.ChartName = aws.String(sa[1])
			default:
				cd.ChartRepo = aws.String("stable")
				cd.ChartName = m.Chart
			}
			// Set chart verify to default
			cd.ChartSkipTLSVerify = aws.Bool(false)
			cd.ChartLocalCA = aws.Bool(false)
			if !IsZero(m.RepositoryOptions) {
				if !IsZero(m.RepositoryOptions.Username) && !IsZero(m.RepositoryOptions.Password) {
					log.Printf("Using basic authentication with username: %s for repository", *m.RepositoryOptions.Username)
					cd.ChartUsername = m.RepositoryOptions.Username
					cd.ChartPassword = m.RepositoryOptions.Password
				}
				// IsZero on bool if false
				if !IsZero(m.RepositoryOptions.InsecureSkipTLSVerify) {
					cd.ChartSkipTLSVerify = m.RepositoryOptions.InsecureSkipTLSVerify
				}
				if !IsZero(m.RepositoryOptions.CAFile) {
					u, err := url.Parse(*m.RepositoryOptions.CAFile)
					if err != nil {
						return nil, genericError("Process url", err)
					}
					switch {
					case strings.ToLower(u.Scheme) == "s3":
						bucket := u.Host
						key := strings.TrimLeft(u.Path, "/")
						region, err := getBucketRegion(c.AWSClients.S3Client(nil, nil), bucket)
						if err != nil {
							return nil, err
						}
						err = downloadS3(c.AWSClients.S3Client(region, nil), bucket, key, caLocalPath)
						if err != nil {
							return nil, err
						}
						cd.ChartLocalCA = aws.Bool(true)
					default:
						log.Printf("Unsupported CAFile format: %s must be S3 path. Ignoring CAFile...", *m.RepositoryOptions.CAFile)
					}
				}
			}
			cd.ChartType = aws.String("Remote")
			cd.Chart = aws.String(fmt.Sprintf("%s/%s", *cd.ChartRepo, *cd.ChartName))
		}
	}
	if m.Version != nil {
		cd.ChartVersion = m.Version
	}
	switch m.Repository {
	case nil:
		cd.ChartRepoURL = aws.String(stableRepoURL)
	default:
		cd.ChartRepoURL = m.Repository
	}
	return cd, nil
}