Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve/documentation #1359

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e1564a6
add api documentation stubs
neolynx Oct 3, 2024
5d98dbf
allow comments in config file
neolynx Oct 3, 2024
7a5eff8
document aptly.conf
neolynx Oct 4, 2024
528e141
docs: improve swagger
neolynx Oct 5, 2024
cc037b2
go mod tidy
neolynx Oct 4, 2024
2e474ab
update doc
neolynx Oct 15, 2024
97ad82f
fix conflict
neolynx Nov 1, 2024
9bf2bbc
update go.mod
neolynx Nov 1, 2024
851f815
update
neolynx Nov 2, 2024
1e9ed38
fix lint
neolynx Nov 3, 2024
772ea33
doc: import chapters from aptly.info
neolynx Nov 3, 2024
95b3970
update go.mod
neolynx Nov 17, 2024
6238674
Update repos, task, snapshot api docs
iofq Nov 17, 2024
1d2640d
Update packages api docs
iofq Nov 19, 2024
a389b1d
Update gpg, graph api docs
iofq Nov 19, 2024
b73456d
Update db api docs
iofq Nov 19, 2024
03c7b15
Update files api docs
iofq Nov 19, 2024
10fb494
fix swagger build
neolynx Nov 21, 2024
f6aa185
doc: improve cmd usage arguments
neolynx Nov 28, 2024
bf8e4cc
update doc
neolynx Nov 28, 2024
c182384
swagger: improve layout
neolynx Nov 28, 2024
3e459b3
dos: improve api info
neolynx Nov 28, 2024
50db190
swagger: cleanup files doc
neolynx Nov 28, 2024
195c32e
swagger: cleanup Snapshots
neolynx Nov 28, 2024
633209e
swwagger: cleanup
neolynx Nov 28, 2024
08b8381
task-dummy: remove internal testing API
neolynx Nov 28, 2024
909a1cb
swagger: cleanup
neolynx Nov 28, 2024
d7e9bf1
swagger: document async
neolynx Nov 28, 2024
3afad81
swagger: document params
neolynx Nov 28, 2024
4123c7a
fix optional params
neolynx Nov 29, 2024
ed541ba
document aptly.conf
neolynx Nov 29, 2024
1cf4204
write commented json default config
neolynx Dec 1, 2024
8cf1e31
fix json
neolynx Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ usr/bin/aptly
dpkgs/
debian/changelog.dpkg-bak

docs/
docs/docs.go
docs/swagger.json
docs/swagger.yaml
docs/swagger.conf
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ version: ## Print aptly version
swagger-install:
# Install swag
@test -f $(BINPATH)/swag || GOOS=linux GOARCH=amd64 go install github.com/swaggo/swag/cmd/swag@latest
# Generate swagger.conf
cp docs/swagger.conf.tpl docs/swagger.conf
echo "// @version $(VERSION)" >> docs/swagger.conf

azurite-start:
azurite & \
Expand All @@ -55,7 +58,7 @@ azurite-stop:

swagger: swagger-install
# Generate swagger docs
@PATH=$(BINPATH)/:$(PATH) swag init --markdownFiles docs
@PATH=$(BINPATH)/:$(PATH) swag init --parseDependency --parseInternal --markdownFiles docs --generalInfo docs/swagger.conf

etcd-install:
# Install etcd
Expand All @@ -64,7 +67,7 @@ etcd-install:
flake8: ## run flake8 on system test python files
flake8 system/

lint:
lint: prepare
# Install golangci-lint
@test -f $(BINPATH)/golangci-lint || go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
# Running lint
Expand Down Expand Up @@ -107,7 +110,7 @@ serve: prepare swagger-install ## Run development server (auto recompiling)
test -f $(BINPATH)/air || go install github.com/air-verse/air@v1.52.3
cp debian/aptly.conf ~/.aptly.conf
sed -i /enableSwaggerEndpoint/s/false/true/ ~/.aptly.conf
PATH=$(BINPATH):$$PATH air -build.pre_cmd 'swag init -q --markdownFiles docs' -build.exclude_dir docs,system,debian,pgp/keyrings,pgp/test-bins,completion.d,man,deb/testdata,console,_man,systemd,obj-x86_64-linux-gnu -- api serve -listen 0.0.0.0:3142
PATH=$(BINPATH):$$PATH air -build.pre_cmd 'swag init -q --markdownFiles docs --generalInfo docs/swagger.conf' -build.exclude_dir docs,system,debian,pgp/keyrings,pgp/test-bins,completion.d,man,deb/testdata,console,_man,systemd,obj-x86_64-linux-gnu -- api serve -listen 0.0.0.0:3142

