Skip to content

Commit

Permalink
add api with swagger and basic api (login method)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Apr 24, 2024
1 parent 8672e6c commit ddf5c8b
Show file tree
Hide file tree
Showing 17 changed files with 1,065 additions and 0 deletions.
115 changes: 115 additions & 0 deletions api/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// 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}}",
"termsOfService": "https://kerberos.io",
"contact": {
"name": "API Support",
"url": "https://www.kerberos.io",
"email": "support@kerberos.io"
},
"license": {
"name": "Apache 2.0 - Commons Clause",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/login": {
"post": {
"description": "Get Authorization token.",
"tags": [
"authentication"
],
"summary": "Get Authorization token.",
"operationId": "login",
"parameters": [
{
"description": "Credentials",
"name": "credentials",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Authentication"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Authorization"
}
}
}
}
}
},
"definitions": {
"models.Authentication": {
"type": "object",
"properties": {
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"models.Authorization": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"expire": {
"type": "string"
},
"role": {
"type": "string"
},
"token": {
"type": "string"
},
"username": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "",
BasePath: "/",
Schemes: []string{},
Title: "Swagger Kerberos Agent API",
Description: "This is the API for using and configure Kerberos Agent.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
90 changes: 90 additions & 0 deletions api/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"swagger": "2.0",
"info": {
"description": "This is the API for using and configure Kerberos Agent.",
"title": "Swagger Kerberos Agent API",
"termsOfService": "https://kerberos.io",
"contact": {
"name": "API Support",
"url": "https://www.kerberos.io",
"email": "support@kerberos.io"
},
"license": {
"name": "Apache 2.0 - Commons Clause",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"basePath": "/",
"paths": {
"/api/login": {
"post": {
"description": "Get Authorization token.",
"tags": [
"authentication"
],
"summary": "Get Authorization token.",
"operationId": "login",
"parameters": [
{
"description": "Credentials",
"name": "credentials",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Authentication"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Authorization"
}
}
}
}
}
},
"definitions": {
"models.Authentication": {
"type": "object",
"properties": {
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"models.Authorization": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"expire": {
"type": "string"
},
"role": {
"type": "string"
},
"token": {
"type": "string"
},
"username": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}
60 changes: 60 additions & 0 deletions api/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
basePath: /
definitions:
models.Authentication:
properties:
password:
type: string
username:
type: string
type: object
models.Authorization:
properties:
code:
type: integer
expire:
type: string
role:
type: string
token:
type: string
username:
type: string
type: object
info:
contact:
email: support@kerberos.io
name: API Support
url: https://www.kerberos.io
description: This is the API for using and configure Kerberos Agent.
license:
name: Apache 2.0 - Commons Clause
url: http://www.apache.org/licenses/LICENSE-2.0.html
termsOfService: https://kerberos.io
title: Swagger Kerberos Agent API
version: "1.0"
paths:
/api/login:
post:
description: Get Authorization token.
operationId: login
parameters:
- description: Credentials
in: body
name: credentials
required: true
schema:
$ref: '#/definitions/models.Authentication'
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.Authorization'
summary: Get Authorization token.
tags:
- authentication
securityDefinitions:
Bearer:
in: header
name: Authorization
type: apiKey
swagger: "2.0"
56 changes: 56 additions & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module github.com/uug-ai/facial-access-control/api

go 1.22.1

require (
github.com/appleboy/gin-jwt/v2 v2.9.2
github.com/gin-contrib/cors v1.7.1
github.com/gin-contrib/pprof v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/sirupsen/logrus v1.9.3
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.3
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/bytedance/sonic v1.11.3 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit ddf5c8b

Please sign in to comment.