diff --git a/.gitignore b/.gitignore index 0e6380b..91c71eb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ *.dll *.so *.dylib -QMS +qms # Test binary, built with `go test -c` *.test diff --git a/Dockerfile b/Dockerfile index 4bba620..334c37b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ RUN go install github.com/jstemmer/go-junit-report@latest ENV CGO_ENABLED=0 -WORKDIR /go/src/github.com/cyverse-de/QMS +WORKDIR /go/src/github.com/cyverse-de/qms COPY . . RUN make @@ -12,10 +12,10 @@ FROM debian:stable-slim WORKDIR /app -COPY --from=0 /go/src/github.com/cyverse-de/QMS/QMS /bin/QMS -COPY --from=0 /go/src/github.com/cyverse-de/QMS/swagger.json swagger.json -COPY --from=0 /go/src/github.com/cyverse-de/QMS/migrations migrations +COPY --from=0 /go/src/github.com/cyverse-de/qms/qms /bin/qms +COPY --from=0 /go/src/github.com/cyverse-de/qms/swagger.json swagger.json +COPY --from=0 /go/src/github.com/cyverse-de/qms/migrations migrations -ENTRYPOINT ["QMS"] +ENTRYPOINT ["qms"] EXPOSE 8080 diff --git a/Makefile b/Makefile index 166bb2e..abd69d9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: QMS +all: qms install-swagger: which swagger || go install github.com/go-swagger/go-swagger/cmd/swagger@latest @@ -6,10 +6,16 @@ install-swagger: swagger.json: install-swagger swagger generate spec -o ./swagger.json --scan-models -QMS: swagger.json +qms: swagger.json go build --buildvcs=false . clean: - rm -rf QMS swagger.json + rm -rf qms swagger.json -.PHONY: install-swagger clean all +lint: + golangci-lint run + +test: + go test ./... + +.PHONY: install-swagger clean all lint test diff --git a/README.md b/README.md index af24175..d2383c4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# QMS +# qms -QMS is the CyVerse Quota Management System. Its purpose is to keep track of resource usage limits and totals for +qms is the CyVerse Quota Management System. Its purpose is to keep track of resource usage limits and totals for CyVerse users. ## Concepts @@ -20,21 +20,21 @@ user. Quotas can be customized if necessary, but customizing quotas should be a ### Current Usage -The QMS tracks the current resource usage totals for each CyVerse user. These usage totals are calculated by other -CyVerse microservices and reported to the QMS. +The qms tracks the current resource usage totals for each CyVerse user. These usage totals are calculated by other +CyVerse microservices and reported to the qms. ### Updates -Updates to both quotas and resource usage totals are recorded in the QMS database for auditing purposes. +Updates to both quotas and resource usage totals are recorded in the qms database for auditing purposes. ## Configuration Settings -The QMS uses environment variables for its configuration settings. The following configuration settings are supported. +The qms uses environment variables for its configuration settings. The following configuration settings are supported. ### QMS_DATABASE_URI (Required) -This environment variable contains the database connection URI. The QMS uses a PostgreSQL database to keep track of -its data. Any version of PostgreSQL that supports the required extensions should work, but the QMS has been tested +This environment variable contains the database connection URI. The qms uses a PostgreSQL database to keep track of +its data. Any version of PostgreSQL that supports the required extensions should work, but the qms has been tested against versions 12, 13, and 14. The following extensions are required: 1. uuid-ossp @@ -58,20 +58,20 @@ postgresql://dbuser@dbhost.example.org:5432/dbname?sslmode=disable ### QMS_DATABASE_MIGRATE (Optional, Default: `false`) -If this environment variable is defined and set to `true` then QMS will automatically run database schema migrations +If this environment variable is defined and set to `true` then qms will automatically run database schema migrations on startup. ### QMS_DATABASE_REINIT (Optional, Default: `false`) -If this environment variable is defined and set to `true` then the QMS will reinitialize the database upon startup. +If this environment variable is defined and set to `true` then the qms will reinitialize the database upon startup. This feature is intended to be used only during development testing, when the schema migrations are being actively updated. Note: this parameter is only applicable if `QMS_DATABASE_MIGRATE` is also enabled. ## Database Schema Migraions -The QMS runs its schema migrations upon startup. For this to succeed, two prerequisites must be satisfied. The first +The qms runs its schema migrations upon startup. For this to succeed, two prerequisites must be satisfied. The first requirement is that the database must exist and must have the required extensions listed above installed. Having the -extensions installed in advance allows QMS to use a regular PostgreSQL account instead of requiring an administrative +extensions installed in advance allows qms to use a regular PostgreSQL account instead of requiring an administrative account. The second requirement is that the schema migrations must exist in a subdirectory of the current working directory diff --git a/config/config.go b/config/config.go index e3108e1..56c80fe 100644 --- a/config/config.go +++ b/config/config.go @@ -6,9 +6,9 @@ import ( "github.com/cyverse-de/go-mod/cfg" ) -var ServiceName = "QMS" +var ServiceName = "qms" -// Specification defines the configuration settings for the QMS service. +// Specification defines the configuration settings for the qms service. type Specification struct { DatabaseURI string RunSchemaMigrations bool @@ -19,7 +19,7 @@ type Specification struct { UsernameSuffix string } -// LoadConfig loads the configuration for the QMS service. +// LoadConfig loads the configuration for the qms service. func LoadConfig(envPrefix, configPath, dotEnvPath string) (*Specification, error) { k, err := cfg.Init(&cfg.Settings{ EnvPrefix: envPrefix, diff --git a/go.mod b/go.mod index f0ca086..ddc44a7 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/cyverse/QMS +module github.com/cyverse/qms go 1.21 diff --git a/internal/controllers/admins.go b/internal/controllers/admins.go index ac0c40e..50c6e59 100644 --- a/internal/controllers/admins.go +++ b/internal/controllers/admins.go @@ -5,7 +5,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/model" "github.com/labstack/echo/v4" ) diff --git a/internal/controllers/plans.go b/internal/controllers/plans.go index 3bbbc01..f6be52a 100644 --- a/internal/controllers/plans.go +++ b/internal/controllers/plans.go @@ -7,9 +7,9 @@ import ( "gorm.io/gorm/clause" "github.com/cyverse-de/echo-middleware/v2/params" - "github.com/cyverse/QMS/internal/db" - "github.com/cyverse/QMS/internal/httpmodel" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/db" + "github.com/cyverse/qms/internal/httpmodel" + "github.com/cyverse/qms/internal/model" "github.com/labstack/echo/v4" "github.com/sirupsen/logrus" "gorm.io/gorm" diff --git a/internal/controllers/resource_types.go b/internal/controllers/resource_types.go index 34e64de..4d22855 100644 --- a/internal/controllers/resource_types.go +++ b/internal/controllers/resource_types.go @@ -6,7 +6,7 @@ import ( "net/http" "github.com/cyverse-de/echo-middleware/v2/params" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/model" "github.com/labstack/echo/v4" "github.com/sirupsen/logrus" "gorm.io/gorm" @@ -26,7 +26,7 @@ func extractResourceTypeID(ctx echo.Context) (string, error) { // // List Resource Types // -// Lists all the resource types defined in the QMS database. +// Lists all the resource types defined in the qms database. // // responses: // 200: resourceTypeListing @@ -53,7 +53,7 @@ func (s Server) ListResourceTypes(ctx echo.Context) error { // // Add Resource Type // -// Adds a new resource type to the QMS database. +// Adds a new resource type to the qms database. // // responses: // 200: resourceTypeDetails @@ -151,7 +151,7 @@ func (s Server) GetResourceTypeDetails(ctx echo.Context) error { // // Update Resource Type // -// Updates an existing resource type in the QMS database. +// Updates an existing resource type in the qms database. // // responses: // 200: resourceTypeDetails diff --git a/internal/controllers/root.go b/internal/controllers/root.go index 6d466e3..2755b2d 100644 --- a/internal/controllers/root.go +++ b/internal/controllers/root.go @@ -4,8 +4,8 @@ import ( "database/sql" "net/http" - "github.com/cyverse/QMS/internal/model" - "github.com/cyverse/QMS/logging" + "github.com/cyverse/qms/internal/model" + "github.com/cyverse/qms/logging" "github.com/labstack/echo/v4" "github.com/sirupsen/logrus" "gorm.io/gorm" @@ -13,7 +13,7 @@ import ( var log = logging.GetLogger().WithFields(logrus.Fields{"package": "controllers"}) -// Server defines the REST API of the QMS +// Server defines the REST API of the qms type Server struct { Router *echo.Echo DB *sql.DB diff --git a/internal/controllers/subscriptions.go b/internal/controllers/subscriptions.go index 74ad69a..743eb98 100644 --- a/internal/controllers/subscriptions.go +++ b/internal/controllers/subscriptions.go @@ -5,9 +5,9 @@ import ( "fmt" "net/http" - "github.com/cyverse/QMS/internal/db" - "github.com/cyverse/QMS/internal/model" - "github.com/cyverse/QMS/internal/query" + "github.com/cyverse/qms/internal/db" + "github.com/cyverse/qms/internal/model" + "github.com/cyverse/qms/internal/query" "github.com/labstack/echo/v4" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/internal/controllers/usages.go b/internal/controllers/usages.go index 4694289..7e8bc48 100644 --- a/internal/controllers/usages.go +++ b/internal/controllers/usages.go @@ -7,8 +7,8 @@ import ( "strings" "time" - "github.com/cyverse/QMS/internal/db" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/db" + "github.com/cyverse/qms/internal/model" "github.com/labstack/echo/v4" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/internal/controllers/users.go b/internal/controllers/users.go index 719f879..7f26619 100644 --- a/internal/controllers/users.go +++ b/internal/controllers/users.go @@ -10,11 +10,11 @@ import ( "github.com/cyverse-de/go-mod/pbinit" "github.com/cyverse-de/p/go/qms" - "github.com/cyverse/QMS/internal/db" - "github.com/cyverse/QMS/internal/httpmodel" - "github.com/cyverse/QMS/internal/model" - "github.com/cyverse/QMS/internal/model/timestamp" - "github.com/cyverse/QMS/internal/query" + "github.com/cyverse/qms/internal/db" + "github.com/cyverse/qms/internal/httpmodel" + "github.com/cyverse/qms/internal/model" + "github.com/cyverse/qms/internal/model/timestamp" + "github.com/cyverse/qms/internal/query" "github.com/labstack/echo/v4" "github.com/sirupsen/logrus" ) @@ -28,7 +28,7 @@ const ( // // List Users // -// Lists the users registered in the QMS database. +// Lists the users registered in the qms database. // // responses: // 200: userListing @@ -199,7 +199,7 @@ func (s Server) GetUserOverages(ctx echo.Context) error { responseList := pbinit.NewOverageList() - // Skip the remaining logic because QMS is configured to not report overages. + // Skip the remaining logic because qms is configured to not report overages. if !s.ReportOverages { return model.ProtobufJSON(ctx, responseList, http.StatusOK) } @@ -240,7 +240,7 @@ func (s Server) InOverage(ctx echo.Context) error { response := pbinit.NewIsOverage() - // Skip the rest of the logic because QMS is configured to not report overages + // Skip the rest of the logic because qms is configured to not report overages if !s.ReportOverages { response.IsOverage = false return model.ProtobufJSON(ctx, response, http.StatusOK) diff --git a/internal/controllers/util.go b/internal/controllers/util.go index 3823756..8516a06 100644 --- a/internal/controllers/util.go +++ b/internal/controllers/util.go @@ -5,8 +5,8 @@ import ( "fmt" "net/http" - "github.com/cyverse/QMS/internal/db" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/db" + "github.com/cyverse/qms/internal/model" "github.com/labstack/echo/v4" ) diff --git a/internal/db/plan.go b/internal/db/plan.go index a4296b0..a74641f 100644 --- a/internal/db/plan.go +++ b/internal/db/plan.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/model" "github.com/pkg/errors" "gorm.io/gorm" ) diff --git a/internal/db/resource_types.go b/internal/db/resource_types.go index 29b938c..9415b94 100644 --- a/internal/db/resource_types.go +++ b/internal/db/resource_types.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/model" "github.com/pkg/errors" "gorm.io/gorm" ) diff --git a/internal/db/subscriptions.go b/internal/db/subscriptions.go index 3c73f01..cd4d379 100644 --- a/internal/db/subscriptions.go +++ b/internal/db/subscriptions.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/model" "github.com/pkg/errors" "gorm.io/gorm" "gorm.io/gorm/clause" diff --git a/internal/db/usage.go b/internal/db/usage.go index 5e89e9b..efc98b0 100644 --- a/internal/db/usage.go +++ b/internal/db/usage.go @@ -3,7 +3,7 @@ package db import ( "context" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/model" "gorm.io/gorm" "gorm.io/gorm/clause" ) diff --git a/internal/db/user.go b/internal/db/user.go index bbfbfb9..bd11aa4 100644 --- a/internal/db/user.go +++ b/internal/db/user.go @@ -3,7 +3,7 @@ package db import ( "context" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/model" "github.com/pkg/errors" "gorm.io/gorm" "gorm.io/gorm/clause" diff --git a/internal/httpmodel/new_plan.go b/internal/httpmodel/new_plan.go index 8027655..a3dd3c5 100644 --- a/internal/httpmodel/new_plan.go +++ b/internal/httpmodel/new_plan.go @@ -3,7 +3,7 @@ package httpmodel import ( "fmt" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/model" ) // Note: the names in the comments may deviate a bit from the actual structure names in order to avoid producing diff --git a/internal/model/subscriptions.go b/internal/model/subscriptions.go index 8918eee..f15f235 100644 --- a/internal/model/subscriptions.go +++ b/internal/model/subscriptions.go @@ -3,7 +3,7 @@ package model import ( "time" - "github.com/cyverse/QMS/internal/model/timestamp" + "github.com/cyverse/qms/internal/model/timestamp" ) // SubscriptionOptions represents options that can be applied to a new subscription. diff --git a/internal/model/update.go b/internal/model/update.go index 42f6d8e..9cbd143 100644 --- a/internal/model/update.go +++ b/internal/model/update.go @@ -10,7 +10,7 @@ const ( ValueTypeUsages = "usages" ) -// UpdateOperation defines the structure of an available update operation in the QMS database. +// UpdateOperation defines the structure of an available update operation in the qms database. // // swagger:model type UpdateOperation struct { diff --git a/internal/swagger/swagger.go b/internal/swagger/swagger.go index 79ca47b..e8648a0 100644 --- a/internal/swagger/swagger.go +++ b/internal/swagger/swagger.go @@ -1,6 +1,6 @@ -// Package api QMS +// Package api qms // -// Documentation of the QMS Api +// Documentation of the qms Api // // Schemes: http // BasePath: / @@ -16,9 +16,9 @@ package swagger import ( - "github.com/cyverse/QMS/internal/controllers" - "github.com/cyverse/QMS/internal/httpmodel" - "github.com/cyverse/QMS/internal/model" + "github.com/cyverse/qms/internal/controllers" + "github.com/cyverse/qms/internal/httpmodel" + "github.com/cyverse/qms/internal/model" ) // Note: the comments in this package don't conform to the convention of including the name of the entity that the diff --git a/logging/logging.go b/logging/logging.go index a8348c9..386c721 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -2,7 +2,7 @@ package logging import ( gomodlog "github.com/cyverse-de/go-mod/logging" - "github.com/cyverse/QMS/config" + "github.com/cyverse/qms/config" "github.com/sirupsen/logrus" ) diff --git a/main.go b/main.go index b30b9f4..5c78d1e 100644 --- a/main.go +++ b/main.go @@ -8,9 +8,9 @@ import ( "github.com/cyverse-de/go-mod/cfg" "github.com/cyverse-de/go-mod/otelutils" - "github.com/cyverse/QMS/config" - "github.com/cyverse/QMS/logging" - "github.com/cyverse/QMS/server" + "github.com/cyverse/qms/config" + "github.com/cyverse/qms/logging" + "github.com/cyverse/qms/server" "github.com/golang-migrate/migrate/v4" _ "github.com/golang-migrate/migrate/v4/database/postgres" _ "github.com/golang-migrate/migrate/v4/source/file" diff --git a/server/router.go b/server/router.go index 8f9ba44..2ddcae7 100644 --- a/server/router.go +++ b/server/router.go @@ -2,7 +2,7 @@ package server import ( "github.com/cyverse-de/echo-middleware/v2/redoc" - "github.com/cyverse/QMS/internal/controllers" + "github.com/cyverse/qms/internal/controllers" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -32,7 +32,7 @@ func InitRouter() *echo.Echo { e.Logger = echoLogger // Add middleware. - e.Use(otelecho.Middleware("QMS")) + e.Use(otelecho.Middleware("qms")) e.Use(echoLogger.Hook()) e.Use(middleware.Recover()) e.Use(redoc.Serve(redoc.Opts{Title: "CyVerse Quota Management System"})) diff --git a/server/server.go b/server/server.go index bd8d2e2..93fd218 100644 --- a/server/server.go +++ b/server/server.go @@ -3,10 +3,10 @@ package server import ( "fmt" - "github.com/cyverse/QMS/config" - "github.com/cyverse/QMS/internal/controllers" - "github.com/cyverse/QMS/internal/db" - "github.com/cyverse/QMS/logging" + "github.com/cyverse/qms/config" + "github.com/cyverse/qms/internal/controllers" + "github.com/cyverse/qms/internal/db" + "github.com/cyverse/qms/logging" "github.com/sirupsen/logrus" )