Skip to content

Commit

Permalink
Allow access to go internal modules (#12312)
Browse files Browse the repository at this point in the history
* Allow access to go internal modules

* Add unit test for SetUseGoInternalModules
  • Loading branch information
KacperMalachowski authored Nov 12, 2024
1 parent b719fc6 commit fd0d938
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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

0 comments on commit fd0d938

Please sign in to comment.