mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Support for per-repo uploader.json in aptly repo commands. #71
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
3
system/t09_repo/CreateRepo4Test_gold
Normal file
3
system/t09_repo/CreateRepo4Test_gold
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
Local repo [repo4] successfully added.
|
||||
You can run 'aptly repo add repo4 ...' to add packages to repository.
|
||||
6
system/t09_repo/CreateRepo4Test_repo_show
Normal file
6
system/t09_repo/CreateRepo4Test_repo_show
Normal file
@@ -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
|
||||
1
system/t09_repo/CreateRepo5Test_gold
Normal file
1
system/t09_repo/CreateRepo5Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
ERROR: error loading uploaders file: unexpected EOF
|
||||
1
system/t09_repo/CreateRepo6Test_gold
Normal file
1
system/t09_repo/CreateRepo6Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
ERROR: error loading uploaders file: open /uploaders-not-found.json: no such file or directory
|
||||
1
system/t09_repo/EditRepo4Test_gold
Normal file
1
system/t09_repo/EditRepo4Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
Local repo [repo4] successfully updated.
|
||||
6
system/t09_repo/EditRepo4Test_repo_show
Normal file
6
system/t09_repo/EditRepo4Test_repo_show
Normal file
@@ -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
|
||||
1
system/t09_repo/EditRepo5Test_gold
Normal file
1
system/t09_repo/EditRepo5Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
ERROR: error loading uploaders file: unexpected EOF
|
||||
1
system/t09_repo/EditRepo6Test_gold
Normal file
1
system/t09_repo/EditRepo6Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
ERROR: error loading uploaders file: open /uploaders-not-found.json: no such file or directory
|
||||
1
system/t09_repo/EditRepo7Test_gold
Normal file
1
system/t09_repo/EditRepo7Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
Local repo [repo7] successfully updated.
|
||||
5
system/t09_repo/EditRepo7Test_repo_show
Normal file
5
system/t09_repo/EditRepo7Test_repo_show
Normal file
@@ -0,0 +1,5 @@
|
||||
Name: repo7
|
||||
Comment:
|
||||
Default Distribution:
|
||||
Default Component: main
|
||||
Number of packages: 0
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user