dpkg: prepare swagger ## Build debian packages
@test -n "$(DEBARCH)" || (echo "please define DEBARCH"; exit 1)
Expand Down Expand Up @@ -205,7 +208,8 @@ man: ## Create man pages

clean: ## remove local build and module cache
# Clean all generated and build files
test -d .go/ && chmod u+w -R .go/ && rm -rf .go/ || true
find .go/ -type d ! -perm -u=w -exec chmod u+w {} \;
rm -rf .go/
rm -rf build/ obj-*-linux-gnu* tmp/
rm -f unit.out aptly.test VERSION docs/docs.go docs/swagger.json docs/swagger.yaml docs/swagger.conf
find system/ -type d -name __pycache__ -exec rm -rf {} \; 2>/dev/null || true
Expand Down
45 changes: 42 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,43 @@ import (
// 3. SnapshotCollection
// 4. PublishedRepoCollection

// GET /api/version
type aptlyVersion struct {
// Aptly Version
Version string `json:"Version"`
}

// @Summary Aptly version
// @Description **Get aptly version**
// @Description
// @Description **Example:**
// @Description ```
// @Description $ curl http://localhost:8080/api/version
// @Description {"Version":"0.9~dev"}
// @Description ```
// @Tags Status
// @Produce json
// @Success 200 {object} aptlyVersion
// @Router /api/version [get]
func apiVersion(c *gin.Context) {
c.JSON(200, gin.H{"Version": aptly.Version})
}

// GET /api/ready
type aptlyStatus struct {
// Aptly Status
Status string `json:"Status" example:"'Aptly is ready', 'Aptly is unavailable', 'Aptly is healthy'"`
}

// @Summary Ready State
// @Description **Get aptly ready state**
// @Description
// @Description Return aptly ready state:
// @Description - `Aptly is ready` (HTTP 200)
// @Description - `Aptly is unavailable` (HTTP 503)
// @Tags Status
// @Produce json
// @Success 200 {object} aptlyStatus "Aptly is ready"
// @Failure 503 {object} aptlyStatus "Aptly is unavailable"
// @Router /api/ready [get]
func apiReady(isReady *atomic.Value) func(*gin.Context) {
return func(c *gin.Context) {
if isReady == nil || !isReady.Load().(bool) {
Expand All @@ -40,7 +71,15 @@ func apiReady(isReady *atomic.Value) func(*gin.Context) {
}
}

// GET /api/healthy
// @Summary Health State
// @Description **Get aptly health state**
// @Description
// @Description Return aptly health state:
// @Description - `Aptly is healthy` (HTTP 200)
// @Tags Status
// @Produce json
// @Success 200 {object} aptlyStatus
// @Router /api/healthy [get]
func apiHealthy(c *gin.Context) {
c.JSON(200, gin.H{"Status": "Aptly is healthy"})
}
Expand Down
12 changes: 10 additions & 2 deletions api/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ import (
"github.com/gin-gonic/gin"
)

// POST /api/db/cleanup
// @Summary DB Cleanup
// @Description **Cleanup Aptly DB**
// @Description Database cleanup removes information about unreferenced packages and deletes files in the package pool that aren’t used by packages anymore.
// @Description It is a good idea to run this command after massive deletion of mirrors, snapshots or local repos.
// @Tags Database
// @Produce json
// @Param _async query bool false "Run in background and return task object"
// @Success 200 {object} string "Output"
// @Failure 404 {object} Error "Not Found"
// @Router /api/db/cleanup [post]
func apiDbCleanup(c *gin.Context) {

resources := []string{string(task.AllResourcesKey)}
maybeRunTaskInBackground(c, "Clean up db", resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
var err error
Expand Down
83 changes: 75 additions & 8 deletions api/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ func verifyDir(c *gin.Context) bool {
return true
}

// @Summary Get files
// @Description Get list of uploaded files.
// @Summary List Directories
// @Description **Get list of upload directories**
// @Description
// @Description **Example:**
// @Description ```
// @Description $ curl http://localhost:8080/api/files
// @Description ["aptly-0.9"]
// @Description ```
// @Tags Files
// @Produce json
// @Produce json
// @Success 200 {array} string "List of files"
// @Router /api/files [get]
func apiFilesListDirs(c *gin.Context) {
Expand Down Expand Up @@ -67,7 +73,27 @@ func apiFilesListDirs(c *gin.Context) {
c.JSON(200, list)
}

// POST /files/:dir/
// @Summary Upload Files
// @Description **Upload files to a directory**
// @Description
// @Description - one or more files can be uploaded
// @Description - existing uploaded are overwritten
// @Description
// @Description **Example:**
// @Description ```
// @Description $ curl -X POST -F file=@aptly_0.9~dev+217+ge5d646c_i386.deb http://localhost:8080/api/files/aptly-0.9
// @Description ["aptly-0.9/aptly_0.9~dev+217+ge5d646c_i386.deb"]
// @Description ```
// @Tags Files
// @Accept multipart/form-data
// @Param dir path string true "Directory to upload files to. Created if does not exist"
// @Param files formData file true "Files to upload"
// @Produce json
// @Success 200 {array} string "list of uploaded files"
// @Failure 400 {object} Error "Bad Request"
// @Failure 404 {object} Error "Not Found"
// @Failure 500 {object} Error "Internal Server Error"
// @Router /api/files/{dir} [post]
func apiFilesUpload(c *gin.Context) {
if !verifyDir(c) {
return
Expand Down Expand Up @@ -118,10 +144,23 @@ func apiFilesUpload(c *gin.Context) {

apiFilesUploadedCounter.WithLabelValues(c.Params.ByName("dir")).Inc()
c.JSON(200, stored)

}

// GET /files/:dir
// @Summary List Files
// @Description **Show uploaded files in upload directory**
// @Description
// @Description **Example:**
// @Description ```
// @Description $ curl http://localhost:8080/api/files/aptly-0.9
// @Description ["aptly_0.9~dev+217+ge5d646c_i386.deb"]
// @Description ```
// @Tags Files
// @Produce json
// @Param dir path string true "Directory to list"
// @Success 200 {array} string "Files found in directory"
// @Failure 404 {object} Error "Not Found"
// @Failure 500 {object} Error "Internal Server Error"
// @Router /api/files/{dir} [get]
func apiFilesListFiles(c *gin.Context) {
if !verifyDir(c) {
return
Expand Down Expand Up @@ -159,7 +198,20 @@ func apiFilesListFiles(c *gin.Context) {
c.JSON(200, list)
}

// DELETE /files/:dir
// @Summary Delete Directory
// @Description **Delete upload directory and uploaded files within**
// @Description
// @Description **Example:**
// @Description ```
// @Description $ curl -X DELETE http://localhost:8080/api/files/aptly-0.9
// @Description {}
// @Description ```
// @Tags Files
// @Produce json
// @Param dir path string true "Directory"
// @Success 200 {object} string "msg"
// @Failure 500 {object} Error "Internal Server Error"
// @Router /api/files/{dir} [delete]
func apiFilesDeleteDir(c *gin.Context) {
if !verifyDir(c) {
return
Expand All @@ -174,7 +226,22 @@ func apiFilesDeleteDir(c *gin.Context) {
c.JSON(200, gin.H{})
}

// DELETE /files/:dir/:name
// @Summary Delete File
// @Description **Delete a uploaded file in upload directory**
// @Description
// @Description **Example:**
// @Description ```
// @Description $ curl -X DELETE http://localhost:8080/api/files/aptly-0.9/aptly_0.9~dev+217+ge5d646c_i386.deb
// @Description {}
// @Description ```
// @Tags Files
// @Produce json
// @Param dir path string true "Directory to delete from"
// @Param name path string true "File to delete"
// @Success 200 {object} string "msg"
// @Failure 400 {object} Error "Bad Request"
// @Failure 500 {object} Error "Internal Server Error"
// @Router /api/files/{dir}/{name} [delete]
func apiFilesDeleteFile(c *gin.Context) {
if !verifyDir(c) {
return
Expand Down
30 changes: 22 additions & 8 deletions api/gpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,29 @@ import (
"github.com/gin-gonic/gin"
)

// POST /api/gpg
func apiGPGAddKey(c *gin.Context) {
var b struct {
Keyserver string
GpgKeyID string
GpgKeyArmor string
Keyring string
}
type gpgAddKeyParams struct {
// Keyserver, when downloading GpgKeyIDs
Keyserver string `json:"Keyserver" example:"hkp://keyserver.ubuntu.com:80"`
// GpgKeyIDs to download from Keyserver, comma separated list
GpgKeyID string `json:"GpgKeyID" example:"EF0F382A1A7B6500,8B48AD6246925553"`
// Armored gpg public ket, instead of downloading from keyserver
GpgKeyArmor string `json:"GpgKeyArmor" example:""`
// Keyring for adding the keys (default: trustedkeys.gpg)
Keyring string `json:"Keyring" example:"trustedkeys.gpg"`
}

// @Summary Add GPG Keys
// @Description **Adds GPG keys to aptly keyring**
// @Description
// @Description Add GPG public keys for veryfing remote repositories for mirroring.
// @Tags Mirrors
// @Produce json
// @Success 200 {object} string "OK"
// @Failure 400 {object} Error "Bad Request"
// @Failure 404 {object} Error "Not Found"
// @Router /api/gpg [post]
func apiGPGAddKey(c *gin.Context) {
b := gpgAddKeyParams{}
if c.Bind(&b) != nil {
return
}
Expand Down
22 changes: 21 additions & 1 deletion api/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,27 @@ import (
"github.com/gin-gonic/gin"
)

// GET /api/graph.:ext?layout=[vertical|horizontal(default)]
// @Summary Graph Output
// @Description **Generate dependency graph**
// @Description
// @Description Command graph generates graph of dependencies:
// @Description
// @Description * between snapshots and mirrors (what mirror was used to create each snapshot)
// @Description * between snapshots and local repos (what local repo was used to create snapshot)
// @Description * between snapshots (pulling, merging, etc.)
// @Description * between snapshots, local repos and published repositories (how snapshots were published).
// @Description
// @Description Graph is rendered to PNG file using graphviz package.
// @Description
// @Description Example URL: `http://localhost:8080/api/graph.svg?layout=vertical`
// @Tags Status
// @Produce image/png, image/svg+xml
// @Param ext path string true "ext specifies desired file extension, e.g. .png, .svg."
// @Param layout query string false "Change between a `horizontal` (default) and a `vertical` graph layout."
// @Success 200 {object} []byte "Output"
// @Failure 404 {object} Error "Not Found"
// @Failure 500 {object} Error "Internal Server Error"
// @Router /api/graph.{ext} [get]
func apiGraph(c *gin.Context) {
var (
err error
Expand Down
8 changes: 5 additions & 3 deletions api/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func getVerifier(keyRings []string) (pgp.Verifier, error) {
return verifier, nil
}

// @Summary Get mirrors
// @Summary Get Mirrors
// @Description **Show list of currently available mirrors**
// @Description Each mirror is returned as in “show” API.
// @Tags Mirrors
Expand Down Expand Up @@ -82,8 +82,8 @@ type mirrorCreateParams struct {
IgnoreSignatures bool ` json:"IgnoreSignatures"`
}

// @Summary Create mirror
// @Description **Create a mirror**
// @Summary Create Mirror
// @Description **Create a mirror of a remote repository**
// @Tags Mirrors
// @Consume json
// @Param request body mirrorCreateParams true "Parameters"
Expand Down Expand Up @@ -164,6 +164,7 @@ func apiMirrorsCreate(c *gin.Context) {
// @Tags Mirrors
// @Param name path string true "mirror name"
// @Param force query int true "force: 1 to enable"
// @Param _async query bool false "Run in background and return task object"
// @Produce json
// @Success 200 {object} task.ProcessReturnValue
// @Failure 404 {object} Error "Mirror not found"
Expand Down Expand Up @@ -364,6 +365,7 @@ type mirrorUpdateParams struct {
// @Param name path string true "mirror name to update"
// @Consume json
// @Param request body mirrorUpdateParams true "Parameters"
// @Param _async query bool false "Run in background and return task object"
// @Produce json
// @Success 200 {object} task.ProcessReturnValue "Mirror was updated successfully"
// @Success 202 {object} task.Task "Mirror is being updated"
Expand Down
11 changes: 10 additions & 1 deletion api/packages.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package api

import (
_ "github.com/aptly-dev/aptly/deb" // for swagger
"github.com/gin-gonic/gin"
)

// GET /api/packages/:key
// @Summary Show packages
// @Description **Show information about package by package key**
// @Description Package keys could be obtained from various GET .../packages APIs.
// @Tags Packages
// @Produce json
// @Param key path string true "package key (unique package identifier)"
// @Success 200 {object} deb.Package "OK"
// @Failure 404 {object} Error "Not Found"
// @Router /api/packages/{key} [get]
func apiPackagesShow(c *gin.Context) {
collectionFactory := context.NewCollectionFactory()
p, err := collectionFactory.PackageCollection().ByKey([]byte(c.Params.ByName("key")))
Expand Down
Loading
Loading