diff --git a/src/core-api/.gitignore b/src/core-api/.gitignore index 5e9d0cddd..5c5eae19f 100644 --- a/src/core-api/.gitignore +++ b/src/core-api/.gitignore @@ -33,3 +33,4 @@ core *.log bk-apigateway-core-api .coverage.cov +config.yaml \ No newline at end of file diff --git a/src/core-api/Makefile b/src/core-api/Makefile index 0d117b091..3ed708d89 100644 --- a/src/core-api/Makefile +++ b/src/core-api/Makefile @@ -17,12 +17,17 @@ init: go install github.com/segmentio/golines@latest # for goimports go install -v github.com/incu6us/goimports-reviser/v3@latest + # for swag + go install github.com/swaggo/swag/cmd/swag@latest .PHONY: dep dep: go mod tidy go mod vendor +doc: + swag init + .PHONY: mock mock: go generate ./... diff --git a/src/core-api/cmd/init.go b/src/core-api/cmd/init.go index 2f1967105..9c5eb195e 100644 --- a/src/core-api/cmd/init.go +++ b/src/core-api/cmd/init.go @@ -22,7 +22,7 @@ import ( "fmt" "github.com/getsentry/raven-go" - sentry "github.com/getsentry/sentry-go" + "github.com/getsentry/sentry-go" "github.com/spf13/viper" "core/pkg/config" diff --git a/src/core-api/docs/docs.go b/src/core-api/docs/docs.go new file mode 100644 index 000000000..88e5ddb6a --- /dev/null +++ b/src/core-api/docs/docs.go @@ -0,0 +1,208 @@ +// Package docs Code generated by swaggo/swag. DO NOT EDIT +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/api/v1/open/gateways/{gateway_name}/public_key/": { + "get": { + "description": "query public key of v1", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "open" + ], + "summary": "query public key of v1", + "parameters": [ + { + "type": "string", + "description": "gateway_name", + "name": "gateway_name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "success", + "schema": { + "$ref": "#/definitions/util.LegacySuccessResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/util.LegacyErrorResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/util.LegacyErrorResponse" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/util.LegacyErrorResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/util.LegacyErrorResponse" + } + } + } + } + }, + "/api/v2/open/gateways/{gateway_name}/public_key/": { + "get": { + "description": "query public key of v2", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "open" + ], + "summary": "query public key of v2", + "parameters": [ + { + "type": "string", + "description": "gateway_name", + "name": "gateway_name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "success", + "schema": { + "$ref": "#/definitions/util.SuccessResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/util.ErrorResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/util.ErrorResponse" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/util.ErrorResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/util.ErrorResponse" + } + } + } + } + } + }, + "definitions": { + "util.Error": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "message": { + "type": "string" + }, + "system": { + "type": "string" + } + } + }, + "util.ErrorResponse": { + "type": "object", + "properties": { + "error": { + "$ref": "#/definitions/util.Error" + } + } + }, + "util.LegacyErrorResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer" + }, + "message": { + "type": "string" + }, + "result": { + "type": "boolean" + } + } + }, + "util.LegacySuccessResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer" + }, + "data": {}, + "message": { + "type": "string" + }, + "result": { + "type": "boolean" + } + } + }, + "util.SuccessResponse": { + "type": "object", + "properties": { + "data": {} + } + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "", + Host: "", + BasePath: "", + Schemes: []string{}, + Title: "", + Description: "", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/src/core-api/docs/swagger.json b/src/core-api/docs/swagger.json new file mode 100644 index 000000000..60bf989fa --- /dev/null +++ b/src/core-api/docs/swagger.json @@ -0,0 +1,179 @@ +{ + "swagger": "2.0", + "info": { + "contact": {} + }, + "paths": { + "/api/v1/open/gateways/{gateway_name}/public_key/": { + "get": { + "description": "query public key of v1", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "open" + ], + "summary": "query public key of v1", + "parameters": [ + { + "type": "string", + "description": "gateway_name", + "name": "gateway_name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "success", + "schema": { + "$ref": "#/definitions/util.LegacySuccessResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/util.LegacyErrorResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/util.LegacyErrorResponse" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/util.LegacyErrorResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/util.LegacyErrorResponse" + } + } + } + } + }, + "/api/v2/open/gateways/{gateway_name}/public_key/": { + "get": { + "description": "query public key of v2", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "open" + ], + "summary": "query public key of v2", + "parameters": [ + { + "type": "string", + "description": "gateway_name", + "name": "gateway_name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "success", + "schema": { + "$ref": "#/definitions/util.SuccessResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/util.ErrorResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/util.ErrorResponse" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/util.ErrorResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/util.ErrorResponse" + } + } + } + } + } + }, + "definitions": { + "util.Error": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "message": { + "type": "string" + }, + "system": { + "type": "string" + } + } + }, + "util.ErrorResponse": { + "type": "object", + "properties": { + "error": { + "$ref": "#/definitions/util.Error" + } + } + }, + "util.LegacyErrorResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer" + }, + "message": { + "type": "string" + }, + "result": { + "type": "boolean" + } + } + }, + "util.LegacySuccessResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer" + }, + "data": {}, + "message": { + "type": "string" + }, + "result": { + "type": "boolean" + } + } + }, + "util.SuccessResponse": { + "type": "object", + "properties": { + "data": {} + } + } + } +} \ No newline at end of file diff --git a/src/core-api/docs/swagger.yaml b/src/core-api/docs/swagger.yaml new file mode 100644 index 000000000..075b38c2e --- /dev/null +++ b/src/core-api/docs/swagger.yaml @@ -0,0 +1,116 @@ +definitions: + util.Error: + properties: + code: + type: string + message: + type: string + system: + type: string + type: object + util.ErrorResponse: + properties: + error: + $ref: '#/definitions/util.Error' + type: object + util.LegacyErrorResponse: + properties: + code: + type: integer + message: + type: string + result: + type: boolean + type: object + util.LegacySuccessResponse: + properties: + code: + type: integer + data: {} + message: + type: string + result: + type: boolean + type: object + util.SuccessResponse: + properties: + data: {} + type: object +info: + contact: {} +paths: + /api/v1/open/gateways/{gateway_name}/public_key/: + get: + consumes: + - application/json + description: query public key of v1 + parameters: + - description: gateway_name + in: path + name: gateway_name + required: true + type: string + produces: + - application/json + responses: + "200": + description: success + schema: + $ref: '#/definitions/util.LegacySuccessResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/util.LegacyErrorResponse' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/util.LegacyErrorResponse' + "404": + description: Not Found + schema: + $ref: '#/definitions/util.LegacyErrorResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/util.LegacyErrorResponse' + summary: query public key of v1 + tags: + - open + /api/v2/open/gateways/{gateway_name}/public_key/: + get: + consumes: + - application/json + description: query public key of v2 + parameters: + - description: gateway_name + in: path + name: gateway_name + required: true + type: string + produces: + - application/json + responses: + "200": + description: success + schema: + $ref: '#/definitions/util.SuccessResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/util.ErrorResponse' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/util.ErrorResponse' + "404": + description: Not Found + schema: + $ref: '#/definitions/util.ErrorResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/util.ErrorResponse' + summary: query public key of v2 + tags: + - open +swagger: "2.0" diff --git a/src/core-api/go.mod b/src/core-api/go.mod index c752260ff..d166825b9 100644 --- a/src/core-api/go.mod +++ b/src/core-api/go.mod @@ -7,22 +7,28 @@ require ( github.com/TencentBlueKing/gopkg v1.2.0 github.com/agiledragon/gomonkey/v2 v2.10.1 github.com/dlmiddlecote/sqlstats v1.0.2 + github.com/getsentry/raven-go v0.2.0 github.com/getsentry/sentry-go v0.20.0 github.com/gin-gonic/contrib v0.0.0-20221130124618-7e01895a63f2 - github.com/gin-gonic/gin v1.8.2 - github.com/go-playground/validator/v10 v10.11.1 + github.com/gin-gonic/gin v1.9.0 + github.com/go-playground/validator/v10 v10.11.2 github.com/go-sql-driver/mysql v1.7.0 github.com/gofrs/uuid v4.4.0+incompatible + github.com/golang-jwt/jwt/v4 v4.5.0 github.com/golang/mock v1.4.4 github.com/jmoiron/sqlx v1.3.5 github.com/json-iterator/go v1.1.12 github.com/onsi/ginkgo/v2 v2.9.5 github.com/onsi/gomega v1.27.6 + github.com/patrickmn/go-cache v2.1.0+incompatible github.com/prometheus/client_golang v1.15.0 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.15.0 - github.com/stretchr/testify v1.8.3 + github.com/stretchr/testify v1.8.4 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.0 + github.com/swaggo/swag v1.16.2 github.com/tchap/zapext/v2 v2.1.1 github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.2 github.com/uptrace/opentelemetry-go-extra/otelsqlx v0.2.2 @@ -38,16 +44,22 @@ require ( ) require ( + github.com/KyleBanks/depth v1.2.1 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/bytedance/sonic v1.8.0 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/getsentry/raven-go v0.2.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-openapi/jsonpointer v0.20.0 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/spec v0.20.11 // indirect + github.com/go-openapi/swag v0.22.4 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect @@ -58,14 +70,16 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/magiconair/properties v1.8.7 // indirect + github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -76,22 +90,23 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.9 // indirect go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/proto/otlp v0.19.0 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.8.0 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect - golang.org/x/tools v0.9.1 // indirect + golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect + golang.org/x/crypto v0.16.0 // indirect + golang.org/x/net v0.19.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.16.0 // indirect google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect google.golang.org/grpc v1.55.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/src/core-api/go.sum b/src/core-api/go.sum index 334c18591..4f221270b 100644 --- a/src/core-api/go.sum +++ b/src/core-api/go.sum @@ -44,6 +44,8 @@ github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMd github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= github.com/TencentBlueKing/gopkg v1.2.0 h1:gtqlJU1IbBgnUzb4OILKnwpiZ71ybYQ+VW8heQm5QYE= @@ -64,6 +66,9 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA= +github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -73,6 +78,9 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -124,14 +132,15 @@ github.com/getsentry/sentry-go v0.12.0/go.mod h1:NSap0JBYWzHND8oMbyi0+XZhUalc1TB github.com/getsentry/sentry-go v0.20.0 h1:bwXW98iMRIWxn+4FgPW7vMrjmbym6HblXALmhjHmQaQ= github.com/getsentry/sentry-go v0.20.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/contrib v0.0.0-20221130124618-7e01895a63f2 h1:dyuNlYlG1faymw39NdJddnzJICy6587tiGSVioWhYoE= github.com/gin-gonic/contrib v0.0.0-20221130124618-7e01895a63f2/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg= github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= -github.com/gin-gonic/gin v1.8.2 h1:UzKToD9/PoFj/V4rvlKqTRKnQYyz8Sc1MJlv4JHPtvY= -github.com/gin-gonic/gin v1.8.2/go.mod h1:qw5AYuDrzRTnhvusDsrov+fDIxp9Dleuu12h8nfB398= +github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= +github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -148,16 +157,28 @@ github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= -github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= +github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= +github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/spec v0.20.11 h1:J/TzFDLTt4Rcl/l1PmyErvkqlJDncGvPTMnCI39I4gY= +github.com/go-openapi/spec v0.20.11/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= +github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= -github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= +github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= +github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= @@ -174,6 +195,8 @@ github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1 github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= @@ -269,6 +292,8 @@ github.com/iris-contrib/pongo2 v0.0.1/go.mod h1:Ssh+00+3GAZqSQb30AvBRNxBx7rf0Gqw github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw= github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g= github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -288,12 +313,13 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -308,6 +334,11 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= @@ -343,6 +374,7 @@ github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5Vgl github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -364,7 +396,6 @@ github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvI github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -394,9 +425,7 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -440,12 +469,20 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M= +github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= +github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04= +github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E= github.com/tchap/zapext/v2 v2.1.1 h1:b+F48/0QFBqV0Vr8AJYH2nAmgggQncv0SJIESn6+FMw= github.com/tchap/zapext/v2 v2.1.1/go.mod h1:YM6t4NfOcMAE9Eo1wSlYIoC017zit9UQinf733BBFEs= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= @@ -476,6 +513,7 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -520,6 +558,8 @@ go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= go.uber.org/zap v1.20.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -533,9 +573,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -572,7 +611,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -615,9 +655,10 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -639,8 +680,9 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -694,16 +736,20 @@ golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -713,8 +759,9 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -774,8 +821,9 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= -golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= -golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= +golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -886,6 +934,7 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -909,6 +958,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -924,5 +974,6 @@ logur.dev/adapter/zap v0.5.0/go.mod h1:fpjTeoSkN05hrUviBkIe/u0CKWTh1PBxWQLLFgnWh logur.dev/logur v0.16.1/go.mod h1:DyA5B+b6WjjCcnpE1+HGtTLh2lXooxRq+JmAwXMRK08= logur.dev/logur v0.17.0/go.mod h1:DyA5B+b6WjjCcnpE1+HGtTLh2lXooxRq+JmAwXMRK08= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/src/core-api/pkg/api/open/public_key.go b/src/core-api/pkg/api/open/public_key.go new file mode 100644 index 000000000..168967756 --- /dev/null +++ b/src/core-api/pkg/api/open/public_key.go @@ -0,0 +1,127 @@ +/* + * TencentBlueKing is pleased to support the open source community by making + * 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. + * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + * + * We undertake not to change the open source license (MIT license) applicable + * to the current version of the project delivered to anyone in the future. + */ + +package open + +import ( + "database/sql" + "errors" + "net/http" + + "github.com/gin-gonic/gin" + + "core/pkg/constant" + "core/pkg/service" + "core/pkg/util" +) + +type queryPublicKeySerializer struct { + BkGatewayName string `uri:"gateway_name" binding:"required" example:"gateway"` +} + +// QueryPublicKeyV1 godoc +// @Summary query public key of v1 +// @Description query public key of v1 +// @Tags open +// @Accept json +// @Produce json +// @Header 200 {string} X-Bkapi-Jwt "the bkapi jwt" +// @Param gateway_name path string true "gateway_name" +// @Success 200 {object} util.LegacySuccessResponse "success" +// @Success 400 {object} util.LegacyErrorResponse "Bad Request" +// @Success 401 {object} util.LegacyErrorResponse "Unauthorized" +// @Failure 404 {object} util.LegacyErrorResponse "Not Found" +// @Failure 500 {object} util.LegacyErrorResponse "Internal Server Error" +// @Router /api/v1/open/gateways/{gateway_name}/public_key/ [get] +func QueryPublicKeyV1(c *gin.Context) { + // uri params: bk_gateway_name or api_name + // response body: + // { + // "data": { + // "public_key": "" + // } + // } + + var query queryPublicKeySerializer + if err := c.ShouldBindUri(&query); err != nil { + util.LegacyErrorJSONResponse(c, util.BadRequestError, http.StatusBadRequest, err.Error()) + return + } + svc := service.NewGatewayPublicKeyService() + + publicKey, err := svc.GetByGatewayName(c.Request.Context(), query.BkGatewayName) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + util.LegacyErrorJSONResponse(c, util.NotFoundError, http.StatusNotFound, err.Error()) + return + } else { + util.LegacyErrorJSONResponse(c, util.SystemError, http.StatusInternalServerError, err.Error()) + return + } + } + util.LegacySuccessJsonResponse(c, gin.H{ + "issuer": c.GetString(constant.BkGatewayJWTIssuerKey), + "public_key": publicKey, + }) +} + +// QueryPublicKeyV2 godoc +// @Summary query public key of v2 +// @Description query public key of v2 +// @Tags open +// @Accept json +// @Produce json +// @Param gateway_name path string true "gateway_name" +// @Success 200 {object} util.SuccessResponse "success" +// @Failure 400 {object} util.ErrorResponse "Bad Request" +// @Failure 401 {object} util.ErrorResponse "Unauthorized" +// @Failure 404 {object} util.ErrorResponse "Not Found" +// @Failure 500 {object} util.ErrorResponse "Internal Server Error" +// @Router /api/v2/open/gateways/{gateway_name}/public_key/ [get] +func QueryPublicKeyV2(c *gin.Context) { + // uri params: bk_gateway_name or api_name + // response body: + // { + // "data": { + // "public_key": "" + // } + // } + + var query queryPublicKeySerializer + if err := c.ShouldBindUri(&query); err != nil { + util.BadRequestErrorJSONResponse(c, util.ValidationErrorMessage(err)) + return + } + svc := service.NewGatewayPublicKeyService() + + publicKey, err := svc.GetByGatewayName(c.Request.Context(), query.BkGatewayName) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + util.NotFoundJSONResponse(c, err.Error()) + return + } else { + util.SystemErrorJSONResponse(c, err) + return + } + } + + util.SuccessJSONResponse(c, gin.H{ + "issuer": c.GetString(constant.BkGatewayJWTIssuerKey), + "public_key": publicKey, + }) +} diff --git a/src/core-api/pkg/cacheimpls/publish_event_test.go b/src/core-api/pkg/cacheimpls/publish_event_test.go index 96b79d1bb..25884bf09 100644 --- a/src/core-api/pkg/cacheimpls/publish_event_test.go +++ b/src/core-api/pkg/cacheimpls/publish_event_test.go @@ -37,7 +37,6 @@ func TestPublishEvent_Key(t *testing.T) { } func TestPublishEventExistsAndSet(t *testing.T) { - key := PublishEventKey{ GatewayID: 1, StageID: 2, @@ -53,5 +52,4 @@ func TestPublishEventExistsAndSet(t *testing.T) { exists = PublishEventExists(context.Background(), key) assert.Equal(t, true, exists) - } diff --git a/src/core-api/pkg/constant/open.go b/src/core-api/pkg/constant/open.go new file mode 100644 index 000000000..c3bb9d5df --- /dev/null +++ b/src/core-api/pkg/constant/open.go @@ -0,0 +1,21 @@ +/* + * TencentBlueKing is pleased to support the open source community by making + * 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. + * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + * + * We undertake not to change the open source license (MIT license) applicable + * to the current version of the project delivered to anyone in the future. + */ + +package constant + +const BkGatewayJWTIssuerKey = "bk_gateway_jwt_issuer" diff --git a/src/core-api/pkg/middleware/bk_gateway_jwt.go b/src/core-api/pkg/middleware/bk_gateway_jwt.go new file mode 100644 index 000000000..1cde0be65 --- /dev/null +++ b/src/core-api/pkg/middleware/bk_gateway_jwt.go @@ -0,0 +1,206 @@ +/* + * TencentBlueKing is pleased to support the open source community by making + * 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. + * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + * + * We undertake not to change the open source license (MIT license) applicable + * to the current version of the project delivered to anyone in the future. + */ + +package middleware + +import ( + "database/sql" + "errors" + "fmt" + "net/http" + + "github.com/gin-gonic/gin" + jwt "github.com/golang-jwt/jwt/v4" + "github.com/spf13/cast" + + "core/pkg/constant" + "core/pkg/service" + "core/pkg/util" +) + +const ( + BkGatewayJWTHeaderKey = "X-Bkapi-Jwt" + OfficialGatewayName = "bk-apigateway" +) + +var ( + ErrUnauthorized = errors.New("jwtauth: token is unauthorized") + + ErrExpired = errors.New("jwtauth: token is expired") + ErrNBFInvalid = errors.New("jwtauth: token nbf validation failed") + ErrIATInvalid = errors.New("jwtauth: token iat validation failed") + + ErrAPIGatewayJWTMissingApp = errors.New("app not in jwt claims") + ErrAPIGatewayJWTAppInfoParseFail = errors.New("app info parse fail") + ErrAPIGatewayJWTAppInfoNoAppCode = errors.New("app_code not in app info") + ErrAPIGatewayJWTAppCodeNotString = errors.New("app_code not string") + ErrAPIGatewayJWTAppInfoNoVerified = errors.New("verified not in app info") + ErrAPIGatewayJWTAppInfoVerifiedNotBool = errors.New("verified not bool") + ErrAPIGatewayJWTAppNotVerified = errors.New("app not verified") +) + +// BkGatewayJWTAuthMiddlewareV1 is the middleware to verify the bk gateway jwt +func BkGatewayJWTAuthMiddlewareV1() func(c *gin.Context) { + return func(c *gin.Context) { + signedToken := c.GetHeader(BkGatewayJWTHeaderKey) + if signedToken == "" { + util.LegacyErrorJSONResponse( + c, + util.UnauthorizedError, + http.StatusUnauthorized, + "no authorization credentials provided", + ) + c.Abort() + return + } + // get public key + svc := service.NewGatewayPublicKeyService() + publicKeyString, err := svc.GetByGatewayName(c.Request.Context(), OfficialGatewayName) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + util.LegacyErrorJSONResponse(c, util.NotFoundError, http.StatusNotFound, err.Error()) + return + } + util.LegacyErrorJSONResponse(c, util.SystemError, http.StatusInternalServerError, err.Error()) + c.Abort() + return + } + + // parse token + claims, err := parseBKJWTToken(signedToken, []byte(publicKeyString)) + if err != nil { + util.LegacyErrorJSONResponse(c, util.UnauthorizedError, http.StatusUnauthorized, err.Error()) + c.Abort() + return + } + // verify token + err = verifyJwtToken(claims) + if err != nil { + util.LegacyErrorJSONResponse(c, util.UnauthorizedError, http.StatusUnauthorized, err.Error()) + c.Abort() + return + } + // set issuer + c.Set(constant.BkGatewayJWTIssuerKey, cast.ToString(claims["iss"])) + c.Next() + } +} + +// BkGatewayJWTAuthMiddlewareV2 is the middleware to verify the bk gateway jwt +func BkGatewayJWTAuthMiddlewareV2() func(c *gin.Context) { + return func(c *gin.Context) { + signedToken := c.GetHeader(BkGatewayJWTHeaderKey) + if signedToken == "" { + util.UnauthorizedJSONResponse(c, "no authorization credentials provided") + c.Abort() + return + } + // get public key + svc := service.NewGatewayPublicKeyService() + publicKeyString, err := svc.GetByGatewayName(c.Request.Context(), OfficialGatewayName) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + util.NotFoundJSONResponse(c, err.Error()) + return + } + util.SystemErrorJSONResponse(c, err) + c.Abort() + return + } + + // parse token + claims, err := parseBKJWTToken(signedToken, []byte(publicKeyString)) + if err != nil { + util.UnauthorizedJSONResponse(c, err.Error()) + c.Abort() + return + } + // verify token + err = verifyJwtToken(claims) + if err != nil { + util.UnauthorizedJSONResponse(c, err.Error()) + c.Abort() + return + } + // set issuer + c.Set(constant.BkGatewayJWTIssuerKey, cast.ToString(claims["iss"])) + + c.Next() + } +} + +// BKJWTAuthMiddleware parse the bk jwt +func parseBKJWTToken(tokenString string, publicKey []byte) (jwt.MapClaims, error) { + keyFunc := func(token *jwt.Token) (interface{}, error) { + pubKey, err := jwt.ParseRSAPublicKeyFromPEM(publicKey) + if err != nil { + return pubKey, fmt.Errorf("jwt parse fail, err=%w", err) + } + return pubKey, nil + } + + claims := jwt.MapClaims{} + token, err := jwt.ParseWithClaims(tokenString, claims, keyFunc) + if err != nil { + var verr *jwt.ValidationError + if errors.As(err, &verr) { + switch { + case verr.Errors&jwt.ValidationErrorExpired > 0: + return nil, ErrExpired + case verr.Errors&jwt.ValidationErrorIssuedAt > 0: + return nil, ErrIATInvalid + case verr.Errors&jwt.ValidationErrorNotValidYet > 0: + return nil, ErrNBFInvalid + } + } + return nil, err + } + + if !token.Valid { + return nil, ErrUnauthorized + } + + return claims, nil +} + +// verifyJwtToken verify the jwtToken +func verifyJwtToken(claims jwt.MapClaims) error { + appInfo, ok := claims["app"] + if !ok { + return ErrAPIGatewayJWTMissingApp + } + app, ok := appInfo.(map[string]interface{}) + if !ok { + return ErrAPIGatewayJWTAppInfoParseFail + } + + verifiedRaw, ok := app["verified"] + if !ok { + return ErrAPIGatewayJWTAppInfoNoVerified + } + + verified, ok := verifiedRaw.(bool) + if !ok { + return ErrAPIGatewayJWTAppInfoVerifiedNotBool + } + + if !verified { + return ErrAPIGatewayJWTAppNotVerified + } + return nil +} diff --git a/src/core-api/pkg/middleware/bk_gateway_jwt_test.go b/src/core-api/pkg/middleware/bk_gateway_jwt_test.go new file mode 100644 index 000000000..2b771fcb0 --- /dev/null +++ b/src/core-api/pkg/middleware/bk_gateway_jwt_test.go @@ -0,0 +1,120 @@ +/* + * TencentBlueKing is pleased to support the open source community by making + * 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. + * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + * + * We undertake not to change the open source license (MIT license) applicable + * to the current version of the project delivered to anyone in the future. + */ + +package middleware + +import ( + "context" + "io" + "net/http" + "net/http/httptest" + "testing" + + gomonkey "github.com/agiledragon/gomonkey/v2" + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" + + "core/pkg/cacheimpls" + "core/pkg/config" + "core/pkg/database" + "core/pkg/database/dao" + "core/pkg/logging" + "core/pkg/util" +) + +const testPublicKey = ` +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnzyis1ZjfNB0bBgKFMSv +vkTtwlvBsaJq7S5wA+kzeVOVpVWwkWdVha4s38XM/pa/yr47av7+z3VTmvDRyAHc +aT92whREFpLv9cj5lTeJSibyr/Mrm/YtjCZVWgaOYIhwrXwKLqPr/11inWsAkfIy +tvHWTxZYEcXLgAXFuUuaS3uF9gEiNQwzGTU1v0FqkqTBr4B8nW3HCN47XUu0t8Y0 +e+lf4s4OxQawWD79J9/5d3Ry0vbV3Am1FtGJiJvOwRsIfVChDpYStTcHTCMqtvWb +V6L11BWkpzGXSW4Hv43qa+GSYOD2QU68Mb59oSk2OB+BtOLpJofmbGEGgvmwyCI9 +MwIDAQAB +-----END PUBLIC KEY----- +` + +const testJwtToken = "eyJhbGciOiJSUzUxMiIsImtpZCI6InRlc3QiLCJ0eXAiOiJKV1QiLCJpYXQiOjE1NjA0ODMxMTZ9.eyJpc3MiOiJBUElHVyIsImFwcCI6eyJhcHBfY29kZSI6ImFwaWd3LXRlc3QiLCJ2ZXJpZmllZCI6dHJ1ZX0sInVzZXIiOnsidXNlcm5hbWUiOiJhZG1pbiJ9LCJleHAiOjE4NzI3NjgyNzksIm5iZiI6MTU2MDQ4MzExNn0.Me5NMNx6-Hqc5gfqxhWT0rrROrr-d-W-nvnCtptEinqwoRTQ-8KB6ZNro8Xr12k8hLgcfgRa9GjN5XT5XNXdaj2ThuIU7VdcdpXl1ynxKDAOhd5iPDds0O2ecC-jE_l8wWBGrcUUIeiNBNaUv6v6qnQMDPJbqxjU28gf7GA7stR8nsjpux_LL2MyOY27-e-_9bbh_eE1DudjkBc4vj78pgSSUJ-7bXT5-MpLFgsdrGtof2t0k2pP9bRNvGlH1HuK087PCQFRCmHb414OJ8CKyBYhzKXtG2ibPfsBFjaoU0Fq_tiv_eByAB1ACObIddRMq43JCs4vMqGcsn3Em5a-Lg" + +func TestBkGatewayJWTAuthMiddleware(t *testing.T) { + logging.InitLogger(&config.Config{}) + + database.DefaultDBClient = database.NewDBClient(&config.Database{}) + + r := gin.Default() + r.Use(BkGatewayJWTAuthMiddlewareV1()) + util.NewTestRouter(r) + + req, _ := http.NewRequest("GET", "/ping", nil) + w := httptest.NewRecorder() + + r.ServeHTTP(w, req) + + assert.Equal(t, http.StatusUnauthorized, w.Code) + + // request with invalid X-Bkapi-Jwt + patches := gomonkey.NewPatches() + + patches.ApplyFunc( + cacheimpls.GetGatewayByName, + func(ctx context.Context, name string) (gateway dao.Gateway, err error) { + return dao.Gateway{ID: 1}, nil + }, + ) + patches.ApplyFunc( + cacheimpls.GetJWTPublicKey, + func(ctx context.Context, gatewayID int64) (string, error) { + return testPublicKey, nil + }, + ) + + req2, _ := http.NewRequest("GET", "/ping", nil) + req2.Header.Set(BkGatewayJWTHeaderKey, "test") + w2 := httptest.NewRecorder() + r.ServeHTTP(w2, req2) + assert.Equal(t, http.StatusUnauthorized, w.Code) + defer w2.Result().Body.Close() + response, err := io.ReadAll(w2.Result().Body) + assert.NoError(t, err) + + assert.Contains(t, string(response), "token contains an invalid number of segment") + + // request with valid X-Bkapi-Jwt + patches.ApplyFunc( + cacheimpls.GetGatewayByName, + func(ctx context.Context, name string) (gateway dao.Gateway, err error) { + return dao.Gateway{ID: 1}, nil + }, + ) + patches.ApplyFunc( + cacheimpls.GetJWTPublicKey, + func(ctx context.Context, gatewayID int64) (string, error) { + return testPublicKey, nil + }, + ) + + req3, _ := http.NewRequest("GET", "/ping", nil) + req3.Header.Set(BkGatewayJWTHeaderKey, testJwtToken) + w3 := httptest.NewRecorder() + r.ServeHTTP(w3, req3) + defer w3.Result().Body.Close() + response, err = io.ReadAll(w3.Result().Body) + assert.NoError(t, err) + assert.Equal(t, http.StatusOK, w3.Code) + assert.Contains(t, string(response), "pong") +} diff --git a/src/core-api/pkg/server/router.go b/src/core-api/pkg/server/router.go index 7a7b12bf1..75831b63a 100644 --- a/src/core-api/pkg/server/router.go +++ b/src/core-api/pkg/server/router.go @@ -26,9 +26,13 @@ import ( "github.com/gin-gonic/contrib/sentry" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus/promhttp" + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" + _ "core/docs" "core/pkg/api/microgateway" + "core/pkg/api/open" "core/pkg/config" "core/pkg/database" "core/pkg/middleware" @@ -44,6 +48,10 @@ func NewRouter(cfg *config.Config) *gin.Engine { router := gin.Default() router.Use(middleware.RequestID()) + // metrics + router.Use(middleware.Metrics()) + // recovery sentry + router.Use(sentry.Recovery(raven.DefaultClient, false)) // basic // liveness @@ -77,23 +85,36 @@ func NewRouter(cfg *config.Config) *gin.Engine { }) // metrics router.GET("/metrics", gin.WrapH(promhttp.Handler())) + // router.GET("/version", handler.Version) // trace if cfg.Tracing.GinAPIEnabled() { // set gin otel router.Use(otelgin.Middleware(cfg.Tracing.ServiceName)) } - microGatewayRouter := router.Group("/api/v1/micro-gateway") - // metrics - microGatewayRouter.Use(middleware.Metrics()) - // recovery sentry - microGatewayRouter.Use(sentry.Recovery(raven.DefaultClient, false)) + // swagger docs + if cfg.Debug { + url := ginSwagger.URL("/swagger/doc.json") + router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url)) + } + + microGatewayRouter := router.Group("/api/v1/micro-gateway") microGatewayRouter.Use(middleware.APILogger()) microGatewayRouter.Use(middleware.MicroGatewayInstanceMiddleware()) microGatewayRouter.GET("/:micro_gateway_instance_id/permissions/", microgateway.QueryPermission) microGatewayRouter.GET("/:micro_gateway_instance_id/public_keys/", microgateway.QueryPublicKey) microGatewayRouter.POST("/:micro_gateway_instance_id/release/:publish_id/events/", microgateway.ReportPublishEvent) + + // open api + openRouterV1 := router.Group("/api/v1/open") + openRouterV1.Use(middleware.BkGatewayJWTAuthMiddlewareV1()) + openRouterV1.GET("gateways/:gateway_name/public_key/", open.QueryPublicKeyV1) + + openRouterV2 := router.Group("/api/v2/open") + openRouterV2.Use(middleware.BkGatewayJWTAuthMiddlewareV2()) + openRouterV2.GET("gateways/:gateway_name/public_key/", open.QueryPublicKeyV2) + return router } diff --git a/src/core-api/pkg/service/public_key.go b/src/core-api/pkg/service/public_key.go index c912edf0a..9a24edf10 100644 --- a/src/core-api/pkg/service/public_key.go +++ b/src/core-api/pkg/service/public_key.go @@ -30,6 +30,7 @@ import ( // GatewayPublicKeyService is the interface of gateway public key service type GatewayPublicKeyService interface { Get(ctx context.Context, instanceID, gatewayName string) (string, error) + GetByGatewayName(ctx context.Context, gatewayName string) (string, error) } type gatewayPublicKeyService struct { @@ -59,3 +60,18 @@ func (s *gatewayPublicKeyService) Get(ctx context.Context, instanceID, gatewayNa return publicKey, nil } + +// GetByGatewayName will get the gateway public key from cache by gatewayName +func (s *gatewayPublicKeyService) GetByGatewayName(ctx context.Context, gatewayName string) (string, error) { + // get gateway + gateway, err := cacheimpls.GetGatewayByName(ctx, gatewayName) + if err != nil { + return "", err + } + // query jwt + publicKey, err := cacheimpls.GetJWTPublicKey(ctx, gateway.ID) + if err != nil { + return "", err + } + return publicKey, nil +} diff --git a/src/core-api/pkg/service/public_key_test.go b/src/core-api/pkg/service/public_key_test.go index 349c358ef..cfc04637c 100644 --- a/src/core-api/pkg/service/public_key_test.go +++ b/src/core-api/pkg/service/public_key_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/assert" "core/pkg/cacheimpls" + "core/pkg/database/dao" "core/pkg/database/dao/mock" ) @@ -94,4 +95,66 @@ var _ = Describe("GatewayPublicKeyService", func() { assert.NoError(GinkgoT(), err) }) }) + + Describe("Get By GatewayName cases", func() { + var ctl *gomock.Controller + var gatewayName string + var patches *gomonkey.Patches + var svc GatewayPublicKeyService + + BeforeEach(func() { + patches = gomonkey.NewPatches() + ctl = gomock.NewController(GinkgoT()) + gatewayName = "gateway" + + mockManager := mock.NewMockJWTManager(ctl) + + svc = &gatewayPublicKeyService{ + jwtManager: mockManager, + } + }) + + AfterEach(func() { + ctl.Finish() + patches.Reset() + }) + + It("error", func() { + patches.ApplyFunc( + cacheimpls.GetGatewayByName, + func(ctx context.Context, name string) (gateway dao.Gateway, err error) { + return dao.Gateway{ID: 1}, nil + }, + ) + patches.ApplyFunc( + cacheimpls.GetJWTPublicKey, + func(ctx context.Context, gatewayID int64) (string, error) { + return "", errors.New("get GetActionDetail fail") + }, + ) + + publicKey, err := svc.GetByGatewayName(context.Background(), gatewayName) + assert.Empty(GinkgoT(), publicKey) + assert.Error(GinkgoT(), err) + }) + + It("ok", func() { + patches.ApplyFunc( + cacheimpls.GetGatewayByName, + func(ctx context.Context, name string) (gateway dao.Gateway, err error) { + return dao.Gateway{ID: 1}, nil + }, + ) + patches.ApplyFunc( + cacheimpls.GetJWTPublicKey, + func(ctx context.Context, gatewayID int64) (string, error) { + return "publicKey", nil + }, + ) + + publicKey, err := svc.GetByGatewayName(context.Background(), gatewayName) + assert.Equal(GinkgoT(), "publicKey", publicKey) + assert.NoError(GinkgoT(), err) + }) + }) }) diff --git a/src/core-api/pkg/service/publish_event_test.go b/src/core-api/pkg/service/publish_event_test.go index 5245824fe..e42dfd9eb 100644 --- a/src/core-api/pkg/service/publish_event_test.go +++ b/src/core-api/pkg/service/publish_event_test.go @@ -176,7 +176,6 @@ var _ = Describe("PublishEventService", func() { err := svc.Report(ctx, event) assert.Error(GinkgoT(), err) assert.Contains(GinkgoT(), err.Error(), "has been reported") - }) It("ok: report success", func() { diff --git a/src/core-api/pkg/util/response.go b/src/core-api/pkg/util/response.go index 809941e6a..7cd9880db 100644 --- a/src/core-api/pkg/util/response.go +++ b/src/core-api/pkg/util/response.go @@ -37,23 +37,53 @@ const ( SystemError = "InternalServerError" ) +// SuccessResponse ... +type SuccessResponse struct { + Data interface{} `json:"data"` +} + +// Error ... +type Error struct { + Code string `json:"code"` + Message string `json:"message"` + System string `json:"system"` +} + +// ErrorResponse ... +type ErrorResponse struct { + Error Error `json:"error"` +} + +// LegacySuccessResponse ... +type LegacySuccessResponse struct { + Data interface{} `json:"data"` + Result bool `json:"result"` + Message string `json:"message"` + Code int `json:"code"` +} + +// LegacyErrorResponse ... +type LegacyErrorResponse struct { + Result bool `json:"result"` + Message string `json:"message"` + Code int `json:"code"` +} + // SuccessJSONResponse ... func SuccessJSONResponse(c *gin.Context, data interface{}) { - c.JSON(http.StatusOK, gin.H{ - "data": data, + c.JSON(http.StatusOK, SuccessResponse{ + Data: data, }) } // BaseErrorJSONResponse ... func BaseErrorJSONResponse(c *gin.Context, errorCode string, message string, statusCode int) { // BaseJSONResponse(c, statusCode, code, message, gin.H{}) - c.JSON(statusCode, gin.H{ - "error": gin.H{ - "code": errorCode, - "message": message, - "system": "bk-apigateway", - }, - }) + c.JSON(statusCode, ErrorResponse{Error: Error{ + Code: errorCode, + Message: message, + System: "bk-apigateway", + }}) } // NewErrorJSONResponse ... @@ -66,6 +96,26 @@ func NewErrorJSONResponse( } } +// LegacySuccessJsonResponse ... +func LegacySuccessJsonResponse(c *gin.Context, data interface{}) { + // 兼容历史接口 + c.JSON(http.StatusOK, LegacySuccessResponse{ + Result: true, + Code: 0, + Data: data, + }) +} + +// LegacyErrorJSONResponse ... +func LegacyErrorJSONResponse(ctx *gin.Context, errorCode string, statusCode int, message string) { + // 兼容历史接口 + ctx.JSON(statusCode, LegacyErrorResponse{ + Result: false, + Code: 4000, + Message: message, + }) +} + // BadRequestErrorJSONResponse ... var ( BadRequestErrorJSONResponse = NewErrorJSONResponse(BadRequestError, http.StatusBadRequest)