// StrategyAndSourceForRepository returns the build strategy and source code reference
// of the provided source repository
// TODO: user should be able to choose whether to download a remote source ref for
// more info
492261
func StrategyAndSourceForRepository(repo *SourceRepository, image *ImageRef) (*BuildStrategyRef, *SourceRef, error) {
	strategy := &BuildStrategyRef{
		Base:     image,
		Strategy: repo.strategy,
	}
	source := &SourceRef{
		Binary:       repo.binary,
		Secrets:      repo.secrets,
		ConfigMaps:   repo.configMaps,
		RequiresAuth: repo.requiresAuth,
	}

	if repo.sourceImage != nil {
		srcImageRef, err := InputImageFromMatch(repo.sourceImage.Input().ResolvedMatch)
		if err != nil {
			return nil, nil, err
		}
		source.SourceImage = srcImageRef
		source.ImageSourcePath = repo.sourceImageFrom
		source.ImageDestPath = repo.sourceImageTo
	}

	if (repo.ignoreRepository || repo.forceAddDockerfile) && repo.Info() != nil && repo.Info().Dockerfile != nil {
		source.DockerfileContents = repo.Info().Dockerfile.Contents()
	}
	if !repo.ignoreRepository {
		remoteURL, ok, err := repo.RemoteURL()
		if err != nil {
			return nil, nil, fmt.Errorf("cannot obtain remote URL for repository at %s", repo.location)
		}
		if ok {
			source.URL = remoteURL
		} else {
			source.Binary = true
		}
		source.ContextDir = repo.ContextDir()
	}

	return strategy, source, nil
}
209292
func (s Strategy) publicDockerImageRepository(stream *imageapi.ImageStream) string {
	externalHostname, ok := s.registryHostnameRetriever.ExternalRegistryHostname()
	if !ok {
		return ""
	}
	ref := imageapi.DockerImageReference{
		Registry:  externalHostname,
		Namespace: stream.Namespace,
		Name:      stream.Name,
	}
	return ref.String()
}
262233
func (m MultiRESTMapper) AliasesForResource(alias string) (aliases []string, ok bool) {
	for _, t := range m {
		if aliases, ok = t.AliasesForResource(alias); ok {
			return
		}
	}
	return nil, false
}
867634
func (s *SourceService) CreateSource(ctx context.Context, b *platform.Source) error {
	u, err := newURL(s.Addr, sourcePath)
	if err != nil {
		return err
	}

	octets, err := json.Marshal(b)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", u.String(), bytes.NewReader(octets))
	if err != nil {
		return err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(s.Token, req)

	hc := newClient(u.Scheme, s.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	// TODO(jsternberg): Should this check for a 201 explicitly?
	if err := CheckError(resp); err != nil {
		return err
	}

	if err := json.NewDecoder(resp.Body).Decode(b); err != nil {
		return err
	}

	return nil
}
1279491
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
	switch resource {
	// Group=samplecontroller.k8s.io, Version=v1alpha1
	case v1alpha1.SchemeGroupVersion.WithResource("foos"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Samplecontroller().V1alpha1().Foos().Informer()}, nil

	}

	return nil, fmt.Errorf("no informer found for %v", resource)
}
1286273
func AddMissingComponentsToRefBuilder(
	b *app.ReferenceBuilder, repositories app.SourceRepositories, dockerfileResolver, sourceResolver, pipelineResolver app.Resolver,
	g *GenerationInputs,
) (app.ComponentReferences, error) {
	errs := []error{}
	result := app.ComponentReferences{}
	for _, repo := range repositories {
		info := repo.Info()
		switch {
		case info == nil:
			errs = append(errs, fmt.Errorf("source not detected for repository %q", repo))
			continue

		case info.Jenkinsfile && (g.Strategy == newapp.StrategyUnspecified || g.Strategy == newapp.StrategyPipeline):
			refs := b.AddComponents([]string{"pipeline"}, func(input *app.ComponentInput) app.ComponentReference {
				input.Resolver = pipelineResolver
				input.Use(repo)
				input.ExpectToBuild = true
				repo.UsedBy(input)
				repo.SetStrategy(newapp.StrategyPipeline)
				return input
			})
			result = append(result, refs...)

		case info.Dockerfile != nil && (g.Strategy == newapp.StrategyUnspecified || g.Strategy == newapp.StrategyDocker):
			node := info.Dockerfile.AST()
			baseImage := dockerfileutil.LastBaseImage(node)
			if baseImage == "" {
				errs = append(errs, fmt.Errorf("the Dockerfile in the repository %q has no FROM instruction", info.Path))
				continue
			}
			refs := b.AddComponents([]string{baseImage}, func(input *app.ComponentInput) app.ComponentReference {
				input.Resolver = dockerfileResolver
				input.Use(repo)
				input.ExpectToBuild = true
				repo.UsedBy(input)
				repo.SetStrategy(newapp.StrategyDocker)
				return input
			})
			result = append(result, refs...)

		default:
			// TODO: Add support for searching for more than one language if len(info.Types) > 1
			if len(info.Types) == 0 {
				errs = append(errs, fmt.Errorf("no language was detected for repository at %q; please specify a builder image to use with your repository: [builder-image]~%s", repo, repo))

				continue
			}
			refs := b.AddComponents([]string{info.Types[0].Term()}, func(input *app.ComponentInput) app.ComponentReference {
				input.Resolver = sourceResolver
				input.ExpectToBuild = true
				input.Use(repo)
				repo.UsedBy(input)
				return input
			})
			result = append(result, refs...)
		}
	}
	return result, kutilerrors.NewAggregate(errs)
}
95710
func (s *SourceService) CreateSource(ctx context.Context, source *platform.Source) error {
	return s.CreateSourceFn(ctx, source)
}
1195141
func AddSourceRepositoriesToRefBuilder(b *app.ReferenceBuilder, c *ComponentInputs, g *GenerationInputs, s, i *[]string) (app.SourceRepositories, error) {
	strategy := g.Strategy
	if strategy == newapp.StrategyUnspecified {
		strategy = newapp.StrategySource
	}
	// when git is installed we keep default logic. sourcelookup.go will do sorting of images, repos
	if git.IsGitInstalled() || len(c.SourceRepositories) > 0 {
		for _, s := range c.SourceRepositories {
			if repo, ok := b.AddSourceRepository(s, strategy); ok {
				repo.SetContextDir(g.ContextDir)
			}
		}
		// when git is not installed we need to parse some logic to decide if we got 'new-app -i image code' or 'image -c code' syntax
	} else if len(c.Components) > 0 && len(*i) > 0 && len(*s) == 0 || len(c.Components) > 0 && len(*i) == 0 && len(*s) > 0 {
		for _, s := range c.Components {
			if repo, ok := b.AddSourceRepository(s, strategy); ok {
				repo.SetContextDir(g.ContextDir)
				c.Components = []string{}
			}
		}
	}
	if len(g.Dockerfile) > 0 {
		if g.Strategy != newapp.StrategyUnspecified && g.Strategy != newapp.StrategyDocker {
			return nil, errors.New("when directly referencing a Dockerfile, the strategy must must be 'docker'")
		}
		if err := AddDockerfileToSourceRepositories(b, g.Dockerfile); err != nil {
			return nil, err
		}
	}
	_, result, errs := b.Result()
	return result, kutilerrors.NewAggregate(errs)
}
646382
func (s *Service) CreateSource(ctx context.Context, src *platform.Source) error {
	src.ID = s.IDGenerator.ID()
	if err := s.PutSource(ctx, src); err != nil {
		return &platform.Error{
			Err: err,
		}
	}
	return nil
}
823564
func ProjectTokenSource(proj string, scopes ...string) (oauth2.TokenSource, error) {
	// TODO(bradfitz): try different strategies too, like
	// three-legged flow if the service account doesn't exist, and
	// then cache the token file on disk somewhere. Or maybe that should be an
	// option, for environments without stdin/stdout available to the user.
	// We'll figure it out as needed.
	fileName := filepath.Join(homedir(), "keys", proj+".key.json")
	jsonConf, err := ioutil.ReadFile(fileName)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, fmt.Errorf("Missing JSON key configuration. Download the Service Account JSON key from https://console.developers.google.com/project/%s/apiui/credential and place it at %s", proj, fileName)
		}
		return nil, err
	}
	conf, err := google.JWTConfigFromJSON(jsonConf, scopes...)
	if err != nil {
		return nil, fmt.Errorf("reading JSON config from %s: %v", fileName, err)
	}
	return conf.TokenSource(oauth2.NoContext), nil
}
880982
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
	switch resource {
	// Group=wardle.k8s.io, Version=v1alpha1
	case v1alpha1.SchemeGroupVersion.WithResource("fischers"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Wardle().V1alpha1().Fischers().Informer()}, nil
	case v1alpha1.SchemeGroupVersion.WithResource("flunders"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Wardle().V1alpha1().Flunders().Informer()}, nil

		// Group=wardle.k8s.io, Version=v1beta1
	case v1beta1.SchemeGroupVersion.WithResource("flunders"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Wardle().V1beta1().Flunders().Informer()}, nil

	}

	return nil, fmt.Errorf("no informer found for %v", resource)
}
734677
func Convert_v1_GitSourceRevision_To_build_GitSourceRevision(in *v1.GitSourceRevision, out *build.GitSourceRevision, s conversion.Scope) error {
	return autoConvert_v1_GitSourceRevision_To_build_GitSourceRevision(in, out, s)
}
278062
func BuildSource(s string) *Source {
	var result []string
	var lineBuf bytes.Buffer
	for _, runeValue := range s {
		lineBuf.WriteRune(runeValue)
		if runeValue == '\n' {
			result = append(result, lineBuf.String())
			lineBuf.Reset()
		}
	}
	rest := lineBuf.String()
	// Stuff after last end-of-line (EOF or some more code)
	result = append(result, rest+"\n")
	return &Source{result}
}
1042473
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
	switch resource {
	// Group=traefik.containo.us, Version=v1alpha1
	case v1alpha1.SchemeGroupVersion.WithResource("ingressroutes"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().IngressRoutes().Informer()}, nil
	case v1alpha1.SchemeGroupVersion.WithResource("middlewares"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().Middlewares().Informer()}, nil

	}

	return nil, fmt.Errorf("no informer found for %v", resource)
}
382517
func (t *TeamLDAPMapping) GetRepositoriesURL() string {
	if t == nil || t.RepositoriesURL == nil {
		return ""
	}
	return *t.RepositoriesURL
}
163464
func (iamRes *IAMBuilder) ForResource() *IAMResourceBuilder {
	return &IAMResourceBuilder{
		builder:       iamRes,
		resourceParts: make([]gocf.Stringable, 0),
	}
}
28018
func (ctx *ResourceTransformationCtx) PublishSourceMap(content string) error {
	target := ctx.OutPath + ".map"
	f, err := ctx.OpenResourcePublisher(target)
	if err != nil {
		return err
	}
	defer f.Close()
	_, err = f.Write([]byte(content))
	return err
}