diff --git a/api/mirror.go b/api/mirror.go index 3b3d721f..0052f2a5 100644 --- a/api/mirror.go +++ b/api/mirror.go @@ -32,9 +32,10 @@ func getVerifier(keyRings []string) (pgp.Verifier, error) { } // @Summary Get mirrors -// @Description Show list of currently available mirrors. Each mirror is returned as in “show” API. +// @Description **Show list of currently available mirrors** +// @Description Each mirror is returned as in “show” API. // @Tags Mirrors -// @Produce json +// @Produce json // @Success 200 {array} deb.RemoteRepo // @Router /api/mirrors [get] func apiMirrorsList(c *gin.Context) { @@ -50,45 +51,49 @@ func apiMirrorsList(c *gin.Context) { c.JSON(200, result) } +type mirrorCreateParams struct { + // Name of mirror to be created + Name string `binding:"required" json:"Name" example:"mirror2"` + // Url of the archive to mirror + ArchiveURL string `binding:"required" json:"ArchiveURL" example:"http://deb.debian.org/debian"` + // Distribution name to mirror + Distribution string ` json:"Distribution" example:"'buster', for flat repositories use './'"` + // Package query that is applied to mirror packages + Filter string ` json:"Filter" example:"xserver-xorg"` + // Components to mirror, if not specified aptly would fetch all components + Components []string ` json:"Components" example:"main"` + // Limit mirror to those architectures, if not specified aptly would fetch all architectures + Architectures []string ` json:"Architectures" example:"amd64"` + // Gpg keyring(s) for verifying Release file + Keyrings []string ` json:"Keyrings" example:"trustedkeys.gpg"` + // Set "true" to mirror source packages + DownloadSources bool ` json:"DownloadSources"` + // Set "true" to mirror udeb files + DownloadUdebs bool ` json:"DownloadUdebs"` + // Set "true" to mirror installer files + DownloadInstaller bool ` json:"DownloadInstaller"` + // Set "true" to include dependencies of matching packages when filtering + FilterWithDeps bool ` json:"FilterWithDeps"` + // Set "true" to skip if the given components are in the Release file + SkipComponentCheck bool ` json:"SkipComponentCheck"` + // Set "true" to skip the verification of architectures + SkipArchitectureCheck bool ` json:"SkipArchitectureCheck"` + // Set "true" to skip the verification of Release file signatures + IgnoreSignatures bool ` json:"IgnoreSignatures"` +} + // @Summary Create mirror -// @Description Create empty mirror with specified parameters. +// @Description **Create a mirror** // @Tags Mirrors -// @Accept json -// @Produce json -// @Param Name query string true "mirror name" -// @Param ArchiveURL query string true "url of the archive to mirror e.g. http://deb.debian.org/debian/" -// @Param Distribution query string false "distribution name to mirror e.g. `buster`, for flat repositories use `./` instead of distribution name" -// @Param Filter query string false "package query that is applied to packages in the mirror" -// @Param Components query []string false "components to mirror, if not specified aptly would fetch all components" -// @Param Architectures query []string false "limit mirror to those architectures, if not specified aptly would fetch all architectures" -// @Param Keyrings query []string false "gpg keyring(s) to use when verifying `Release` file" -// @Param DownloadSources query bool false "whether to mirror sources" -// @Param DownloadUdebs query bool false "whether to mirror `.udeb` packages (Debian installer support)" -// @Param DownloadInstaller query bool false "whether to download additional not packaged installer files" -// @Param FilterWithDeps query bool false "when filtering, include dependencies of matching packages as well" -// @Param SkipComponentCheck query bool false "whether to skip if the given components are in the `Release` file" -// @Param IgnoreSignatures query bool false "whether to skip the verification of `Release` file signatures" +// @Consume json +// @Param request body mirrorCreateParams true "Parameters" +// @Produce json // @Success 200 {object} deb.RemoteRepo // @Failure 400 {object} Error "Bad Request" // @Router /api/mirrors [post] func apiMirrorsCreate(c *gin.Context) { var err error - var b struct { - Name string `binding:"required"` - ArchiveURL string `binding:"required"` - Distribution string - Filter string - Components []string - Architectures []string - Keyrings []string - DownloadSources bool - DownloadUdebs bool - DownloadInstaller bool - FilterWithDeps bool - SkipComponentCheck bool - SkipArchitectureCheck bool - IgnoreSignatures bool - } + var b mirrorCreateParams b.DownloadSources = context.Config().DownloadSourcePackages b.IgnoreSignatures = context.Config().GpgDisableVerify @@ -155,12 +160,11 @@ func apiMirrorsCreate(c *gin.Context) { } // @Summary Delete Mirror -// @Description Delete a mirror +// @Description **Delete a mirror** // @Tags Mirrors -// @Consume json -// @Produce json // @Param name path string true "mirror name" // @Param force query int true "force: 1 to enable" +// @Produce json // @Success 200 {object} task.ProcessReturnValue // @Failure 404 {object} Error "Mirror not found" // @Failure 403 {object} Error "Unable to delete mirror with snapshots" @@ -205,11 +209,10 @@ func apiMirrorsDrop(c *gin.Context) { } // @Summary Show Mirror -// @Description Get mirror information by name +// @Description **Get mirror information by name** // @Tags Mirrors -// @Consume json -// @Produce json // @Param name path string true "mirror name" +// @Produce json // @Success 200 {object} deb.RemoteRepo // @Failure 404 {object} Error "Mirror not found" // @Failure 500 {object} Error "Internal Error" @@ -234,13 +237,12 @@ func apiMirrorsShow(c *gin.Context) { } // @Summary List Mirror Packages -// @Description Get a list of packages from a mirror +// @Description **Get a list of packages from a mirror** // @Tags Mirrors -// @Consume json -// @Produce json // @Param name path string true "mirror name" // @Param q query string false "search query" // @Param format query string false "format: `details` for more detailed information" +// @Produce json // @Success 200 {array} deb.Package "List of Packages" // @Failure 400 {object} Error "Unable to determine list of architectures" // @Failure 404 {object} Error "Mirror not found" @@ -323,26 +325,46 @@ func apiMirrorsPackages(c *gin.Context) { } } +type mirrorUpdateParams struct { + // Change mirror name to `Name` + Name string ` json:"Name" example:"mirror1"` + // Url of the archive to mirror + ArchiveURL string ` json:"ArchiveURL" example:"http://deb.debian.org/debian"` + // Package query that is applied to mirror packages + Filter string ` json:"Filter" example:"xserver-xorg"` + // Limit mirror to those architectures, if not specified aptly would fetch all architectures + Architectures []string ` json:"Architectures" example:"amd64"` + // Components to mirror, if not specified aptly would fetch all components + Components []string ` json:"Components" example:"main"` + // Gpg keyring(s) for verifing Release file + Keyrings []string ` json:"Keyrings" example:"trustedkeys.gpg"` + // Set "true" to include dependencies of matching packages when filtering + FilterWithDeps bool ` json:"FilterWithDeps"` + // Set "true" to mirror source packages + DownloadSources bool ` json:"DownloadSources"` + // Set "true" to mirror udeb files + DownloadUdebs bool ` json:"DownloadUdebs"` + // Set "true" to skip checking if the given components are in the Release file + SkipComponentCheck bool ` json:"SkipComponentCheck"` + // Set "true" to skip checking if the given architectures are in the Release file + SkipArchitectureCheck bool ` json:"SkipArchitectureCheck"` + // Set "true" to ignore checksum errors + IgnoreChecksums bool ` json:"IgnoreChecksums"` + // Set "true" to skip the verification of Release file signatures + IgnoreSignatures bool ` json:"IgnoreSignatures"` + // Set "true" to force a mirror update even if another process is already updating the mirror (use with caution!) + ForceUpdate bool ` json:"ForceUpdate"` + // Set "true" to skip downloading already downloaded packages + SkipExistingPackages bool ` json:"SkipExistingPackages"` +} + // @Summary Update Mirror -// @Description Update Mirror and download packages +// @Description **Update Mirror and download packages** // @Tags Mirrors -// @Consume json -// @Produce json // @Param name path string true "mirror name to update" -// @Param Name query string false "change mirror name" -// @Param ArchiveURL query string false "ArchiveURL" -// @Param Filter query string false "Filter" -// @Param Architectures query []string false "Architectures" -// @Param Components query []string false "Components" -// @Param Keyrings query []string false "Keyrings" -// @Param FilterWithDeps query bool false "FilterWithDeps" -// @Param DownloadSources query bool false "DownloadSources" -// @Param DownloadUdebs query bool false "DownloadUdebs" -// @Param SkipComponentCheck query bool false "SkipComponentCheck" -// @Param IgnoreChecksums query bool false "IgnoreChecksums" -// @Param IgnoreSignatures query bool false "IgnoreSignatures" -// @Param ForceUpdate query bool false "ForceUpdate" -// @Param SkipExistingPackages query bool false "SkipExistingPackages" +// @Consume json +// @Param request body mirrorUpdateParams true "Parameters" +// @Produce json // @Success 200 {object} task.ProcessReturnValue "Mirror was updated successfully" // @Success 202 {object} task.Task "Mirror is being updated" // @Failure 400 {object} Error "Unable to determine list of architectures" @@ -353,26 +375,9 @@ func apiMirrorsUpdate(c *gin.Context) { var ( err error remote *deb.RemoteRepo + b mirrorUpdateParams ) - var b struct { - Name string - ArchiveURL string - Filter string - Architectures []string - Components []string - Keyrings []string - FilterWithDeps bool - DownloadSources bool - DownloadUdebs bool - SkipComponentCheck bool - SkipArchitectureCheck bool - IgnoreChecksums bool - IgnoreSignatures bool - ForceUpdate bool - SkipExistingPackages bool - } - collectionFactory := context.NewCollectionFactory() collection := collectionFactory.RemoteRepoCollection() diff --git a/api/snapshot.go b/api/snapshot.go index 1948f278..3e84b1f2 100644 --- a/api/snapshot.go +++ b/api/snapshot.go @@ -408,7 +408,7 @@ func apiSnapshotsSearchPackages(c *gin.Context) { type snapshotsMergeParams struct { // List of snapshot names to be merged - Sources []string `binding:"required"` + Sources []string `binding:"required" json:"Sources" example:"snapshot1"` } // @Summary Snapshot Merge @@ -418,11 +418,11 @@ type snapshotsMergeParams struct { // @Description // @Description If only one snapshot is specified, merge copies source into destination. // @Tags Snapshots +// @Param name path string true "Name of the snapshot to be created" // @Param latest query int false "merge only the latest version of each package" // @Param no-remove query int false "all versions of packages are preserved during merge" -// @Accept json -// @Param name path string true "Name of the snapshot to be created" -// @Param request body snapshotsMergeParams true "json parameters" +// @Consume json +// @Param request body snapshotsMergeParams true "Parameters" // @Produce json // @Success 200 // @Failure 400 {object} Error "Bad Request" @@ -526,14 +526,14 @@ type snapshotsPullParams struct { // @Description // @Description Aptly pulls first package matching each of package queries, but with flag -all-matches all matching packages would be pulled. // @Tags Snapshots +// @Param name path string true "Name of the snapshot to be created" // @Param all-matches query int false "pull all the packages that satisfy the dependency version requirements (default is to pull first matching package): 1 to enable" // @Param dry-run query int false "don’t create destination snapshot, just show what would be pulled: 1 to enable" // @Param no-deps query int false "don’t process dependencies, just pull listed packages: 1 to enable" // @Param no-remove query int false "don’t remove other package versions when pulling package: 1 to enable" -// @Accept json -// @Param name path string true "Name of the snapshot to be created" -// @Param request body snapshotsPullParams true "json parameters" -// @Produce json +// @Consume json +// @Param request body snapshotsPullParams true "Parameters" +// @Produce json // @Success 200 // @Failure 400 {object} Error "Bad Request" // @Failure 404 {object} Error "Not Found"