mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-16 12:08:04 +00:00
Use POST instead of PUT for source creation.
Signed-off-by: Christoph Fiehe <c.fiehe@eurodata.de>
This commit is contained in:
committed by
André Roth
parent
fa0d2860f0
commit
73cdf5417b
+165
-107
@@ -252,12 +252,11 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
|
|||||||
multiDist = *b.MultiDist
|
multiDist = *b.MultiDist
|
||||||
}
|
}
|
||||||
|
|
||||||
taskName := fmt.Sprintf("Publish %s repository %s/%s with components \"%s\" and sources \"%s\"",
|
|
||||||
b.SourceKind, published.StoragePrefix(), published.Distribution, strings.Join(components, `", "`), strings.Join(names, `", "`))
|
|
||||||
|
|
||||||
resources = append(resources, string(published.Key()))
|
|
||||||
collection := collectionFactory.PublishedRepoCollection()
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
|
|
||||||
|
resources = append(resources, string(published.Key()))
|
||||||
|
taskName := fmt.Sprintf("Publish %s repository %s/%s with components \"%s\" and sources \"%s\"",
|
||||||
|
b.SourceKind, published.StoragePrefix(), published.Distribution, strings.Join(components, `", "`), strings.Join(names, `", "`))
|
||||||
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
taskDetail := task.PublishDetail{
|
taskDetail := task.PublishDetail{
|
||||||
Detail: detail,
|
Detail: detail,
|
||||||
@@ -430,8 +429,7 @@ func apiPublishUpdateSwitch(c *gin.Context) {
|
|||||||
published.MultiDist = *b.MultiDist
|
published.MultiDist = *b.MultiDist
|
||||||
}
|
}
|
||||||
|
|
||||||
var resources []string
|
resources := []string{string(published.Key())}
|
||||||
resources = append(resources, string(published.Key()))
|
|
||||||
taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution)
|
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) {
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
err = collection.LoadComplete(published, collectionFactory)
|
err = collection.LoadComplete(published, collectionFactory)
|
||||||
@@ -532,7 +530,6 @@ func apiPublishDrop(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resources := []string{string(published.Key())}
|
resources := []string{string(published.Key())}
|
||||||
|
|
||||||
taskName := fmt.Sprintf("Delete published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution)
|
taskName := fmt.Sprintf("Delete published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution)
|
||||||
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
err := collection.Remove(context, storage, prefix, distribution,
|
err := collection.Remove(context, storage, prefix, distribution,
|
||||||
@@ -545,8 +542,8 @@ func apiPublishDrop(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Router /api/publish/{prefix}/{distribution}/sources/{component} [put]
|
// @Router /api/publish/{prefix}/{distribution}/sources [post]
|
||||||
func apiPublishSourceUpdate(c *gin.Context) {
|
func apiPublishSourcesCreate(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
b sourceParams
|
b sourceParams
|
||||||
@@ -555,7 +552,57 @@ func apiPublishSourceUpdate(c *gin.Context) {
|
|||||||
param := parseEscapedPath(c.Params.ByName("prefix"))
|
param := parseEscapedPath(c.Params.ByName("prefix"))
|
||||||
storage, prefix := deb.ParsePrefix(param)
|
storage, prefix := deb.ParsePrefix(param)
|
||||||
distribution := parseEscapedPath(c.Params.ByName("distribution"))
|
distribution := parseEscapedPath(c.Params.ByName("distribution"))
|
||||||
component := parseEscapedPath(c.Params.ByName("component"))
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
|
|
||||||
|
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
|
if err != nil {
|
||||||
|
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to create: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collection.LoadComplete(published, collectionFactory)
|
||||||
|
if err != nil {
|
||||||
|
AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unable to create: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Bind(&b) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
revision := published.ObtainRevision()
|
||||||
|
sources := revision.Sources
|
||||||
|
|
||||||
|
component := b.Component
|
||||||
|
name := b.Name
|
||||||
|
|
||||||
|
_, exists := sources[component]
|
||||||
|
if exists {
|
||||||
|
AbortWithJSONError(c, http.StatusBadRequest, fmt.Errorf("unable to create: Component %q already exists", component))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sources[component] = name
|
||||||
|
|
||||||
|
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) {
|
||||||
|
err = collection.Update(published)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save to DB: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: published}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Router /api/publish/{prefix}/{distribution}/sources [get]
|
||||||
|
func apiPublishSourcesList(c *gin.Context) {
|
||||||
|
param := parseEscapedPath(c.Params.ByName("prefix"))
|
||||||
|
storage, prefix := deb.ParsePrefix(param)
|
||||||
|
distribution := parseEscapedPath(c.Params.ByName("distribution"))
|
||||||
|
|
||||||
collectionFactory := context.NewCollectionFactory()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection := collectionFactory.PublishedRepoCollection()
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
@@ -572,32 +619,13 @@ func apiPublishSourceUpdate(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
revision := published.ObtainRevision()
|
revision := published.Revision
|
||||||
sources := revision.Sources
|
if revision == nil {
|
||||||
|
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to show: No source changes exist"))
|
||||||
b.Component = component
|
|
||||||
b.Name = revision.Sources[component]
|
|
||||||
|
|
||||||
if c.Bind(&b) != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Component != component {
|
c.JSON(http.StatusOK, revision.ToJSON()["Sources"])
|
||||||
delete(sources, component)
|
|
||||||
}
|
|
||||||
sources[b.Component] = b.Name
|
|
||||||
|
|
||||||
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) {
|
|
||||||
err = collection.Update(published)
|
|
||||||
if err != nil {
|
|
||||||
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save to DB: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &task.ProcessReturnValue{Code: http.StatusOK, Value: published}, nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Router /api/publish/{prefix}/{distribution}/sources [put]
|
// @Router /api/publish/{prefix}/{distribution}/sources [put]
|
||||||
@@ -641,79 +669,6 @@ func apiPublishSourcesUpdate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resources := []string{string(published.Key())}
|
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) {
|
|
||||||
err = collection.Update(published)
|
|
||||||
if err != nil {
|
|
||||||
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save to DB: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &task.ProcessReturnValue{Code: http.StatusOK, Value: published}, nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Router /api/publish/{prefix}/{distribution}/sources [get]
|
|
||||||
func apiPublishSourceList(c *gin.Context) {
|
|
||||||
param := parseEscapedPath(c.Params.ByName("prefix"))
|
|
||||||
storage, prefix := deb.ParsePrefix(param)
|
|
||||||
distribution := parseEscapedPath(c.Params.ByName("distribution"))
|
|
||||||
|
|
||||||
collectionFactory := context.NewCollectionFactory()
|
|
||||||
collection := collectionFactory.PublishedRepoCollection()
|
|
||||||
|
|
||||||
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
|
||||||
if err != nil {
|
|
||||||
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to show: %s", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = collection.LoadComplete(published, collectionFactory)
|
|
||||||
if err != nil {
|
|
||||||
AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unable to show: %s", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
revision := published.Revision
|
|
||||||
if revision == nil {
|
|
||||||
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to show: No source changes exist"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, revision.ToJSON()["Sources"])
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Router /api/publish/{prefix}/{distribution}/sources/{component} [delete]
|
|
||||||
func apiPublishSourceDelete(c *gin.Context) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
param := parseEscapedPath(c.Params.ByName("prefix"))
|
|
||||||
storage, prefix := deb.ParsePrefix(param)
|
|
||||||
distribution := parseEscapedPath(c.Params.ByName("distribution"))
|
|
||||||
component := parseEscapedPath(c.Params.ByName("component"))
|
|
||||||
|
|
||||||
collectionFactory := context.NewCollectionFactory()
|
|
||||||
collection := collectionFactory.PublishedRepoCollection()
|
|
||||||
|
|
||||||
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
|
||||||
if err != nil {
|
|
||||||
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to show: %s", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = collection.LoadComplete(published, collectionFactory)
|
|
||||||
if err != nil {
|
|
||||||
AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unable to show: %s", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
revision := published.ObtainRevision()
|
|
||||||
sources := revision.Sources
|
|
||||||
|
|
||||||
delete(sources, component)
|
|
||||||
|
|
||||||
resources := []string{string(published.Key())}
|
|
||||||
|
|
||||||
taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution)
|
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) {
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
err = collection.Update(published)
|
err = collection.Update(published)
|
||||||
@@ -749,6 +704,110 @@ func apiPublishSourcesDelete(c *gin.Context) {
|
|||||||
published.DropRevision()
|
published.DropRevision()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Router /api/publish/{prefix}/{distribution}/sources/{component} [put]
|
||||||
|
func apiPublishSourceUpdate(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
b sourceParams
|
||||||
|
)
|
||||||
|
|
||||||
|
param := parseEscapedPath(c.Params.ByName("prefix"))
|
||||||
|
storage, prefix := deb.ParsePrefix(param)
|
||||||
|
distribution := parseEscapedPath(c.Params.ByName("distribution"))
|
||||||
|
component := parseEscapedPath(c.Params.ByName("component"))
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
|
|
||||||
|
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
|
if err != nil {
|
||||||
|
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to update: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collection.LoadComplete(published, collectionFactory)
|
||||||
|
if err != nil {
|
||||||
|
AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unable to update: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
revision := published.ObtainRevision()
|
||||||
|
sources := revision.Sources
|
||||||
|
|
||||||
|
_, exists := sources[component]
|
||||||
|
if !exists {
|
||||||
|
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to update: Component %q does not exist", component))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Component = component
|
||||||
|
b.Name = revision.Sources[component]
|
||||||
|
|
||||||
|
if c.Bind(&b) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.Component != component {
|
||||||
|
delete(sources, component)
|
||||||
|
}
|
||||||
|
|
||||||
|
component = b.Component
|
||||||
|
name := b.Name
|
||||||
|
sources[component] = name
|
||||||
|
|
||||||
|
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) {
|
||||||
|
err = collection.Update(published)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save to DB: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: published}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Router /api/publish/{prefix}/{distribution}/sources/{component} [delete]
|
||||||
|
func apiPublishSourceDelete(c *gin.Context) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
param := parseEscapedPath(c.Params.ByName("prefix"))
|
||||||
|
storage, prefix := deb.ParsePrefix(param)
|
||||||
|
distribution := parseEscapedPath(c.Params.ByName("distribution"))
|
||||||
|
component := parseEscapedPath(c.Params.ByName("component"))
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
|
|
||||||
|
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
|
if err != nil {
|
||||||
|
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to show: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collection.LoadComplete(published, collectionFactory)
|
||||||
|
if err != nil {
|
||||||
|
AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unable to show: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
revision := published.ObtainRevision()
|
||||||
|
sources := revision.Sources
|
||||||
|
|
||||||
|
delete(sources, component)
|
||||||
|
|
||||||
|
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) {
|
||||||
|
err = collection.Update(published)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save to DB: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: published}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// @Router /api/publish/{prefix}/{distribution}/update [post]
|
// @Router /api/publish/{prefix}/{distribution}/update [post]
|
||||||
func apiPublishUpdate(c *gin.Context) {
|
func apiPublishUpdate(c *gin.Context) {
|
||||||
param := parseEscapedPath(c.Params.ByName("prefix"))
|
param := parseEscapedPath(c.Params.ByName("prefix"))
|
||||||
@@ -807,7 +866,6 @@ func apiPublishUpdate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resources := []string{string(published.Key())}
|
resources := []string{string(published.Key())}
|
||||||
|
|
||||||
taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution)
|
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) {
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
result, err := published.Update(collectionFactory, out)
|
result, err := published.Update(collectionFactory, out)
|
||||||
|
|||||||
+3
-2
@@ -191,11 +191,12 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
|||||||
api.POST("/publish/:prefix", apiPublishRepoOrSnapshot)
|
api.POST("/publish/:prefix", apiPublishRepoOrSnapshot)
|
||||||
api.PUT("/publish/:prefix/:distribution", apiPublishUpdateSwitch)
|
api.PUT("/publish/:prefix/:distribution", apiPublishUpdateSwitch)
|
||||||
api.DELETE("/publish/:prefix/:distribution", apiPublishDrop)
|
api.DELETE("/publish/:prefix/:distribution", apiPublishDrop)
|
||||||
api.GET("/publish/:prefix/:distribution/sources", apiPublishSourceList)
|
api.POST("/publish/:prefix/:distribution/sources", apiPublishSourcesCreate)
|
||||||
|
api.GET("/publish/:prefix/:distribution/sources", apiPublishSourcesList)
|
||||||
api.PUT("/publish/:prefix/:distribution/sources", apiPublishSourcesUpdate)
|
api.PUT("/publish/:prefix/:distribution/sources", apiPublishSourcesUpdate)
|
||||||
|
api.DELETE("/publish/:prefix/:distribution/sources", apiPublishSourcesDelete)
|
||||||
api.PUT("/publish/:prefix/:distribution/sources/:component", apiPublishSourceUpdate)
|
api.PUT("/publish/:prefix/:distribution/sources/:component", apiPublishSourceUpdate)
|
||||||
api.DELETE("/publish/:prefix/:distribution/sources/:component", apiPublishSourceDelete)
|
api.DELETE("/publish/:prefix/:distribution/sources/:component", apiPublishSourceDelete)
|
||||||
api.DELETE("/publish/:prefix/:distribution/sources", apiPublishSourcesDelete)
|
|
||||||
api.POST("/publish/:prefix/:distribution/update", apiPublishUpdate)
|
api.POST("/publish/:prefix/:distribution/update", apiPublishUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user