mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-04 05:10:40 +00:00
Make snapshot creation API more RESTful: accept snapshot name from URL. #116
This commit is contained in:
+2
-2
@@ -37,11 +37,11 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
|||||||
root.POST("/repos/:name/file/:dir/:file", apiReposPackageFromFile)
|
root.POST("/repos/:name/file/:dir/:file", apiReposPackageFromFile)
|
||||||
root.POST("/repos/:name/file/:dir", apiReposPackageFromDir)
|
root.POST("/repos/:name/file/:dir", apiReposPackageFromDir)
|
||||||
|
|
||||||
root.POST("/repos/:name/snapshots", apiSnapshotsCreateFromRepository)
|
root.POST("/repos/:name/snapshots/:snapname", apiSnapshotsCreateFromRepository)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
root.POST("/mirrors/:name/snapshots", apiSnapshotsCreateFromMirror)
|
root.POST("/mirrors/:name/snapshots/:snapname", apiSnapshotsCreateFromMirror)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-28
@@ -36,15 +36,6 @@ func apiSnapshotsCreateFromMirror(c *gin.Context) {
|
|||||||
snapshot *deb.Snapshot
|
snapshot *deb.Snapshot
|
||||||
)
|
)
|
||||||
|
|
||||||
var b struct {
|
|
||||||
Name string `binding:"required"`
|
|
||||||
Description string
|
|
||||||
}
|
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
collection := context.CollectionFactory().RemoteRepoCollection()
|
collection := context.CollectionFactory().RemoteRepoCollection()
|
||||||
collection.RLock()
|
collection.RLock()
|
||||||
defer collection.RUnlock()
|
defer collection.RUnlock()
|
||||||
@@ -71,16 +62,12 @@ func apiSnapshotsCreateFromMirror(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot, err = deb.NewSnapshotFromRepository(b.Name, repo)
|
snapshot, err = deb.NewSnapshotFromRepository(c.Params.ByName("snapname"), repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
c.Fail(400, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Description != "" {
|
|
||||||
snapshot.Description = b.Description
|
|
||||||
}
|
|
||||||
|
|
||||||
err = snapshotCollection.Add(snapshot)
|
err = snapshotCollection.Add(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
c.Fail(400, err)
|
||||||
@@ -175,15 +162,6 @@ func apiSnapshotsCreateFromRepository(c *gin.Context) {
|
|||||||
snapshot *deb.Snapshot
|
snapshot *deb.Snapshot
|
||||||
)
|
)
|
||||||
|
|
||||||
var b struct {
|
|
||||||
Name string `binding:"required"`
|
|
||||||
Description string
|
|
||||||
}
|
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collection := context.CollectionFactory().LocalRepoCollection()
|
||||||
collection.RLock()
|
collection.RLock()
|
||||||
defer collection.RUnlock()
|
defer collection.RUnlock()
|
||||||
@@ -204,16 +182,12 @@ func apiSnapshotsCreateFromRepository(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot, err = deb.NewSnapshotFromLocalRepo(b.Name, repo)
|
snapshot, err = deb.NewSnapshotFromLocalRepo(c.Params.ByName("snapname"), repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
c.Fail(400, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Description != "" {
|
|
||||||
snapshot.Description = b.Description
|
|
||||||
}
|
|
||||||
|
|
||||||
err = snapshotCollection.Add(snapshot)
|
err = snapshotCollection.Add(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
c.Fail(400, err)
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class SnapshotsAPITestCreateFromRepo(APITest):
|
|||||||
snapshot_name = self.random_name()
|
snapshot_name = self.random_name()
|
||||||
self.check_equal(self.post("/api/repos", json={"Name": repo_name}).status_code, 201)
|
self.check_equal(self.post("/api/repos", json={"Name": repo_name}).status_code, 201)
|
||||||
|
|
||||||
resp = self.post("/api/repos/" + repo_name + '/snapshots', json={'Name': snapshot_name})
|
resp = self.post("/api/repos/" + repo_name + '/snapshots/' + snapshot_name)
|
||||||
self.check_equal(resp.status_code, 400)
|
self.check_equal(resp.status_code, 400)
|
||||||
|
|
||||||
d = self.random_name()
|
d = self.random_name()
|
||||||
@@ -105,7 +105,7 @@ class SnapshotsAPITestCreateFromRepo(APITest):
|
|||||||
|
|
||||||
self.check_equal(self.post("/api/repos/" + repo_name + "/file/" + d).status_code, 200)
|
self.check_equal(self.post("/api/repos/" + repo_name + "/file/" + d).status_code, 200)
|
||||||
|
|
||||||
resp = self.post("/api/repos/" + repo_name + '/snapshots', json={'Name': snapshot_name})
|
resp = self.post("/api/repos/" + repo_name + '/snapshots/' + snapshot_name)
|
||||||
self.check_equal(self.get("/api/snapshots/" + snapshot_name).status_code, 200)
|
self.check_equal(self.get("/api/snapshots/" + snapshot_name).status_code, 200)
|
||||||
|
|
||||||
self.check_subset({u'Architecture': 'i386',
|
self.check_subset({u'Architecture': 'i386',
|
||||||
@@ -122,7 +122,7 @@ class SnapshotsAPITestCreateFromRepo(APITest):
|
|||||||
params={"format": "details", "q": "Version (> 0.6.1-1.4)"}).json()[0])
|
params={"format": "details", "q": "Version (> 0.6.1-1.4)"}).json()[0])
|
||||||
|
|
||||||
# duplicate snapshot name
|
# duplicate snapshot name
|
||||||
resp = self.post("/api/repos/" + repo_name + '/snapshots', json={'Name': snapshot_name})
|
resp = self.post("/api/repos/" + repo_name + '/snapshots/' + snapshot_name)
|
||||||
self.check_equal(resp.status_code, 400)
|
self.check_equal(resp.status_code, 400)
|
||||||
|
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ class SnapshotsAPITestSearch(APITest):
|
|||||||
|
|
||||||
self.check_equal(self.post("/api/repos/" + repo_name + "/file/" + d).status_code, 200)
|
self.check_equal(self.post("/api/repos/" + repo_name + "/file/" + d).status_code, 200)
|
||||||
|
|
||||||
resp = self.post("/api/repos/" + repo_name + '/snapshots', json={'Name': snapshot_name})
|
resp = self.post("/api/repos/" + repo_name + '/snapshots/' + snapshot_name)
|
||||||
self.check_equal(resp.status_code, 201)
|
self.check_equal(resp.status_code, 201)
|
||||||
|
|
||||||
resp = self.get("/api/snapshots/" + snapshot_name + "/packages",
|
resp = self.get("/api/snapshots/" + snapshot_name + "/packages",
|
||||||
@@ -249,7 +249,7 @@ class SnapshotsAPITestDiff(APITest):
|
|||||||
|
|
||||||
self.check_equal(self.post("/api/repos/" + repo_name + "/file/" + d).status_code, 200)
|
self.check_equal(self.post("/api/repos/" + repo_name + "/file/" + d).status_code, 200)
|
||||||
|
|
||||||
resp = self.post("/api/repos/" + repo_name + '/snapshots', json={'Name': snapshots[0]})
|
resp = self.post("/api/repos/" + repo_name + '/snapshots/' + snapshots[0])
|
||||||
self.check_equal(resp.status_code, 201)
|
self.check_equal(resp.status_code, 201)
|
||||||
|
|
||||||
resp = self.post("/api/snapshots", json={'Name': snapshots[1]})
|
resp = self.post("/api/snapshots", json={'Name': snapshots[1]})
|
||||||
|
|||||||
Reference in New Issue
Block a user