Skip to content

Commit

Permalink
chore: Remove git-remote flag (#96)
Browse files Browse the repository at this point in the history
* remove git-remote flag

* adapt tests
  • Loading branch information
lindnerby authored Nov 6, 2024
1 parent 17493ed commit 2dbaec7
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 42 deletions.
4 changes: 0 additions & 4 deletions cmd/modulectl/create/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func Test_Execute_ReturnsError_WhenModuleServiceReturnsError(t *testing.T) {
func Test_Execute_ParsesAllModuleOptions(t *testing.T) {
moduleConfigFile := testutils.RandomName(10)
credentials := testutils.RandomName(10)
gitRemote := testutils.RandomName(10)
insecure := "true"
templateOutput := testutils.RandomName(10)
registryURL := testutils.RandomName(10)
Expand All @@ -57,7 +56,6 @@ func Test_Execute_ParsesAllModuleOptions(t *testing.T) {
os.Args = []string{
"create",
"--config-file", moduleConfigFile,
"--git-remote", gitRemote,
"--insecure", insecure,
"--output", templateOutput,
"--registry", registryURL,
Expand All @@ -76,7 +74,6 @@ func Test_Execute_ParsesAllModuleOptions(t *testing.T) {

assert.Equal(t, moduleConfigFile, svc.opts.ConfigFile)
assert.Equal(t, credentials, svc.opts.Credentials)
assert.Equal(t, gitRemote, svc.opts.GitRemote)
assert.Equal(t, insecureFlagSet, svc.opts.Insecure)
assert.Equal(t, templateOutput, svc.opts.TemplateOutput)
assert.Equal(t, registryURL, svc.opts.RegistryURL)
Expand Down Expand Up @@ -119,7 +116,6 @@ func Test_Execute_ModuleParsesDefaults(t *testing.T) {

assert.Equal(t, createcmd.ConfigFileFlagDefault, svc.opts.ConfigFile)
assert.Equal(t, createcmd.CredentialsFlagDefault, svc.opts.Credentials)
assert.Equal(t, createcmd.GitRemoteFlagDefault, svc.opts.GitRemote)
assert.Equal(t, createcmd.InsecureFlagDefault, svc.opts.Insecure)
assert.Equal(t, createcmd.TemplateOutputFlagDefault, svc.opts.TemplateOutput)
assert.Equal(t, createcmd.RegistryURLFlagDefault, svc.opts.RegistryURL)
Expand Down
5 changes: 0 additions & 5 deletions cmd/modulectl/create/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ const (
CredentialsFlagDefault = ""
credentialsFlagUsage = "Basic authentication credentials for the given repository in the <user:password> format."

GitRemoteFlagName = "git-remote"
GitRemoteFlagDefault = ""
gitRemoteFlagUsage = "Specifies the URL of the module's GitHub repository. "

InsecureFlagName = "insecure"
InsecureFlagDefault = false
insecureFlagUsage = "Uses an insecure connection to access the registry."
Expand All @@ -46,7 +42,6 @@ func parseFlags(flags *pflag.FlagSet, opts *create.Options) {
configFileFlagUsage)
flags.StringVar(&opts.Credentials, CredentialsFlagName, CredentialsFlagDefault,
credentialsFlagUsage)
flags.StringVar(&opts.GitRemote, GitRemoteFlagName, GitRemoteFlagDefault, gitRemoteFlagUsage)
flags.BoolVar(&opts.Insecure, InsecureFlagName, InsecureFlagDefault, insecureFlagUsage)
flags.StringVarP(&opts.TemplateOutput, TemplateOutputFlagName, templateOutputFlagShort, TemplateOutputFlagDefault,
templateOutputFlagUsage)
Expand Down
1 change: 0 additions & 1 deletion cmd/modulectl/create/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func Test_ScaffoldFlagsDefaults(t *testing.T) {
expected: "module-config.yaml",
},
{name: createcmd.CredentialsFlagName, value: createcmd.CredentialsFlagDefault, expected: ""},
{name: createcmd.GitRemoteFlagName, value: createcmd.GitRemoteFlagDefault, expected: ""},
{name: createcmd.InsecureFlagName, value: strconv.FormatBool(createcmd.InsecureFlagDefault), expected: "false"},
{name: createcmd.TemplateOutputFlagName, value: createcmd.TemplateOutputFlagDefault, expected: "template.yaml"},
{name: createcmd.RegistryURLFlagName, value: createcmd.RegistryURLFlagDefault, expected: ""},
Expand Down
1 change: 0 additions & 1 deletion docs/gen-docs/modulectl_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Build a simple module and push it to a remote registry

```bash
-c, --config-file string Specifies the path to the module configuration file.
--git-remote string Specifies the URL of the module's GitHub repository.
-h, --help Provides help for the create command.
--insecure Uses an insecure connection to access the registry.
-o, --output string Path to write the ModuleTemplate file to, if the module is uploaded to a registry (default "template.yaml").
Expand Down
20 changes: 9 additions & 11 deletions internal/service/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,14 @@ func (s *Service) Run(opts Options) error {
return fmt.Errorf("failed to generate module resources: %w", err)
}

if opts.GitRemote != "" {
if err = s.gitSourcesService.AddGitSources(descriptor, opts.GitRemote,
moduleConfig.Version); err != nil {
return fmt.Errorf("failed to add git sources: %w", err)
}
if moduleConfig.Security != "" {
err = s.configureSecScannerConf(descriptor, moduleConfig, opts)
if err != nil {
return fmt.Errorf("failed to configure security scanners: %w", err)
}
if err = s.gitSourcesService.AddGitSources(descriptor, moduleConfig.Repository,
moduleConfig.Version); err != nil {
return fmt.Errorf("failed to add git sources: %w", err)
}
if moduleConfig.Security != "" {
err = s.configureSecScannerConf(descriptor, moduleConfig, opts)
if err != nil {
return fmt.Errorf("failed to configure security scanners: %w", err)
}
}

Expand Down Expand Up @@ -248,7 +246,7 @@ func (s *Service) pushImgAndCreateTemplate(archive *comparch.ComponentArchive, m

func (s *Service) configureSecScannerConf(descriptor *compdesc.ComponentDescriptor, moduleConfig *contentprovider.ModuleConfig, opts Options) error {
opts.Out.Write("- Configuring security scanners config\n")
securityConfig, err := s.securityConfigService.ParseSecurityConfigData(opts.GitRemote, moduleConfig.Security)
securityConfig, err := s.securityConfigService.ParseSecurityConfigData(moduleConfig.Repository, moduleConfig.Security)
if err != nil {
return fmt.Errorf("%w: failed to parse security config data", err)
}
Expand Down
6 changes: 0 additions & 6 deletions internal/service/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func newCreateOptionsBuilder() *createOptionsBuilder {
withOut(iotools.NewDefaultOut(io.Discard)).
withModuleConfigFile("create-module-config.yaml").
withRegistryURL("https://registry.kyma.cx").
withGitRemote("http://github.com/kyma-project").
withTemplateOutput("test").
withCredentials("user:password")
}
Expand All @@ -162,11 +161,6 @@ func (b *createOptionsBuilder) withRegistryURL(registryURL string) *createOption
return b
}

func (b *createOptionsBuilder) withGitRemote(gitRemote string) *createOptionsBuilder {
b.options.GitRemote = gitRemote
return b
}

func (b *createOptionsBuilder) withTemplateOutput(templateOutput string) *createOptionsBuilder {
b.options.TemplateOutput = templateOutput
return b
Expand Down
1 change: 0 additions & 1 deletion internal/service/create/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Options struct {
Out iotools.Out
ConfigFile string
Credentials string
GitRemote string
Insecure bool
TemplateOutput string
RegistryURL string
Expand Down
3 changes: 0 additions & 3 deletions internal/service/create/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func Test_Validate_Options(t *testing.T) {
Out: iotools.NewDefaultOut(io.Discard),
ConfigFile: "config.yaml",
Credentials: "username:password",
GitRemote: "github.com/kyma-project/modulectl",
TemplateOutput: "",
},
wantErr: true,
Expand All @@ -62,7 +61,6 @@ func Test_Validate_Options(t *testing.T) {
Out: iotools.NewDefaultOut(io.Discard),
ConfigFile: "config.yaml",
Credentials: "username:password",
GitRemote: "github.com/kyma-project/modulectl",
TemplateOutput: "output",
RegistryURL: "http://registry.example.com",
},
Expand All @@ -74,7 +72,6 @@ func Test_Validate_Options(t *testing.T) {
Out: iotools.NewDefaultOut(io.Discard),
ConfigFile: "config.yaml",
Credentials: "username:password",
GitRemote: "origin",
TemplateOutput: "output",
RegistryURL: "ftp://registry.example.com",
},
Expand Down
6 changes: 0 additions & 6 deletions tests/e2e/create/create_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const (

ociRegistry = "http://k3d-oci.localhost:5001"
templateOutputPath = "/tmp/template.yaml"
gitRemote = "https://github.com/kyma-project/template-operator"
)

// Command wrapper for `modulectl create`
Expand All @@ -62,7 +61,6 @@ type createCmd struct {
registry string
output string
moduleConfigFile string
gitRemote string
insecure bool
}

Expand All @@ -83,10 +81,6 @@ func (cmd *createCmd) execute() error {
args = append(args, "--output="+cmd.output)
}

if cmd.gitRemote != "" {
args = append(args, "--git-remote="+cmd.gitRemote)
}

if cmd.insecure {
args = append(args, "--insecure")
}
Expand Down
14 changes: 10 additions & 4 deletions tests/e2e/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,15 @@ var _ = Describe("Test 'create' command", Ordered, func() {
Expect(localBlobAccessSpec.LocalReference).To(ContainSubstring("sha256:"))
Expect(localBlobAccessSpec.MediaType).To(Equal("application/x-tar"))

By("And descriptor.component.sources should be empty")
Expect(len(descriptor.Sources)).To(Equal(0))
By("And descriptor.component.sources should contain repository entry")
Expect(len(descriptor.Sources)).To(Equal(1))
source := descriptor.Sources[0]
sourceAccessSpec, err := ocm.DefaultContext().AccessSpecForSpec(source.Access)
Expect(err).ToNot(HaveOccurred())
githubAccessSpec, ok := sourceAccessSpec.(*github.AccessSpec)
Expect(ok).To(BeTrue())
Expect(github.Type).To(Equal(githubAccessSpec.Type))
Expect(githubAccessSpec.RepoURL).To(Equal("https://github.com/kyma-project/template-operator"))

By("And spec.mandatory should be false")
Expect(template.Spec.Mandatory).To(BeFalse())
Expand Down Expand Up @@ -456,14 +463,13 @@ var _ = Describe("Test 'create' command", Ordered, func() {

Context("Given 'modulectl create' command", func() {
var cmd createCmd
It("When invoked with valid module-config containing security-scanner-config and different version, and the git-remote flag",
It("When invoked with valid module-config containing security-scanner-config and different version",
func() {
cmd = createCmd{
moduleConfigFile: withSecurityConfig,
registry: ociRegistry,
insecure: true,
output: templateOutputPath,
gitRemote: gitRemote,
}
})
It("Then the command should succeed", func() {
Expand Down

0 comments on commit 2dbaec7

Please sign in to comment.