diff --git a/docs/swagger.json b/api/swagger.json similarity index 96% rename from docs/swagger.json rename to api/swagger.json index 7e1d92b..ea9222d 100644 --- a/docs/swagger.json +++ b/api/swagger.json @@ -5,9 +5,9 @@ "title": "ClusterCockpit REST API", "termsOfService": "TODO", "contact": { - "name": "HPC-Support", + "name": "ClusterCockpit project", "url": "TODO", - "email": "hpc-support@fau.de" + "email": "support@clustercockpit.org" }, "license": { "name": "MIT License", @@ -15,7 +15,7 @@ }, "version": "0.1.0" }, - "host": "clustercockpit.localhost:8082", + "host": "localhost:8080", "basePath": "/api", "paths": { "/jobs/": { @@ -385,23 +385,6 @@ } } }, - "api.TagJobApiRequest": { - "description": "Request to tag a job.", - "type": "array", - "items": { - "type": "object", - "properties": { - "error": { - "description": "Error Message", - "type": "string" - }, - "status": { - "description": "Statustext of Errorcode", - "type": "string" - } - } - } - }, "schema.Job": { "type": "object", "properties": { @@ -525,4 +508,4 @@ "in": "header" } } -} +} \ No newline at end of file diff --git a/docs/swagger.yaml b/api/swagger.yaml similarity index 96% rename from docs/swagger.yaml rename to api/swagger.yaml index cba0d09..ed46e9d 100644 --- a/docs/swagger.yaml +++ b/api/swagger.yaml @@ -10,18 +10,6 @@ definitions: description: Statustext of Errorcode type: string type: object - api.TagJobApiRequest: - description: Request to tag a job boii - items: - properties: - name: - description: Tag Name - type: string - type: - description: Tag Type - type: string - type: object - type: array api.StartJobApiResponse: description: Successful job start response with database id of new job. properties: @@ -125,11 +113,11 @@ definitions: type: type: string type: object -host: clustercockpit.localhost:8082 +host: localhost:8080 info: contact: - email: hpc-support@fau.de - name: HPC-Support + email: support@clustercockpit.org + name: ClusterCockpit project url: TODO description: Array of tag-objects for request payload license: diff --git a/cmd/cc-backend/main.go b/cmd/cc-backend/main.go index 7ad5382..35852b0 100644 --- a/cmd/cc-backend/main.go +++ b/cmd/cc-backend/main.go @@ -40,12 +40,11 @@ import ( "github.com/google/gops/agent" "github.com/gorilla/handlers" "github.com/gorilla/mux" - "github.com/swaggo/http-swagger" + httpSwagger "github.com/swaggo/http-swagger" _ "github.com/go-sql-driver/mysql" _ "github.com/mattn/go-sqlite3" _ "github.com/santhosh-tekuri/jsonschema/v5/httploader" - _ "github.com/ClusterCockpit/cc-backend/docs" ) func main() { @@ -264,7 +263,9 @@ func main() { if flagDev { r.Handle("/playground", playground.Handler("GraphQL playground", "/query")) - secured.PathPrefix("/docs").Handler(httpSwagger.WrapHandler) + // secured.PathPrefix("/docs").Handler(httpSwagger.WrapHandler) + r.PathPrefix("/swagger/").Handler(httpSwagger.Handler( + httpSwagger.URL("http://localhost:8080/swagger/doc.json"))).Methods(http.MethodGet) } secured.Handle("/query", graphQLEndpoint) diff --git a/go.mod b/go.mod index deef30c..7fb1ac4 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect github.com/deepmap/oapi-codegen v1.11.0 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect + github.com/ghodss/yaml v1.0.0 // indirect github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect diff --git a/go.sum b/go.sum index a9937f5..7df1b7e 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,7 @@ github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBd github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= github.com/getkin/kin-openapi v0.94.0/go.mod h1:LWZfzOd7PRy8GJ1dJ6mCU6tNdSfOwRac1BUPam4aw6Q= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= diff --git a/docs/docs.go b/internal/api/docs.go similarity index 95% rename from docs/docs.go rename to internal/api/docs.go index 8bc1e9c..550027d 100644 --- a/docs/docs.go +++ b/internal/api/docs.go @@ -1,7 +1,6 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag at -// 2022-09-15 11:56:55.737680755 +0200 CEST m=+0.135609460 -package docs +// Package api GENERATED BY SWAG; DO NOT EDIT +// This file was generated by swaggo/swag +package api import "github.com/swaggo/swag" @@ -13,9 +12,9 @@ const docTemplate = `{ "title": "{{.Title}}", "termsOfService": "TODO", "contact": { - "name": "HPC-Support", + "name": "ClusterCockpit project", "url": "TODO", - "email": "hpc-support@fau.de" + "email": "support@clustercockpit.org" }, "license": { "name": "MIT License", @@ -393,23 +392,6 @@ const docTemplate = `{ } } }, - "api.TagJobApiRequest": { - "description": "Request to tag a job.", - "type": "array", - "items": { - "type": "object", - "properties": { - "error": { - "description": "Error Message", - "type": "string" - }, - "status": { - "description": "Statustext of Errorcode", - "type": "string" - } - } - } - }, "schema.Job": { "type": "object", "properties": { @@ -538,11 +520,11 @@ const docTemplate = `{ // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ Version: "0.1.0", - Host: "clustercockpit.localhost:8082", + Host: "localhost:8080", BasePath: "/api", Schemes: []string{}, Title: "ClusterCockpit REST API", - Description: "API for batch job control.", + Description: "Array of tag-objects for request payload", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, } diff --git a/internal/api/rest.go b/internal/api/rest.go index e42965a..c876481 100644 --- a/internal/api/rest.go +++ b/internal/api/rest.go @@ -35,12 +35,12 @@ import ( // @version 0.1.0 // @description API for batch job control. // @termsOfService TODO -// @contact.name HPC-Support +// @contact.name ClusterCockpit project // @contact.url TODO -// @contact.email hpc-support@fau.de +// @contact.email support@clustercockpit.org // @license.name MIT License // @license.url https://opensource.org/licenses/MIT -// @host clustercockpit.localhost:8082 +// @host localhost:8080 // @BasePath /api // @securityDefinitions.apikey ApiKeyAuth // @in header @@ -97,11 +97,11 @@ type StartJobApiResponse struct { // @Description They are only used if no database id was provided. type StopJobApiRequest struct { // Stop Time as Epoch - StopTime int64 `json:"stopTime"` - State schema.JobState `json:"jobState"` // Final job state - JobId *int64 `json:"jobId"` // Job ID of job (Optional) - Cluster *string `json:"cluster"` // Cluster of job (Optional) - StartTime *int64 `json:"startTime"` // Start Time of job (Optional) + StopTime int64 `json:"stopTime"` + State schema.JobState `json:"jobState"` // Final job state + JobId *int64 `json:"jobId"` // Job ID of job (Optional) + Cluster *string `json:"cluster"` // Cluster of job (Optional) + StartTime *int64 `json:"startTime"` // Start Time of job (Optional) } // ErrorResponse model @@ -136,8 +136,6 @@ func decode(r io.Reader, val interface{}) error { return dec.Decode(val) } - - // getJobs godoc // @Summary List all jobs // @Description Get a list of all jobs. Filters can be applied using query parameters. @@ -427,8 +425,8 @@ func (api *RestApi) stopJobById(rw http.ResponseWriter, r *http.Request) { job, err = api.JobRepository.FindById(id) } else { - handleError(errors.New("the parameter 'id' is required"), http.StatusBadRequest, rw) - return + handleError(errors.New("the parameter 'id' is required"), http.StatusBadRequest, rw) + return } if err != nil { handleError(fmt.Errorf("finding job failed: %w", err), http.StatusUnprocessableEntity, rw) @@ -627,7 +625,6 @@ func (api *RestApi) stopJobByRequest(rw http.ResponseWriter, r *http.Request) { // rw.Write([]byte(`{ "status": "OK" }`)) // } - func (api *RestApi) getJobMetrics(rw http.ResponseWriter, r *http.Request) { id := mux.Vars(r)["id"] metrics := r.URL.Query()["metric"] @@ -670,9 +667,6 @@ func (api *RestApi) getJobMetrics(rw http.ResponseWriter, r *http.Request) { }) } - - - func (api *RestApi) getJWT(rw http.ResponseWriter, r *http.Request) { rw.Header().Set("Content-Type", "text/plain") username := r.FormValue("username") @@ -787,10 +781,6 @@ func (api *RestApi) updateConfiguration(rw http.ResponseWriter, r *http.Request) rw.Write([]byte("success")) } - - - - func (api *RestApi) putMachineState(rw http.ResponseWriter, r *http.Request) { if api.MachineStateDir == "" { http.Error(rw, "not enabled", http.StatusNotFound) diff --git a/tools.go b/tools.go index 8e7c1b2..950056c 100644 --- a/tools.go +++ b/tools.go @@ -3,4 +3,7 @@ package tools -import _ "github.com/99designs/gqlgen" +import ( + _ "github.com/99designs/gqlgen" + _ "github.com/swaggo/swag/cmd/swag" +)