Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to go internal modules #12312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type options struct {
debug bool
dryRun bool
tagsOutputFile string
useGoInternalModules bool
}

type Logger interface {
Expand Down Expand Up @@ -256,6 +257,10 @@ func prepareADOTemplateParameters(options options) (adopipelines.OCIImageBuilder
templateParameters.SetAuthorization(options.oidcToken)
}

if options.useGoInternalModules {
templateParameters.SetUseGoInternalModules()
}

err := templateParameters.Validate()
if err != nil {
return nil, fmt.Errorf("failed validating ADO template parameters, err: %w", err)
Expand Down Expand Up @@ -833,6 +838,7 @@ func (o *options) gatherOptions(flagSet *flag.FlagSet) *flag.FlagSet {
flagSet.StringVar(&o.oidcToken, "oidc-token", "", "Token used to authenticate against Azure DevOps backend service")
flagSet.StringVar(&o.azureAccessToken, "azure-access-token", "", "Token used to authenticate against Azure DevOps API")
flagSet.StringVar(&o.tagsOutputFile, "tags-output-file", "/generated-tags.json", "Path to file where generated tags will be written as JSON")
flagSet.BoolVar(&o.useGoInternalModules, "use-go-internal-modules", false, "Allow access to Go internal modules in ADO backend")

return flagSet
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/azuredevops/pipelines/templatesParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ func (p OCIImageBuilderTemplateParams) SetAuthorization(authorizationToken strin
p["Authorization"] = authorizationToken
}

// SetUseGoInternalModules sets UseGoInternalModules parameter.
// This parameter is used to setup access to internal Go modules.
// Modules are fetched with go mod vendor command.
func (p OCIImageBuilderTemplateParams) SetUseGoInternalModules() {
p["UseGoInternalModules"] = "true"
}

// Validate validates if required OCIImageBuilderTemplateParams are set.
// Returns ErrRequiredParamNotSet error if any required parameter is not set.
func (p OCIImageBuilderTemplateParams) Validate() error {
Expand Down
5 changes: 5 additions & 0 deletions pkg/azuredevops/pipelines/templatesParams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ var _ = Describe("Test OCIImageBuilderTemplateParams", func() {
Expect(params["Authorization"]).To(Equal("some-token"))
})

It("sets the correct useGoInternalModules", func() {
params.SetUseGoInternalModules()
Expect(params["UseGoInternalModules"]).To(Equal("true"))
})

// TODO: Improve assertions with more specific matchers and values.
It("validates the params correctly", func() {
// Set all required parameters
Expand Down
Loading