-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1352 from aptly-dev/feature/storage-api
Feature/storage api
- Loading branch information
Showing
17 changed files
with
128 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ prepare: ## Install go module dependencies | |
go mod download | ||
# install and initialize swagger | ||
go install github.com/swaggo/swag/cmd/swag@latest | ||
PATH=$(BINPATH)/:$(PATH) swag init | ||
PATH=$(BINPATH)/:$(PATH) swag init -q | ||
go mod verify | ||
go mod tidy -v | ||
go generate | ||
|
@@ -70,8 +70,8 @@ docker-test: ## Run system tests | |
@rm -f aptly.test | ||
go generate | ||
# install and initialize swagger | ||
go install github.com/swaggo/swag/cmd/swag@latest | ||
PATH=$(BINPATH)/:$(PATH) swag init | ||
test -f $(BINPATH)/swag || go install github.com/swaggo/swag/cmd/swag@latest | ||
PATH=$(BINPATH)/:$(PATH) swag init -q | ||
# build coverage binary | ||
go test -v -coverpkg="./..." -c -tags testruncli | ||
@echo Running python tests ... | ||
|
@@ -126,7 +126,7 @@ releasetype: # Print release type (ci/release) | |
build: ## Build aptly | ||
# install and initialize swagger | ||
unset GOBIN; go install github.com/swaggo/swag/cmd/swag@latest | ||
PATH=$(BINPATH)/:$(PATH) swag init | ||
PATH=$(BINPATH)/:$(PATH) swag init -q | ||
# prepare | ||
go mod tidy | ||
go generate | ||
|
@@ -137,15 +137,15 @@ dev-server: prepare ## Run dev-server | |
go install github.com/air-verse/[email protected] | ||
cp debian/aptly.conf /var/lib/aptly/.aptly.conf | ||
sed -i /enableSwaggerEndpoint/s/false/true/ /var/lib/aptly/.aptly.conf | ||
PATH=$(BINPATH):$$PATH air -build.pre_cmd 'swag init' -build.exclude_dir system -build.exclude_dir debian -build.exclude_dir docs -- api serve -listen 0.0.0.0:3142 | ||
PATH=$(BINPATH):$$PATH air -build.pre_cmd 'swag init -q' -build.exclude_dir system -build.exclude_dir debian -build.exclude_dir docs -- api serve -listen 0.0.0.0:3142 | ||
|
||
dpkg: ## Build debian packages | ||
@test -n "$(DEBARCH)" || (echo "please define DEBARCH"; exit 1) | ||
# go generate | ||
GOPATH=$$PWD/.go go generate -v | ||
# install and initialize swagger | ||
go install github.com/swaggo/swag/cmd/swag@latest | ||
PATH=$(BINPATH)/:$(PATH) swag init | ||
PATH=$(BINPATH)/:$(PATH) swag init -q | ||
# set debian version | ||
@if [ "`make -s releasetype`" = "ci" ]; then \ | ||
echo CI Build, setting version... ; \ | ||
|
@@ -169,7 +169,7 @@ binaries: ## Build binary releases (FreeBSD, MacOS, Linux tar) | |
@make version > VERSION | ||
# install and initialize swagger | ||
GOOS=linux GOARCH=amd64 go install github.com/swaggo/swag/cmd/swag@latest | ||
PATH=$(BINPATH)/:$(PATH) swag init | ||
PATH=$(BINPATH)/:$(PATH) swag init -q | ||
# build aptly | ||
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o build/tmp/aptly -ldflags='-extldflags=-static' | ||
# install | ||
|
@@ -194,7 +194,7 @@ docker-image: ## Build aptly-dev docker image | |
docker-build: ## Build aptly in docker container | ||
@docker run -it --rm -v ${PWD}:/work/src aptly-dev /work/src/system/run-aptly-cmd make build | ||
|
||
docker-aptly: ## Build and run aptly commands in docker container | ||
docker-shell: ## Run aptly and other commands in docker container | ||
@docker run -it --rm -v ${PWD}:/work/src aptly-dev /work/src/system/run-aptly-cmd | ||
|
||
docker-deb: ## Build debian packages in docker container | ||
|
@@ -222,4 +222,4 @@ clean: ## remove local build and module cache | |
test -d .go/ && chmod u+w -R .go/ && rm -rf .go/ || true | ||
rm -rf build/ docs/ obj-*-linux-gnu* | ||
|
||
.PHONY: help man prepare version binaries docker-release docker-system-tests docker-unit-tests docker-lint docker-build docker-image build docker-aptly clean releasetype dpkg dev-server docker-dev-server | ||
.PHONY: help man prepare version binaries docker-release docker-system-tests docker-unit-tests docker-lint docker-build docker-image build docker-shell clean releasetype dpkg dev-server docker-dev-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type diskFree struct { | ||
// Storage size [MiB] | ||
Total uint64 | ||
// Available Storage [MiB] | ||
Free uint64 | ||
// Percentage Full | ||
PercentFull float32 | ||
} | ||
|
||
// @Summary Get Storage Utilization | ||
// @Description **Get disk free information of aptly storage** | ||
// @Tags Status | ||
// @Produce json | ||
// @Success 200 {object} diskFree "Storage information" | ||
// @Failure 400 {object} Error "Internal Error" | ||
// @Router /api/storage [get] | ||
func apiDiskFree(c *gin.Context) { | ||
var df diskFree | ||
|
||
fs := context.Config().GetRootDir() | ||
|
||
var stat syscall.Statfs_t | ||
err := syscall.Statfs(fs, &stat) | ||
if err != nil { | ||
AbortWithJSONError(c, 400, fmt.Errorf("Error getting storage info on %s: %s", fs, err)) | ||
return | ||
} | ||
|
||
df.Total = uint64(stat.Blocks) * uint64(stat.Bsize) / 1048576 | ||
df.Free = uint64(stat.Bavail) * uint64(stat.Bsize) / 1048576 | ||
df.PercentFull = 100.0 - float32(stat.Bavail)/float32(stat.Blocks)*100.0 | ||
|
||
c.JSON(200, df) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from api_lib import APITest | ||
|
||
|
||
class TaskAPITestSwaggerDocs(APITest): | ||
""" | ||
GET /docs | ||
""" | ||
|
||
def check(self): | ||
resp = self.get("/api/storage") | ||
self.check_equal(resp.status_code, 200) |
Oops, something went wrong.