diff --git a/api/publish.go b/api/publish.go index 9c759ae36..c7423731a 100644 --- a/api/publish.go +++ b/api/publish.go @@ -84,10 +84,34 @@ func apiPublishList(c *gin.Context) { c.JSON(200, result) } +type publishCreateParams struct { + // source kind: local for local repositories and snapshot for snapshots + SourceKind string `binding:"required"` + Sources []struct { + Component string + Name string `binding:"required"` + } `binding:"required"` + Distribution string + Label string + Origin string + NotAutomatic string + ButAutomaticUpgrades string + ForceOverwrite bool + SkipContents *bool + SkipBz2 *bool + Architectures []string + Signing SigningOptions + AcquireByHash *bool + MultiDist bool +} + // @Summary TODO // @Description **ToDo** // @Description To Do // @Tags Publish +// @Param prefix path string true "Publishing prefix, `.` for root" +// @Consume json +// @Param request body publishCreateParams true "Parameters" // @Produce json // @Success 200 {object} string "msg" // @Failure 404 {object} Error "Not Found" @@ -96,26 +120,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) { param := parseEscapedPath(c.Params.ByName("prefix")) storage, prefix := deb.ParsePrefix(param) - var b struct { - SourceKind string `binding:"required"` - Sources []struct { - Component string - Name string `binding:"required"` - } `binding:"required"` - Distribution string - Label string - Origin string - NotAutomatic string - ButAutomaticUpgrades string - ForceOverwrite bool - SkipContents *bool - SkipBz2 *bool - Architectures []string - Signing SigningOptions - AcquireByHash *bool - MultiDist bool - } - + var b publishCreateParams if c.Bind(&b) != nil { return } @@ -189,7 +194,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) { return } - published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, collectionFactory) + published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, collectionFactory, b.MultiDist) if err != nil { AbortWithJSONError(c, 500, fmt.Errorf("unable to publish: %s", err)) return @@ -239,7 +244,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) { return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate) } - err := published.Publish(context.PackagePool(), context, collectionFactory, signer, publishOutput, b.ForceOverwrite, b.MultiDist) + err := published.Publish(context.PackagePool(), context, collectionFactory, signer, publishOutput, b.ForceOverwrite) if err != nil { return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to publish: %s", err) } @@ -356,7 +361,7 @@ func apiPublishUpdateSwitch(c *gin.Context) { resources = append(resources, string(published.Key())) taskName := fmt.Sprintf("Update published %s (%s): %s", published.SourceKind, strings.Join(updatedComponents, " "), strings.Join(updatedSnapshots, ", ")) maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) { - err := published.Publish(context.PackagePool(), context, collectionFactory, signer, out, b.ForceOverwrite, b.MultiDist) + err := published.Publish(context.PackagePool(), context, collectionFactory, signer, out, b.ForceOverwrite) if err != nil { return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err) } diff --git a/cmd/publish_snapshot.go b/cmd/publish_snapshot.go index 1e79fac27..3d2e43e60 100644 --- a/cmd/publish_snapshot.go +++ b/cmd/publish_snapshot.go @@ -118,7 +118,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error { butAutomaticUpgrades := context.Flags().Lookup("butautomaticupgrades").Value.String() multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool) - published, err := deb.NewPublishedRepo(storage, prefix, distribution, context.ArchitecturesList(), components, sources, collectionFactory) + published, err := deb.NewPublishedRepo(storage, prefix, distribution, context.ArchitecturesList(), components, sources, collectionFactory, multiDist) if err != nil { return fmt.Errorf("unable to publish: %s", err) } @@ -166,7 +166,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error { context.Progress().ColoredPrintf("@rWARNING@|: force overwrite mode enabled, aptly might corrupt other published repositories sharing the same package pool.\n") } - err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist) + err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite) if err != nil { return fmt.Errorf("unable to publish: %s", err) } diff --git a/cmd/publish_switch.go b/cmd/publish_switch.go index a55347475..334ad6b96 100644 --- a/cmd/publish_switch.go +++ b/cmd/publish_switch.go @@ -13,7 +13,6 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error { var err error components := strings.Split(context.Flags().Lookup("component").Value.String(), ",") - multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool) if len(args) < len(components)+1 || len(args) > len(components)+2 { cmd.Usage() @@ -96,7 +95,7 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error { published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool) } - err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist) + err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite) if err != nil { return fmt.Errorf("unable to publish: %s", err) } diff --git a/cmd/publish_update.go b/cmd/publish_update.go index 9bceda509..10fd388a9 100644 --- a/cmd/publish_update.go +++ b/cmd/publish_update.go @@ -17,7 +17,6 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error { distribution := args[0] param := "." - multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool) if len(args) == 2 { param = args[1] @@ -65,7 +64,7 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error { published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool) } - err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist) + err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite) if err != nil { return fmt.Errorf("unable to publish: %s", err) } diff --git a/deb/publish.go b/deb/publish.go index 20224897e..436848257 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -71,8 +71,8 @@ type PublishedRepo struct { // Provide index files per hash also AcquireByHash bool - // Provide index files per hash also - MiltiDist bool + // Support multiple distributions + MultiDist bool } // ParsePrefix splits [storage:]prefix into components @@ -156,13 +156,14 @@ func walkUpTree(source interface{}, collectionFactory *CollectionFactory) (rootD // distribution and architectures are user-defined properties // components & sources are lists of component to source mapping (*Snapshot or *LocalRepo) func NewPublishedRepo(storage, prefix, distribution string, architectures []string, - components []string, sources []interface{}, collectionFactory *CollectionFactory) (*PublishedRepo, error) { + components []string, sources []interface{}, collectionFactory *CollectionFactory, multiDist bool) (*PublishedRepo, error) { result := &PublishedRepo{ UUID: uuid.New(), Storage: storage, Architectures: architectures, Sources: make(map[string]string), sourceItems: make(map[string]repoSourceItem), + MultiDist: multiDist, } if len(sources) == 0 { @@ -318,6 +319,7 @@ func (p *PublishedRepo) MarshalJSON() ([]byte, error) { "Storage": p.Storage, "SkipContents": p.SkipContents, "AcquireByHash": p.AcquireByHash, + "MultiDist": p.MultiDist, }) } @@ -550,7 +552,7 @@ func (p *PublishedRepo) GetCodename() string { // Publish publishes snapshot (repository) contents, links package files, generates Packages & Release files, signs them func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageProvider aptly.PublishedStorageProvider, - collectionFactory *CollectionFactory, signer pgp.Signer, progress aptly.Progress, forceOverwrite, multiDist bool) error { + collectionFactory *CollectionFactory, signer pgp.Signer, progress aptly.Progress, forceOverwrite bool) error { publishedStorage := publishedStorageProvider.GetPublishedStorage(p.Storage) err := publishedStorage.MkDir(filepath.Join(p.Prefix, "pool")) @@ -662,7 +664,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP if err2 != nil { return err2 } - if multiDist { + if p.MultiDist { relPath = filepath.Join("pool", p.Distribution, component, poolDir) } else { relPath = filepath.Join("pool", component, poolDir)