diff --git a/cmd/repo_create.go b/cmd/repo_create.go index 675401303..e04e6b90b 100644 --- a/cmd/repo_create.go +++ b/cmd/repo_create.go @@ -18,6 +18,14 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error { repo.DefaultDistribution = context.Flags().Lookup("distribution").Value.String() repo.DefaultComponent = context.Flags().Lookup("component").Value.String() + uploadersFile := context.Flags().Lookup("uploaders-file").Value.Get().(string) + if uploadersFile != "" { + repo.Uploaders, err = deb.NewUploadersFromFile(uploadersFile) + if err != nil { + return err + } + } + err = context.CollectionFactory().LocalRepoCollection().Add(repo) if err != nil { return fmt.Errorf("unable to add local repo: %s", err) @@ -47,6 +55,7 @@ Example: cmd.Flag.String("comment", "", "any text that would be used to described local repository") cmd.Flag.String("distribution", "", "default distribution when publishing") cmd.Flag.String("component", "main", "default component when publishing") + cmd.Flag.String("uploaders-file", "", "uploaders.json to be used when including .changes into this repository") return cmd } diff --git a/cmd/repo_edit.go b/cmd/repo_edit.go index 648382b75..018374b49 100644 --- a/cmd/repo_edit.go +++ b/cmd/repo_edit.go @@ -2,6 +2,8 @@ package cmd import ( "fmt" + "github.com/AlekSi/pointer" + "github.com/smira/aptly/deb" "github.com/smira/commander" "github.com/smira/flag" ) @@ -23,16 +25,30 @@ func aptlyRepoEdit(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to edit: %s", err) } - if context.Flags().Lookup("comment").Value.String() != "" { - repo.Comment = context.Flags().Lookup("comment").Value.String() - } + var uploadersFile *string - if context.Flags().Lookup("distribution").Value.String() != "" { - repo.DefaultDistribution = context.Flags().Lookup("distribution").Value.String() - } + context.Flags().Visit(func(flag *flag.Flag) { + switch flag.Name { + case "comment": + repo.Comment = flag.Value.String() + case "distribution": + repo.DefaultDistribution = flag.Value.String() + case "component": + repo.DefaultComponent = flag.Value.String() + case "uploaders-file": + uploadersFile = pointer.ToString(flag.Value.String()) + } + }) - if context.Flags().Lookup("component").Value.String() != "" { - repo.DefaultComponent = context.Flags().Lookup("component").Value.String() + if uploadersFile != nil { + if *uploadersFile != "" { + repo.Uploaders, err = deb.NewUploadersFromFile(*uploadersFile) + if err != nil { + return err + } + } else { + repo.Uploaders = nil + } } err = context.CollectionFactory().LocalRepoCollection().Update(repo) @@ -63,6 +79,7 @@ Example: cmd.Flag.String("comment", "", "any text that would be used to described local repository") cmd.Flag.String("distribution", "", "default distribution when publishing") cmd.Flag.String("component", "", "default component when publishing") + cmd.Flag.String("uploaders-file", "", "uploaders.json to be used when including .changes into this repository") return cmd } diff --git a/cmd/repo_show.go b/cmd/repo_show.go index a6ee9804d..89a599db4 100644 --- a/cmd/repo_show.go +++ b/cmd/repo_show.go @@ -29,6 +29,9 @@ func aptlyRepoShow(cmd *commander.Command, args []string) error { fmt.Printf("Comment: %s\n", repo.Comment) fmt.Printf("Default Distribution: %s\n", repo.DefaultDistribution) fmt.Printf("Default Component: %s\n", repo.DefaultComponent) + if repo.Uploaders != nil { + fmt.Printf("Uploaders: %s\n", repo.Uploaders) + } fmt.Printf("Number of packages: %d\n", repo.NumPackages()) withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool) diff --git a/system/t09_repo/CreateRepo4Test_gold b/system/t09_repo/CreateRepo4Test_gold new file mode 100644 index 000000000..02c678bf7 --- /dev/null +++ b/system/t09_repo/CreateRepo4Test_gold @@ -0,0 +1,3 @@ + +Local repo [repo4] successfully added. +You can run 'aptly repo add repo4 ...' to add packages to repository. diff --git a/system/t09_repo/CreateRepo4Test_repo_show b/system/t09_repo/CreateRepo4Test_repo_show new file mode 100644 index 000000000..bdee25b71 --- /dev/null +++ b/system/t09_repo/CreateRepo4Test_repo_show @@ -0,0 +1,6 @@ +Name: repo4 +Comment: +Default Distribution: +Default Component: main +Uploaders: {"groups":{"developers":["21DBB89C16DB3E6D","37E1C17570096AD1"]},"rules":[{"condition":"Source (dangerous) | Source (kernel)","allow":null,"deny":["*"]},{"condition":"Source (hardlink)","allow":["developers","admins"],"deny":null}]} +Number of packages: 0 diff --git a/system/t09_repo/CreateRepo5Test_gold b/system/t09_repo/CreateRepo5Test_gold new file mode 100644 index 000000000..fdab9a7eb --- /dev/null +++ b/system/t09_repo/CreateRepo5Test_gold @@ -0,0 +1 @@ +ERROR: error loading uploaders file: unexpected EOF diff --git a/system/t09_repo/CreateRepo6Test_gold b/system/t09_repo/CreateRepo6Test_gold new file mode 100644 index 000000000..4065f97fe --- /dev/null +++ b/system/t09_repo/CreateRepo6Test_gold @@ -0,0 +1 @@ +ERROR: error loading uploaders file: open /uploaders-not-found.json: no such file or directory diff --git a/system/t09_repo/EditRepo4Test_gold b/system/t09_repo/EditRepo4Test_gold new file mode 100644 index 000000000..7f6337c1e --- /dev/null +++ b/system/t09_repo/EditRepo4Test_gold @@ -0,0 +1 @@ +Local repo [repo4] successfully updated. diff --git a/system/t09_repo/EditRepo4Test_repo_show b/system/t09_repo/EditRepo4Test_repo_show new file mode 100644 index 000000000..bdee25b71 --- /dev/null +++ b/system/t09_repo/EditRepo4Test_repo_show @@ -0,0 +1,6 @@ +Name: repo4 +Comment: +Default Distribution: +Default Component: main +Uploaders: {"groups":{"developers":["21DBB89C16DB3E6D","37E1C17570096AD1"]},"rules":[{"condition":"Source (dangerous) | Source (kernel)","allow":null,"deny":["*"]},{"condition":"Source (hardlink)","allow":["developers","admins"],"deny":null}]} +Number of packages: 0 diff --git a/system/t09_repo/EditRepo5Test_gold b/system/t09_repo/EditRepo5Test_gold new file mode 100644 index 000000000..fdab9a7eb --- /dev/null +++ b/system/t09_repo/EditRepo5Test_gold @@ -0,0 +1 @@ +ERROR: error loading uploaders file: unexpected EOF diff --git a/system/t09_repo/EditRepo6Test_gold b/system/t09_repo/EditRepo6Test_gold new file mode 100644 index 000000000..4065f97fe --- /dev/null +++ b/system/t09_repo/EditRepo6Test_gold @@ -0,0 +1 @@ +ERROR: error loading uploaders file: open /uploaders-not-found.json: no such file or directory diff --git a/system/t09_repo/EditRepo7Test_gold b/system/t09_repo/EditRepo7Test_gold new file mode 100644 index 000000000..b1b50430b --- /dev/null +++ b/system/t09_repo/EditRepo7Test_gold @@ -0,0 +1 @@ +Local repo [repo7] successfully updated. diff --git a/system/t09_repo/EditRepo7Test_repo_show b/system/t09_repo/EditRepo7Test_repo_show new file mode 100644 index 000000000..25d60afbf --- /dev/null +++ b/system/t09_repo/EditRepo7Test_repo_show @@ -0,0 +1,5 @@ +Name: repo7 +Comment: +Default Distribution: +Default Component: main +Number of packages: 0 diff --git a/system/t09_repo/create.py b/system/t09_repo/create.py index 3abd9c6f7..3112dc588 100644 --- a/system/t09_repo/create.py +++ b/system/t09_repo/create.py @@ -1,6 +1,11 @@ +import os +import inspect from lib import BaseTest +changesRemove = lambda _, s: s.replace(os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "changes"), "") + + class CreateRepo1Test(BaseTest): """ create local repo: regular repo @@ -30,3 +35,31 @@ class CreateRepo3Test(BaseTest): fixtureCmds = ["aptly repo create repo3"] runCmd = "aptly repo create -comment=Repository3 repo3" expectedCode = 1 + + +class CreateRepo4Test(BaseTest): + """ + create local repo: with uploaders.json + """ + runCmd = "aptly repo create -uploaders-file=${changes}/uploaders2.json repo4" + + def check(self): + self.check_output() + self.check_cmd_output("aptly repo show repo4", "repo_show") + + +class CreateRepo5Test(BaseTest): + """ + create local repo: with broken uploaders.json + """ + runCmd = "aptly repo create -uploaders-file=${changes}/uploaders3.json repo5" + expectedCode = 1 + + +class CreateRepo6Test(BaseTest): + """ + create local repo: with missing uploaders.json + """ + runCmd = "aptly repo create -uploaders-file=${changes}/uploaders-not-found.json repo6" + expectedCode = 1 + outputMatchPrepare = changesRemove diff --git a/system/t09_repo/edit.py b/system/t09_repo/edit.py index 075fcf89d..55e56985f 100644 --- a/system/t09_repo/edit.py +++ b/system/t09_repo/edit.py @@ -1,6 +1,11 @@ +import os +import inspect from lib import BaseTest +changesRemove = lambda _, s: s.replace(os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "changes"), "") + + class EditRepo1Test(BaseTest): """ edit repo: change comment @@ -35,3 +40,54 @@ class EditRepo3Test(BaseTest): """ runCmd = "aptly repo edit repo3" expectedCode = 1 + + +class EditRepo4Test(BaseTest): + """ + edit repo: add uploaders.json + """ + fixtureCmds = [ + "aptly repo create repo4", + ] + runCmd = "aptly repo edit -uploaders-file=${changes}/uploaders2.json repo4" + + def check(self): + self.check_output() + self.check_cmd_output("aptly repo show repo4", "repo_show") + + +class EditRepo5Test(BaseTest): + """ + edit repo: with broken uploaders.json + """ + fixtureCmds = [ + "aptly repo create repo5", + ] + runCmd = "aptly repo edit -uploaders-file=${changes}/uploaders3.json repo5" + expectedCode = 1 + + +class EditRepo6Test(BaseTest): + """ + edit local repo: with missing uploaders.json + """ + fixtureCmds = [ + "aptly repo create repo6", + ] + runCmd = "aptly repo edit -uploaders-file=${changes}/uploaders-not-found.json repo6" + expectedCode = 1 + outputMatchPrepare = changesRemove + + +class EditRepo7Test(BaseTest): + """ + edit local repo: remove uploaders.json + """ + fixtureCmds = [ + "aptly repo create -uploaders-file=${changes}/uploaders2.json repo7", + ] + runCmd = "aptly repo edit -uploaders-file= repo7" + + def check(self): + self.check_output() + self.check_cmd_output("aptly repo show repo7", "repo_show")