Skip to content

Commit

Permalink
feat(openapi): add openapi auth and version ,echo apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Sep 6, 2024
1 parent 78678d2 commit 3336b98
Show file tree
Hide file tree
Showing 34 changed files with 481 additions and 224 deletions.
1 change: 1 addition & 0 deletions api/openapi.api
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import "openapi/auth.api"
import "openapi/demo.api"
36 changes: 36 additions & 0 deletions api/openapi/auth.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
syntax = "v1"

info(
title: "Demo Open API"
desc: "This is a api of Open API in Artisan Cloud"
author: "Matrix-X"
email: "[email protected]"
version: "v1"
)

@server(
group: openapi/auth
prefix: /openapi/v1/auth
)


service PowerX {
@doc "Auth by platform"
@handler AuthPlatform
post / (PlatformAuthRequest) returns (PlatformAuthResponse)
}


type (
PlatformAuthRequest {
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
}

PlatformAuthResponse {
TokenType string `json:"tokenType"`
ExpiresIn string `json:"expiresIn"`
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
}
)
2 changes: 1 addition & 1 deletion api/openapi/demo.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "v1"

info(
title: "Demo Open API"
desc: "This is a demo Open API for testing purposes."
desc: "This is a api of Open API in Artisan Cloud"
author: "Matrix-X"
email: "[email protected]"
version: "v1"
Expand Down
16 changes: 16 additions & 0 deletions etc/powerx-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ JWT:
MPJWTSecret: dev_mp # 小程序 JWT密钥
WebJWTSecret: dev_web # Web JWT密钥

OpenAPI:
platforms:
# 访问PowerX OpenAPI的restful 配置
brain_x:
access_key: "key_power_x"
secret_key: "123456789"

providers:
# 访问BrainX OpenAPI的restful 配置
brain_x:
base_url: "http://127.0.0.1:8000/openapi/v1"
access_key: "key_brain_x"
secret_key: '987654321'

Casbin:
SelfHosted: true # 是否使用自己的Casbin服务

Expand All @@ -47,7 +61,9 @@ PowerXDatabase:

RedisBase:
Host: 127.0.0.1:6379
Username:
Password:
DB: 0

WechatOA:
AppId: wx93607xxxxxxxxxx # 微信公众号AppID
Expand Down
85 changes: 1 addition & 84 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,90 +8,6 @@ import (
const DriverPostgres = "postgres"
const DriverMysql = "mysql"

type Database struct {
Driver string
DSN string
SeedCommerceData bool
SeedDepartment bool
}

type RedisBase struct {
Host string
//Username string
Password string
//DB int
}

type WeWork struct {
CropId string
AgentId int
Secret string
Token string
EncodingAESKey string
OAuth struct {
Callback string
Scopes []string
}
HttpDebug bool
Debug bool
}

type WechatOA struct {
AppId string
Secret string
AESKey string
OAuth struct {
Callback string
Scopes []string
}
HttpDebug bool
Debug bool
}

type WechatPay struct {
AppId string
MchId string
MchApiV3Key string
Key string
CertPath string
KeyPath string
RSAPublicKeyPath string
SerialNo string
WechatPaySerial string
NotifyUrl string
HttpDebug bool
Debug bool
}

type WechatMP struct {
AppId string
Secret string
AESKey string
OAuth struct {
Callback string
Scopes []string
}
HttpDebug bool
Debug bool
}

type MediaResource struct {
LocalStorage struct {
StoragePath string
}
OSS struct {
Enable bool
Minio struct {
Endpoint string
Credentials struct {
AccessKey string
SecretKey string
}
UseSSL bool
}
}
}

type Root struct {
Account string
Password string
Expand All @@ -109,6 +25,7 @@ type Config struct {
MPJWTSecret string
WebJWTSecret string
}
OpenAPI OpenAPI

PowerXDatabase Database
RedisBase RedisBase
Expand Down
8 changes: 8 additions & 0 deletions internal/config/database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package config

type Database struct {
Driver string
DSN string
SeedCommerceData bool
SeedDepartment bool
}
18 changes: 18 additions & 0 deletions internal/config/mediaResource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

type MediaResource struct {
LocalStorage struct {
StoragePath string
}
OSS struct {
Enable bool
Minio struct {
Endpoint string
Credentials struct {
AccessKey string
SecretKey string
}
UseSSL bool
}
}
}
15 changes: 15 additions & 0 deletions internal/config/openapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package config

import (
"PowerX/internal/config/openapiplatform"
"PowerX/internal/config/openapiprovider"
)

type OpenAPI struct {
Platforms struct {
BrainX openapiplatform.BrainX
}
Providers struct {
BrainX openapiprovider.BrainX
}
}
6 changes: 6 additions & 0 deletions internal/config/openapiplatform/brainx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package openapiplatform

type BrainX struct {
AccessKey string
SecretKey string
}
7 changes: 7 additions & 0 deletions internal/config/openapiprovider/brainx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package openapiprovider

type BrainX struct {
BaseUrl string
AccessKey string
SecretKey string
}
8 changes: 8 additions & 0 deletions internal/config/redis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package config

type RedisBase struct {
Host string
Username string
Password string
DB int
}
54 changes: 54 additions & 0 deletions internal/config/wechat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package config

type WeWork struct {
CropId string
AgentId int
Secret string
Token string
EncodingAESKey string
OAuth struct {
Callback string
Scopes []string
}
HttpDebug bool
Debug bool
}

type WechatOA struct {
AppId string
Secret string
AESKey string
OAuth struct {
Callback string
Scopes []string
}
HttpDebug bool
Debug bool
}

type WechatPay struct {
AppId string
MchId string
MchApiV3Key string
Key string
CertPath string
KeyPath string
RSAPublicKeyPath string
SerialNo string
WechatPaySerial string
NotifyUrl string
HttpDebug bool
Debug bool
}

type WechatMP struct {
AppId string
Secret string
AESKey string
OAuth struct {
Callback string
Scopes []string
}
HttpDebug bool
Debug bool
}
29 changes: 29 additions & 0 deletions internal/handler/openapi/auth/authplatformhandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package auth

import (
"net/http"

"PowerX/internal/logic/openapi/auth"
"PowerX/internal/svc"
"PowerX/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)

// Auth by platform
func AuthPlatformHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PlatformAuthRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := auth.NewAuthPlatformLogic(r.Context(), svcCtx)
resp, err := l.AuthPlatform(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
Loading

0 comments on commit 3336b98

Please sign in to comment.