Skip to content

Commit

Permalink
Support for per-repo uploader.json in aptly repo commands. #71
Browse files Browse the repository at this point in the history
  • Loading branch information
smira committed Mar 22, 2015
1 parent a160a39 commit 8b782ce
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 8 deletions.
9 changes: 9 additions & 0 deletions cmd/repo_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
33 changes: 25 additions & 8 deletions cmd/repo_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions cmd/repo_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions system/t09_repo/CreateRepo4Test_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Local repo [repo4] successfully added.
You can run 'aptly repo add repo4 ...' to add packages to repository.
6 changes: 6 additions & 0 deletions system/t09_repo/CreateRepo4Test_repo_show
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions system/t09_repo/CreateRepo5Test_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR: error loading uploaders file: unexpected EOF
1 change: 1 addition & 0 deletions system/t09_repo/CreateRepo6Test_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR: error loading uploaders file: open /uploaders-not-found.json: no such file or directory
1 change: 1 addition & 0 deletions system/t09_repo/EditRepo4Test_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Local repo [repo4] successfully updated.
6 changes: 6 additions & 0 deletions system/t09_repo/EditRepo4Test_repo_show
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions system/t09_repo/EditRepo5Test_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR: error loading uploaders file: unexpected EOF
1 change: 1 addition & 0 deletions system/t09_repo/EditRepo6Test_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR: error loading uploaders file: open /uploaders-not-found.json: no such file or directory
1 change: 1 addition & 0 deletions system/t09_repo/EditRepo7Test_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Local repo [repo7] successfully updated.
5 changes: 5 additions & 0 deletions system/t09_repo/EditRepo7Test_repo_show
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name: repo7
Comment:
Default Distribution:
Default Component: main
Number of packages: 0
33 changes: 33 additions & 0 deletions system/t09_repo/create.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
56 changes: 56 additions & 0 deletions system/t09_repo/edit.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")

0 comments on commit 8b782ce

Please sign in to comment.