From d9452951a875c554de4b9070490e6e001d6a8ee4 Mon Sep 17 00:00:00 2001 From: Pierre Ecarlat <pecarlat@grandlyon.com> Date: Fri, 23 Aug 2024 11:09:29 +0200 Subject: [PATCH] renamed tkoen --- .env.template | 3 +- .gitlab-ci.yml | 4 +- docs/swagger.json | 1489 ++++++++++++++++++++ docs/swagger.yaml | 985 +++++++++++++ internal/auth/auth.go | 8 +- internal/rootmux/rootmux_test.go | 6 +- k8s/secrets/ecolyo-agent-server-config.yml | 2 +- package-lock.json | 6 + 8 files changed, 2491 insertions(+), 12 deletions(-) create mode 100644 docs/swagger.json create mode 100644 docs/swagger.yaml create mode 100644 package-lock.json diff --git a/.env.template b/.env.template index f01896f..05ab3a8 100644 --- a/.env.template +++ b/.env.template @@ -20,8 +20,7 @@ DATABASE_USER DATABASE_PASSWORD DATABASE_NAME -# rename this to backoffice token ? -SGE_API_TOKEN +BO_API_TOKEN GRDF_CLIENT_ID GRDF_CLIENT_SECRET diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9bb7369..258ea31 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -141,7 +141,7 @@ deploy_rec: - sed -i "s/{{DATABASE_PASSWORD}}/$REC_DATABASE_PASSWORD/" ./k8s/secrets/ecolyo-agent-database.yml - sed -i "s/{{CLIENT_ID}}/$REC_CLIENT_ID/" ./k8s/secrets/ecolyo-agent-server-config.yml - sed -i "s/{{CLIENT_SECRET}}/$REC_CLIENT_SECRET/" ./k8s/secrets/ecolyo-agent-server-config.yml - - sed -i "s/{{SGE_API_TOKEN}}/$REC_SGE_API_TOKEN/" ./k8s/secrets/ecolyo-agent-server-config.yml + - sed -i "s/{{BO_API_TOKEN}}/$REC_BO_API_TOKEN/" ./k8s/secrets/ecolyo-agent-server-config.yml - sed -i "s/{{GRDF_CLIENT_ID}}/$GRDF_CLIENT_ID/" ./k8s/secrets/ecolyo-agent-server-config.yml - sed -i "s/{{GRDF_CLIENT_SECRET}}/$GRDF_CLIENT_SECRET/" ./k8s/secrets/ecolyo-agent-server-config.yml - sed -i "s/{{HOSTNAME}}/ecolyo-agent-rec.apps.grandlyon.com/g" ./k8s/secrets/ecolyo-agent-server-config.yml @@ -173,7 +173,7 @@ deploy_prod: - sed -i "s/{{DATABASE_PASSWORD}}/$PROD_DATABASE_PASSWORD/" ./k8s/secrets/ecolyo-agent-database.yml - sed -i "s/{{CLIENT_ID}}/$PROD_CLIENT_ID/" ./k8s/secrets/ecolyo-agent-server-config.yml - sed -i "s/{{CLIENT_SECRET}}/$PROD_CLIENT_SECRET/" ./k8s/secrets/ecolyo-agent-server-config.yml - - sed -i "s/{{SGE_API_TOKEN}}/$PROD_SGE_API_TOKEN/" ./k8s/secrets/ecolyo-agent-server-config.yml + - sed -i "s/{{BO_API_TOKEN}}/$PROD_BO_API_TOKEN/" ./k8s/secrets/ecolyo-agent-server-config.yml - sed -i "s/{{GRDF_CLIENT_ID}}/$GRDF_CLIENT_ID/" ./k8s/secrets/ecolyo-agent-server-config.yml - sed -i "s/{{GRDF_CLIENT_SECRET}}/$GRDF_CLIENT_SECRET/" ./k8s/secrets/ecolyo-agent-server-config.yml - sed -i "s/{{HOSTNAME}}/ecolyo-agent.apps.grandlyon.com/g" ./k8s/secrets/ecolyo-agent-server-config.yml diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..6d21452 --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,1489 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is backend of Ecolyo-Agent, a backoffice managing newsletters, SGE consents, fluid prices and custom alerts for Ecolyo", + "title": "Ecolyo-Agent API", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "API Support", + "email": "rpailharey@grandlyon.com" + }, + "version": "1.0.0" + }, + "paths": { + "/api/admin/consent": { + "get": { + "description": "Search for consents based on the pointID", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Search for consents", + "parameters": [ + { + "type": "string", + "description": "pointID to search", + "name": "search", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.GrdfConsentSwagger" + } + } + }, + "400": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/admin/sge/consent": { + "get": { + "description": "Search for consents based on the pointID", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Search for consents", + "parameters": [ + { + "type": "string", + "description": "pointID to search", + "name": "search", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.SgeConsentSwagger" + } + } + }, + "400": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/customPopup": { + "put": { + "description": "Update custom popup content", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "customPopup" + ], + "summary": "Update custom popup content", + "parameters": [ + { + "description": "CustomPopup to create/update with new content", + "name": "customPopup", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.CustomPopup" + } + } + ], + "responses": { + "200": { + "description": "Updated successfully", + "schema": { + "$ref": "#/definitions/models.CustomPopup" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/mailSubject": { + "put": { + "description": "Create/update a specific mailSubject' content", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "mailSubject" + ], + "summary": "Create/update a specific mailSubject' content", + "parameters": [ + { + "description": "MailSubject to create/update with new content", + "name": "mailSubject", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.MailSubject" + } + } + ], + "responses": { + "200": { + "description": "Updated successfully", + "schema": { + "$ref": "#/definitions/models.MailSubject" + } + }, + "201": { + "description": "Created successfully", + "schema": { + "$ref": "#/definitions/models.MailSubject" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/mailSubject/{year}/{month}": { + "get": { + "description": "Get details of a specific mailSubject", + "produces": [ + "application/json" + ], + "tags": [ + "mailSubject" + ], + "summary": "Get details of a specific mailSubject", + "parameters": [ + { + "type": "integer", + "description": "Year of the mailSubject", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the mailSubject", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.MailSubject" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "description": "Delete a specific mailSubject", + "produces": [ + "application/json" + ], + "tags": [ + "mailSubject" + ], + "summary": "Delete a specific mailSubject", + "parameters": [ + { + "type": "integer", + "description": "Year of the mailSubject", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the mailSubject", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "successful delete", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/monthlyInfo": { + "get": { + "description": "Get details of all monthlyInfo", + "produces": [ + "application/json" + ], + "tags": [ + "monthlyInfo" + ], + "summary": "List all monthlyInfo", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.MonthlyInfo" + } + } + } + } + }, + "put": { + "description": "Create/update a specific monthlyInfo' content", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "monthlyInfo" + ], + "summary": "Create/update a specific monthlyInfo' content", + "parameters": [ + { + "description": "MonthlyInfo to create/update with new content", + "name": "monthlyInfo", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.MonthlyInfo" + } + } + ], + "responses": { + "200": { + "description": "Updated successfully", + "schema": { + "$ref": "#/definitions/models.MonthlyInfo" + } + }, + "201": { + "description": "Created successfully", + "schema": { + "$ref": "#/definitions/models.MonthlyInfo" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/monthlyInfo/{year}/{month}": { + "get": { + "description": "Get details of a specific monthlyInfo", + "produces": [ + "application/json" + ], + "tags": [ + "monthlyInfo" + ], + "summary": "Get details of a specific monthlyInfo", + "parameters": [ + { + "type": "integer", + "description": "Year of the monthlyInfo", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the monthlyInfo", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.MonthlyInfo" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "description": "Delete a specific monthlyInfo", + "produces": [ + "application/json" + ], + "tags": [ + "monthlyInfo" + ], + "summary": "Delete a specific monthlyInfo", + "parameters": [ + { + "type": "integer", + "description": "Year of the monthlyInfo", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the monthlyInfo", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "successful delete", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/monthlyNews": { + "get": { + "description": "Get details of all monthlyNews", + "produces": [ + "application/json" + ], + "tags": [ + "monthlyNews" + ], + "summary": "List all monthlyNews", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.MonthlyNews" + } + } + } + } + }, + "put": { + "description": "Create/update a specific monthlyNews' content", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "monthlyNews" + ], + "summary": "Create/update a specific monthlyNews' content", + "parameters": [ + { + "description": "MonthlyNews to create/update with new content", + "name": "monthlyNews", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.MonthlyNews" + } + } + ], + "responses": { + "200": { + "description": "Updated successfully", + "schema": { + "$ref": "#/definitions/models.MonthlyNews" + } + }, + "201": { + "description": "Created successfully", + "schema": { + "$ref": "#/definitions/models.MonthlyNews" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/monthlyNews/{year}/{month}": { + "get": { + "description": "Get details of a specific monthlyNews", + "produces": [ + "application/json" + ], + "tags": [ + "monthlyNews" + ], + "summary": "Get details of a specific monthlyNews", + "parameters": [ + { + "type": "integer", + "description": "Year of the monthlyNews", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the monthlyNews", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.MonthlyNews" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "description": "Delete a specific monthlyNews", + "produces": [ + "application/json" + ], + "tags": [ + "monthlyNews" + ], + "summary": "Delete a specific monthlyNews", + "parameters": [ + { + "type": "integer", + "description": "Year of the monthlyNews", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the monthlyNews", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "successful delete", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/partnersInfo": { + "put": { + "description": "Update partnersInfo' content", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "partnersInfo" + ], + "summary": "Update partnersInfo' content", + "parameters": [ + { + "description": "PartnersInfo to create/update with new content", + "name": "partnersInfo", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.PartnersInfo" + } + } + ], + "responses": { + "200": { + "description": "Updated successfully", + "schema": { + "$ref": "#/definitions/models.PartnersInfo" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/poll": { + "get": { + "description": "Get details of all polls", + "produces": [ + "application/json" + ], + "tags": [ + "poll" + ], + "summary": "List all polls", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Poll" + } + } + } + } + }, + "put": { + "description": "Update a specific poll' content", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "poll" + ], + "summary": "Update a specific poll' content", + "parameters": [ + { + "description": "Poll to update with new content", + "name": "poll", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.Poll" + } + } + ], + "responses": { + "200": { + "description": "Updated successfully", + "schema": { + "$ref": "#/definitions/models.Poll" + } + }, + "201": { + "description": "Created successfully", + "schema": { + "$ref": "#/definitions/models.Poll" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/poll/{year}/{month}": { + "get": { + "description": "Get details of a specific poll", + "produces": [ + "application/json" + ], + "tags": [ + "poll" + ], + "summary": "Get details of a specific poll", + "parameters": [ + { + "type": "integer", + "description": "Year of the poll", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the poll", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Poll" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "description": "Delete a specific poll", + "produces": [ + "application/json" + ], + "tags": [ + "poll" + ], + "summary": "Delete a specific poll", + "parameters": [ + { + "type": "integer", + "description": "Year of the poll", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the poll", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "successful delete", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/animator/price": { + "put": { + "description": "Add a new price entry", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "prices" + ], + "summary": "Add a new price entry", + "parameters": [ + { + "description": "Price to create/update with new content", + "name": "price", + "in": "body", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "Updated successfully", + "schema": { + "type": "object" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/common/customPopup": { + "get": { + "description": "Give status of custom poup", + "produces": [ + "application/json" + ], + "tags": [ + "customPopup" + ], + "summary": "Give status of custom popup", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.CustomPopup" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/common/monthlyReport/{year}/{month}": { + "get": { + "description": "Get details of a specific monthlyReport", + "produces": [ + "application/json" + ], + "tags": [ + "monthlyReport" + ], + "summary": "Get details of a specific monthlyReport", + "parameters": [ + { + "type": "integer", + "description": "Year of the monthlyReport", + "name": "year", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "Month of the monthlyReport", + "name": "month", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.MonthlyReport" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/common/partnersInfo": { + "get": { + "description": "Give status of partners' services", + "produces": [ + "application/json" + ], + "tags": [ + "partnersInfo" + ], + "summary": "Give status of partners' services", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.PartnersInfo" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/common/prices": { + "get": { + "description": "Get all prices", + "produces": [ + "application/json" + ], + "tags": [ + "prices" + ], + "summary": "Get all prices", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/common/prices/fluidType": { + "get": { + "description": "Get all prices for a given fluid", + "produces": [ + "application/json" + ], + "tags": [ + "prices" + ], + "summary": "Get all prices for a given fluid", + "parameters": [ + { + "type": "integer", + "description": "FluidType requested", + "name": "fluidtype", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/grdf/consent": { + "post": { + "description": "Create a new consent", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Create a new consent", + "parameters": [ + { + "type": "integer", + "description": "ID of the consent", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/models.GrdfConsentSwagger" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "couldn't create consent", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/grdf/consent/{id}": { + "get": { + "description": "Get details of a specific consent", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Get details of a specific consent", + "parameters": [ + { + "type": "integer", + "description": "ID of the consent", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.GrdfConsentSwagger" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "description": "Delete a specific consent", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Delete a specific consent", + "parameters": [ + { + "type": "integer", + "description": "ID of the consent", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.GrdfConsentSwagger" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/sge/consent": { + "put": { + "description": "Update a consent, giving it a serviceID", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Update a consent, giving it a serviceID", + "parameters": [ + { + "description": "service ID", + "name": "id", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.UpdateSgeConsentBody" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.SgeConsentSwagger" + } + }, + "400": { + "description": "invalid service id", + "schema": { + "type": "string" + } + }, + "404": { + "description": "couldn't find consent", + "schema": { + "type": "string" + } + }, + "500": { + "description": "couldn't parse body", + "schema": { + "type": "string" + } + } + } + }, + "post": { + "description": "Create a new consent", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Create a new consent", + "parameters": [ + { + "type": "integer", + "description": "ID of the consent", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/models.SgeConsentSwagger" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "string" + } + }, + "500": { + "description": "couldn't create consent", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/sge/consent/{id}": { + "get": { + "description": "Get details of a specific consent", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Get details of a specific consent", + "parameters": [ + { + "type": "integer", + "description": "ID of the consent", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.SgeConsentSwagger" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "description": "Delete a specific consent", + "produces": [ + "application/json" + ], + "tags": [ + "consent" + ], + "summary": "Delete a specific consent", + "parameters": [ + { + "type": "integer", + "description": "ID of the consent", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.SgeConsentSwagger" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not found", + "schema": { + "type": "string" + } + } + } + } + } + }, + "definitions": { + "models.CustomPopup": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "endDate": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "popupEnabled": { + "type": "boolean" + }, + "title": { + "type": "string" + } + } + }, + "models.GrdfConsentSwagger": { + "type": "object", + "properties": { + "CreatedAt": { + "type": "string" + }, + "DeletedAt": { + "type": "string" + }, + "ID": { + "type": "integer" + }, + "UpdatedAt": { + "type": "string" + }, + "endDate": { + "type": "string" + }, + "firstname": { + "type": "string" + }, + "lastname": { + "type": "string" + }, + "pce": { + "type": "string" + }, + "postalCode": { + "type": "string" + }, + "startDate": { + "type": "string" + } + } + }, + "models.MailSubject": { + "type": "object", + "properties": { + "month": { + "type": "integer" + }, + "subject": { + "type": "string" + }, + "year": { + "type": "integer" + } + } + }, + "models.MonthlyInfo": { + "type": "object", + "properties": { + "image": { + "type": "string" + }, + "info": { + "type": "string" + }, + "month": { + "type": "integer" + }, + "year": { + "type": "integer" + } + } + }, + "models.MonthlyNews": { + "type": "object", + "properties": { + "content": { + "type": "string" + }, + "month": { + "type": "integer" + }, + "title": { + "type": "string" + }, + "year": { + "type": "integer" + } + } + }, + "models.MonthlyReport": { + "type": "object", + "properties": { + "image": { + "type": "string" + }, + "info": { + "type": "string" + }, + "link": { + "type": "string" + }, + "month": { + "type": "integer" + }, + "newsContent": { + "type": "string" + }, + "newsTitle": { + "type": "string" + }, + "question": { + "type": "string" + }, + "subject": { + "type": "string" + }, + "year": { + "type": "integer" + } + } + }, + "models.PartnersInfo": { + "type": "object", + "properties": { + "egl_failure": { + "type": "boolean" + }, + "enedis_failure": { + "type": "boolean" + }, + "grdf_failure": { + "type": "boolean" + }, + "id": { + "type": "integer" + }, + "notification_activated": { + "type": "boolean" + } + } + }, + "models.Poll": { + "type": "object", + "properties": { + "link": { + "type": "string" + }, + "month": { + "type": "integer" + }, + "question": { + "type": "string" + }, + "year": { + "type": "integer" + } + } + }, + "models.SgeConsentSwagger": { + "type": "object", + "properties": { + "CreatedAt": { + "type": "string" + }, + "DeletedAt": { + "type": "string" + }, + "ID": { + "type": "integer" + }, + "UpdatedAt": { + "type": "string" + }, + "address": { + "type": "string" + }, + "city": { + "type": "string" + }, + "endDate": { + "type": "string" + }, + "firstname": { + "type": "string" + }, + "inseeCode": { + "type": "string" + }, + "lastname": { + "type": "string" + }, + "pointID": { + "type": "integer" + }, + "postalCode": { + "type": "string" + }, + "safetyOnBoarding": { + "type": "boolean" + }, + "serviceID": { + "type": "integer" + } + } + }, + "models.UpdateSgeConsentBody": { + "type": "object", + "properties": { + "serviceID": { + "type": "integer" + } + } + } + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..e3198ce --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,985 @@ +definitions: + models.CustomPopup: + properties: + description: + type: string + endDate: + type: string + id: + type: integer + popupEnabled: + type: boolean + title: + type: string + image: + type: string + type: object + models.GrdfConsentSwagger: + properties: + CreatedAt: + type: string + DeletedAt: + type: string + ID: + type: integer + UpdatedAt: + type: string + endDate: + type: string + firstname: + type: string + lastname: + type: string + pce: + type: string + postalCode: + type: string + startDate: + type: string + type: object + models.MailSubject: + properties: + month: + type: integer + subject: + type: string + year: + type: integer + type: object + models.MonthlyInfo: + properties: + image: + type: string + info: + type: string + month: + type: integer + year: + type: integer + type: object + models.MonthlyNews: + properties: + content: + type: string + month: + type: integer + title: + type: string + year: + type: integer + type: object + models.MonthlyReport: + properties: + image: + type: string + info: + type: string + link: + type: string + month: + type: integer + newsContent: + type: string + newsTitle: + type: string + question: + type: string + subject: + type: string + year: + type: integer + type: object + models.PartnersInfo: + properties: + egl_failure: + type: boolean + enedis_failure: + type: boolean + grdf_failure: + type: boolean + id: + type: integer + notification_activated: + type: boolean + type: object + models.Poll: + properties: + link: + type: string + month: + type: integer + question: + type: string + year: + type: integer + type: object + models.SgeConsentSwagger: + properties: + CreatedAt: + type: string + DeletedAt: + type: string + ID: + type: integer + UpdatedAt: + type: string + address: + type: string + city: + type: string + endDate: + type: string + firstname: + type: string + inseeCode: + type: string + lastname: + type: string + pointID: + type: integer + postalCode: + type: string + safetyOnBoarding: + type: boolean + serviceID: + type: integer + type: object + models.UpdateSgeConsentBody: + properties: + serviceID: + type: integer + type: object +info: + contact: + email: rpailharey@grandlyon.com + name: API Support + description: This is backend of Ecolyo-Agent, a backoffice managing newsletters, + SGE consents, fluid prices and custom alerts for Ecolyo + termsOfService: http://swagger.io/terms/ + title: Ecolyo-Agent API + version: 1.0.0 +paths: + /api/admin/consent: + get: + description: Search for consents based on the pointID + parameters: + - description: pointID to search + in: query + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/models.GrdfConsentSwagger' + type: array + "400": + description: Not found + schema: + type: string + summary: Search for consents + tags: + - consent + /api/admin/sge/consent: + get: + description: Search for consents based on the pointID + parameters: + - description: pointID to search + in: query + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/models.SgeConsentSwagger' + type: array + "400": + description: Not found + schema: + type: string + summary: Search for consents + tags: + - consent + /api/animator/customPopup: + put: + consumes: + - application/json + description: Update custom popup content + parameters: + - description: CustomPopup to create/update with new content + in: body + name: customPopup + required: true + schema: + $ref: '#/definitions/models.CustomPopup' + produces: + - application/json + responses: + "200": + description: Updated successfully + schema: + $ref: '#/definitions/models.CustomPopup' + "400": + description: Bad Request + schema: + type: string + "500": + description: Internal server error + schema: + type: string + summary: Update custom popup content + tags: + - customPopup + /api/animator/mailSubject: + put: + consumes: + - application/json + description: Create/update a specific mailSubject' content + parameters: + - description: MailSubject to create/update with new content + in: body + name: mailSubject + required: true + schema: + $ref: '#/definitions/models.MailSubject' + produces: + - application/json + responses: + "200": + description: Updated successfully + schema: + $ref: '#/definitions/models.MailSubject' + "201": + description: Created successfully + schema: + $ref: '#/definitions/models.MailSubject' + "400": + description: Bad Request + schema: + type: string + "500": + description: Internal server error + schema: + type: string + summary: Create/update a specific mailSubject' content + tags: + - mailSubject + /api/animator/mailSubject/{year}/{month}: + delete: + description: Delete a specific mailSubject + parameters: + - description: Year of the mailSubject + in: path + name: year + required: true + type: integer + - description: Month of the mailSubject + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: successful delete + schema: + type: string + "404": + description: Not found + schema: + type: string + summary: Delete a specific mailSubject + tags: + - mailSubject + get: + description: Get details of a specific mailSubject + parameters: + - description: Year of the mailSubject + in: path + name: year + required: true + type: integer + - description: Month of the mailSubject + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.MailSubject' + "404": + description: Not found + schema: + type: string + summary: Get details of a specific mailSubject + tags: + - mailSubject + /api/animator/monthlyInfo: + get: + description: Get details of all monthlyInfo + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/models.MonthlyInfo' + type: array + summary: List all monthlyInfo + tags: + - monthlyInfo + put: + consumes: + - application/json + description: Create/update a specific monthlyInfo' content + parameters: + - description: MonthlyInfo to create/update with new content + in: body + name: monthlyInfo + required: true + schema: + $ref: '#/definitions/models.MonthlyInfo' + produces: + - application/json + responses: + "200": + description: Updated successfully + schema: + $ref: '#/definitions/models.MonthlyInfo' + "201": + description: Created successfully + schema: + $ref: '#/definitions/models.MonthlyInfo' + "400": + description: Bad Request + schema: + type: string + "500": + description: Internal server error + schema: + type: string + summary: Create/update a specific monthlyInfo' content + tags: + - monthlyInfo + /api/animator/monthlyInfo/{year}/{month}: + delete: + description: Delete a specific monthlyInfo + parameters: + - description: Year of the monthlyInfo + in: path + name: year + required: true + type: integer + - description: Month of the monthlyInfo + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: successful delete + schema: + type: string + "404": + description: Not found + schema: + type: string + summary: Delete a specific monthlyInfo + tags: + - monthlyInfo + get: + description: Get details of a specific monthlyInfo + parameters: + - description: Year of the monthlyInfo + in: path + name: year + required: true + type: integer + - description: Month of the monthlyInfo + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.MonthlyInfo' + "404": + description: Not found + schema: + type: string + summary: Get details of a specific monthlyInfo + tags: + - monthlyInfo + /api/animator/monthlyNews: + get: + description: Get details of all monthlyNews + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/models.MonthlyNews' + type: array + summary: List all monthlyNews + tags: + - monthlyNews + put: + consumes: + - application/json + description: Create/update a specific monthlyNews' content + parameters: + - description: MonthlyNews to create/update with new content + in: body + name: monthlyNews + required: true + schema: + $ref: '#/definitions/models.MonthlyNews' + produces: + - application/json + responses: + "200": + description: Updated successfully + schema: + $ref: '#/definitions/models.MonthlyNews' + "201": + description: Created successfully + schema: + $ref: '#/definitions/models.MonthlyNews' + "400": + description: Bad Request + schema: + type: string + "500": + description: Internal server error + schema: + type: string + summary: Create/update a specific monthlyNews' content + tags: + - monthlyNews + /api/animator/monthlyNews/{year}/{month}: + delete: + description: Delete a specific monthlyNews + parameters: + - description: Year of the monthlyNews + in: path + name: year + required: true + type: integer + - description: Month of the monthlyNews + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: successful delete + schema: + type: string + "404": + description: Not found + schema: + type: string + summary: Delete a specific monthlyNews + tags: + - monthlyNews + get: + description: Get details of a specific monthlyNews + parameters: + - description: Year of the monthlyNews + in: path + name: year + required: true + type: integer + - description: Month of the monthlyNews + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.MonthlyNews' + "404": + description: Not found + schema: + type: string + summary: Get details of a specific monthlyNews + tags: + - monthlyNews + /api/animator/partnersInfo: + put: + consumes: + - application/json + description: Update partnersInfo' content + parameters: + - description: PartnersInfo to create/update with new content + in: body + name: partnersInfo + required: true + schema: + $ref: '#/definitions/models.PartnersInfo' + produces: + - application/json + responses: + "200": + description: Updated successfully + schema: + $ref: '#/definitions/models.PartnersInfo' + "400": + description: Bad Request + schema: + type: string + "500": + description: Internal server error + schema: + type: string + summary: Update partnersInfo' content + tags: + - partnersInfo + /api/animator/poll: + get: + description: Get details of all polls + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/models.Poll' + type: array + summary: List all polls + tags: + - poll + put: + consumes: + - application/json + description: Update a specific poll' content + parameters: + - description: Poll to update with new content + in: body + name: poll + required: true + schema: + $ref: '#/definitions/models.Poll' + produces: + - application/json + responses: + "200": + description: Updated successfully + schema: + $ref: '#/definitions/models.Poll' + "201": + description: Created successfully + schema: + $ref: '#/definitions/models.Poll' + "400": + description: Bad Request + schema: + type: string + "500": + description: Internal server error + schema: + type: string + summary: Update a specific poll' content + tags: + - poll + /api/animator/poll/{year}/{month}: + delete: + description: Delete a specific poll + parameters: + - description: Year of the poll + in: path + name: year + required: true + type: integer + - description: Month of the poll + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: successful delete + schema: + type: string + "404": + description: Not found + schema: + type: string + summary: Delete a specific poll + tags: + - poll + get: + description: Get details of a specific poll + parameters: + - description: Year of the poll + in: path + name: year + required: true + type: integer + - description: Month of the poll + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.Poll' + "404": + description: Not found + schema: + type: string + summary: Get details of a specific poll + tags: + - poll + /api/animator/price: + put: + consumes: + - application/json + description: Add a new price entry + parameters: + - description: Price to create/update with new content + in: body + name: price + required: true + schema: + type: object + produces: + - application/json + responses: + "200": + description: Updated successfully + schema: + type: object + "400": + description: Bad Request + schema: + type: string + "500": + description: Internal server error + schema: + type: string + summary: Add a new price entry + tags: + - prices + /api/common/customPopup: + get: + description: Give status of custom poup + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.CustomPopup' + "404": + description: Not found + schema: + type: string + summary: Give status of custom popup + tags: + - customPopup + /api/common/monthlyReport/{year}/{month}: + get: + description: Get details of a specific monthlyReport + parameters: + - description: Year of the monthlyReport + in: path + name: year + required: true + type: integer + - description: Month of the monthlyReport + in: path + name: month + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.MonthlyReport' + "404": + description: Not found + schema: + type: string + summary: Get details of a specific monthlyReport + tags: + - monthlyReport + /api/common/partnersInfo: + get: + description: Give status of partners' services + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.PartnersInfo' + "404": + description: Not found + schema: + type: string + summary: Give status of partners' services + tags: + - partnersInfo + /api/common/prices: + get: + description: Get all prices + produces: + - application/json + responses: + "200": + description: OK + schema: + type: object + "404": + description: Not found + schema: + type: string + summary: Get all prices + tags: + - prices + /api/common/prices/fluidType: + get: + description: Get all prices for a given fluid + parameters: + - description: FluidType requested + in: path + name: fluidtype + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + type: object + "404": + description: Not found + schema: + type: string + summary: Get all prices for a given fluid + tags: + - prices + /api/grdf/consent: + post: + description: Create a new consent + parameters: + - description: ID of the consent + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/models.GrdfConsentSwagger' + "400": + description: Bad request + schema: + type: string + "500": + description: couldn't create consent + schema: + type: string + summary: Create a new consent + tags: + - consent + /api/grdf/consent/{id}: + delete: + description: Delete a specific consent + parameters: + - description: ID of the consent + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.GrdfConsentSwagger' + "404": + description: Not found + schema: + type: string + "500": + description: Not found + schema: + type: string + summary: Delete a specific consent + tags: + - consent + get: + description: Get details of a specific consent + parameters: + - description: ID of the consent + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.GrdfConsentSwagger' + "404": + description: Not found + schema: + type: string + summary: Get details of a specific consent + tags: + - consent + /api/sge/consent: + post: + description: Create a new consent + parameters: + - description: ID of the consent + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/models.SgeConsentSwagger' + "400": + description: Bad request + schema: + type: string + "500": + description: couldn't create consent + schema: + type: string + summary: Create a new consent + tags: + - consent + put: + description: Update a consent, giving it a serviceID + parameters: + - description: service ID + in: body + name: id + required: true + schema: + $ref: '#/definitions/models.UpdateSgeConsentBody' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.SgeConsentSwagger' + "400": + description: invalid service id + schema: + type: string + "404": + description: couldn't find consent + schema: + type: string + "500": + description: couldn't parse body + schema: + type: string + summary: Update a consent, giving it a serviceID + tags: + - consent + /api/sge/consent/{id}: + delete: + description: Delete a specific consent + parameters: + - description: ID of the consent + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.SgeConsentSwagger' + "404": + description: Not found + schema: + type: string + "500": + description: Not found + schema: + type: string + summary: Delete a specific consent + tags: + - consent + get: + description: Get details of a specific consent + parameters: + - description: ID of the consent + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.SgeConsentSwagger' + "404": + description: Not found + schema: + type: string + summary: Get details of a specific consent + tags: + - consent +swagger: "2.0" diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 860511c..8838dbd 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -25,9 +25,9 @@ const ( var ( AnimatorRole = common.StringValueFromEnv("ANIMATOR_ROLE", "ANIMATORS") // AdminRole represents the role reserved for admins - AdminRole = common.StringValueFromEnv("ADMIN_ROLE", "ADMINS") - hostname = common.StringValueFromEnv("HOSTNAME", "ecolyobackoffice.127.0.0.1.nip.io") - SGEApiToken = common.StringValueFromEnv("SGE_API_TOKEN", "sgetoken") + AdminRole = common.StringValueFromEnv("ADMIN_ROLE", "ADMINS") + hostname = common.StringValueFromEnv("HOSTNAME", "ecolyobackoffice.127.0.0.1.nip.io") + BOApiToken = common.StringValueFromEnv("BO_API_TOKEN", "sgetoken") ) // User represents a logged in user @@ -120,7 +120,7 @@ func ValidateAuthMiddleware(next http.Handler, allowedRoles []string, checkXSRF func BOAuthMiddleware(next http.Handler) http.Handler { tokenChecker := func(w http.ResponseWriter, r *http.Request) { // Check API Token - if r.Header.Get("Authorization") != "Bearer "+SGEApiToken { + if r.Header.Get("Authorization") != "Bearer "+BOApiToken { http.Error(w, "invalid token", http.StatusUnauthorized) return } diff --git a/internal/rootmux/rootmux_test.go b/internal/rootmux/rootmux_test.go index f5de086..1258e60 100644 --- a/internal/rootmux/rootmux_test.go +++ b/internal/rootmux/rootmux_test.go @@ -66,7 +66,7 @@ func TestMain(m *testing.M) { os.Setenv("TOKEN_URL", oAuth2Server.URL+"/token") os.Setenv("USERINFO_URL", oAuth2Server.URL+"/animatorinfo") os.Setenv("LOGOUT_URL", oAuth2Server.URL+"/logout") - os.Setenv("SGE_API_TOKEN", "sgeApiToken") + os.Setenv("BO_API_TOKEN", "boApiToken") // Setup the token manager to use debug mode os.Setenv("DEBUG_MODE", "true") @@ -301,7 +301,7 @@ func sgeTests(t *testing.T) { do("DELETE", "/api/sge/consent/1", noH, "", http.StatusUnauthorized, ErrorInvalidToken) // Create correct authorization header - boApiHeader := map[string]string{"Authorization": "Bearer " + auth.SGEApiToken} + boApiHeader := map[string]string{"Authorization": "Bearer " + auth.BOApiToken} // Try to create a consent (must pass) do("POST", "/api/sge/consent", boApiHeader, consentStr, http.StatusCreated, `{"ID":"52fdfc07-2182-454f-963f-5f0f9a621d72"`) // Try to create another consent (must pass) @@ -328,7 +328,7 @@ func grdfTests(t *testing.T) { do("DELETE", "/api/grdf/consent/1", noH, "", http.StatusUnauthorized, ErrorInvalidToken) // Create correct authorization header - boApiHeader := map[string]string{"Authorization": "Bearer " + auth.SGEApiToken} + boApiHeader := map[string]string{"Authorization": "Bearer " + auth.BOApiToken} // Try to create a consent (must pass) do("POST", "/api/grdf/consent", boApiHeader, grdfConsentStr, http.StatusCreated, `{"ID":"81855ad8-681d-4d86-91e9-1e00167939cb"`) // Try to create another consent (must pass) diff --git a/k8s/secrets/ecolyo-agent-server-config.yml b/k8s/secrets/ecolyo-agent-server-config.yml index 8974c88..8beaebc 100644 --- a/k8s/secrets/ecolyo-agent-server-config.yml +++ b/k8s/secrets/ecolyo-agent-server-config.yml @@ -17,7 +17,7 @@ stringData: IMAGE_FOLDER: mnt/image-lib MOCK_OAUTH2: 'false' REDIRECT_URL: 'https://{{HOSTNAME}}/OAuth2Callback' - SGE_API_TOKEN: {{SGE_API_TOKEN}} + BO_API_TOKEN: {{BO_API_TOKEN}} TOKEN_URL: {{TOKEN_URL}} USERINFO_URL: {{USERINFO_URL}} GRDF_CLIENT_ID: {{GRDF_CLIENT_ID}} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..ae50268 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "backoffice-server", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} -- GitLab