From 2d0d2118402d98a1dfd324f53411576e9e8b16e1 Mon Sep 17 00:00:00 2001 From: Zhang Xiao Date: Wed, 20 Aug 2025 09:14:21 +0000 Subject: [PATCH] Support updating label and origin domain of publish Signed-off-by: Zhang Xiao --- api/publish.go | 24 +++++++++++++++++++ cmd/publish_update.go | 10 ++++++++ system/t06_publish/PublishUpdate19Test_gold | 9 +++++++ .../t06_publish/PublishUpdate19Test_release | 11 +++++++++ system/t06_publish/update.py | 22 +++++++++++++++++ system/t12_api/publish.py | 12 ++++++---- 6 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 system/t06_publish/PublishUpdate19Test_gold create mode 100644 system/t06_publish/PublishUpdate19Test_release diff --git a/api/publish.go b/api/publish.go index 1a2b5287bb..2b63389c80 100644 --- a/api/publish.go +++ b/api/publish.go @@ -378,6 +378,10 @@ type publishedRepoUpdateSwitchParams struct { AcquireByHash *bool ` json:"AcquireByHash" example:"false"` // Enable multiple packages with the same filename in different distributions MultiDist *bool ` json:"MultiDist" example:"false"` + // Value of Label: field in published repository stanza + Label *string ` json:"Label" example:"Debian"` + // Value of Origin: field in published repository stanza + Origin *string ` json:"Origin" example:"Debian"` } // @Summary Update Published Repository @@ -466,6 +470,14 @@ func apiPublishUpdateSwitch(c *gin.Context) { published.MultiDist = *b.MultiDist } + if b.Label != nil { + published.Label = *b.Label + } + + if b.Origin != nil { + published.Origin = *b.Origin + } + resources := []string{string(published.Key())} taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution) maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) { @@ -957,6 +969,10 @@ type publishedRepoUpdateParams struct { AcquireByHash *bool ` json:"AcquireByHash" example:"false"` // Enable multiple packages with the same filename in different distributions MultiDist *bool ` json:"MultiDist" example:"false"` + // Value of Label: field in published repository stanza + Label *string ` json:"Label" example:"Debian"` + // Value of Origin: field in published repository stanza + Origin *string ` json:"Origin" example:"Debian"` } // @Summary Update Published Repository @@ -1025,6 +1041,14 @@ func apiPublishUpdate(c *gin.Context) { published.MultiDist = *b.MultiDist } + if b.Label != nil { + published.Label = *b.Label + } + + if b.Origin != nil { + published.Origin = *b.Origin + } + resources := []string{string(published.Key())} taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution) maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) { diff --git a/cmd/publish_update.go b/cmd/publish_update.go index 6ea638d41f..64f09c4e1a 100644 --- a/cmd/publish_update.go +++ b/cmd/publish_update.go @@ -60,6 +60,14 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error { published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool) } + if context.Flags().IsSet("origin") { + published.Origin = context.Flags().Lookup("origin").Value.String() + } + + if context.Flags().IsSet("label") { + published.Label = context.Flags().Lookup("label").Value.String() + } + if context.Flags().IsSet("multi-dist") { published.MultiDist = context.Flags().Lookup("multi-dist").Value.Get().(bool) } @@ -127,6 +135,8 @@ Example: cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch") cmd.Flag.Bool("skip-cleanup", false, "don't remove unreferenced files in prefix/component") cmd.Flag.Bool("multi-dist", false, "enable multiple packages with the same filename in different distributions") + cmd.Flag.String("origin", "", "overwrite origin name to publish") + cmd.Flag.String("label", "", "overwrite label to publish") return cmd } diff --git a/system/t06_publish/PublishUpdate19Test_gold b/system/t06_publish/PublishUpdate19Test_gold new file mode 100644 index 0000000000..040bcc133c --- /dev/null +++ b/system/t06_publish/PublishUpdate19Test_gold @@ -0,0 +1,9 @@ +Loading packages... +Generating metadata files and linking package files... +Finalizing metadata files... +Signing file 'Release' with gpg, please enter your passphrase when prompted: +Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: +Cleaning up published repository ./maverick... +Cleaning up component 'main'... + +Published local repository ./maverick (origin: earth, label: fun) [i386, source] publishes {main: [local-repo]} has been updated successfully. diff --git a/system/t06_publish/PublishUpdate19Test_release b/system/t06_publish/PublishUpdate19Test_release new file mode 100644 index 0000000000..0ab5dd0ab0 --- /dev/null +++ b/system/t06_publish/PublishUpdate19Test_release @@ -0,0 +1,11 @@ +Origin: earth +Label: fun +Suite: maverick +Codename: maverick +Architectures: i386 +Components: main +Description: Generated by aptly +MD5Sum: +SHA1: +SHA256: +SHA512: diff --git a/system/t06_publish/update.py b/system/t06_publish/update.py index 3a24ec1696..2f58314d43 100644 --- a/system/t06_publish/update.py +++ b/system/t06_publish/update.py @@ -606,3 +606,25 @@ def check(self): components = sorted(components.split(' ')) if ['other-test', 'test'] != components: raise Exception("value of 'Components' in release file is '%s' and does not match '%s'." % (' '.join(components), 'other-test test')) + + +class PublishUpdate19Test(BaseTest): + """ + publish update: update label and origin + """ + fixtureCmds = [ + "aptly repo create local-repo", + "aptly repo add local-repo ${files}/", + "aptly publish repo -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick -skip-bz2 local-repo", + "aptly repo remove local-repo pyspi" + ] + runCmd = "aptly publish update -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -label=fun -origin=earth maverick" + gold_processor = BaseTest.expand_environ + + def check(self): + super(PublishUpdate19Test, self).check() + + self.check_exists('public/dists/maverick/InRelease') + + # verify contents except of sums + self.check_file_contents('public/dists/maverick/Release', 'release', match_prepare=strip_processor) diff --git a/system/t12_api/publish.py b/system/t12_api/publish.py index 827515796f..ee2d2ac6cc 100644 --- a/system/t12_api/publish.py +++ b/system/t12_api/publish.py @@ -725,6 +725,8 @@ def check(self): "Snapshots": [{"Component": "main", "Name": snapshot2_name}], "Signing": DefaultSigningOptions, "SkipContents": True, + "Label": "fun", + "Origin": "earth", }) self.check_task(task) repo_expected = { @@ -732,8 +734,8 @@ def check(self): 'Architectures': ['i386', 'source'], 'Codename': '', 'Distribution': 'wheezy', - 'Label': '', - 'Origin': '', + 'Label': 'fun', + 'Origin': 'earth', 'NotAutomatic': '', 'ButAutomaticUpgrades': '', 'Path': prefix + '/' + 'wheezy', @@ -1533,6 +1535,8 @@ def check(self): "Signing": DefaultSigningOptions, "SkipBz2": True, "SkipContents": True, + "Label": "fun", + "Origin": "earth", } ).status_code, 200) @@ -1541,8 +1545,8 @@ def check(self): 'Architectures': ['i386', 'source'], 'Codename': '', 'Distribution': 'wheezy', - 'Label': '', - 'Origin': '', + 'Label': 'fun', + 'Origin': 'earth', 'NotAutomatic': '', 'ButAutomaticUpgrades': '', 'Path': prefix + '/' + 'wheezy',