Compare commits
2 Commits
eabdc8772e
...
f6aac5dceb
| Author | SHA1 | Date | |
|---|---|---|---|
| f6aac5dceb | |||
| b266a46f2d |
@@ -26,6 +26,12 @@ jobs:
|
|||||||
-u "${{ vars.REGISTRY_USERNAME }}" \
|
-u "${{ vars.REGISTRY_USERNAME }}" \
|
||||||
--password-stdin
|
--password-stdin
|
||||||
|
|
||||||
|
- name: Sync Host Repo
|
||||||
|
working-directory: /data/www/lone-services
|
||||||
|
run: |
|
||||||
|
git fetch origin develop
|
||||||
|
git pull origin develop
|
||||||
|
|
||||||
- name: Pull and Deploy
|
- name: Pull and Deploy
|
||||||
working-directory: /data/www/lone-services/deploy
|
working-directory: /data/www/lone-services/deploy
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ D:\Git\bin\bash.exe rpc/scripts/gen-rpc.sh order
|
|||||||
rpc/scripts/gen-rpc.sh order
|
rpc/scripts/gen-rpc.sh order
|
||||||
```
|
```
|
||||||
|
|
||||||
|
加一个服务需要在bff/etc/bff.yaml 加 Upstreams ,docker.compose.prod.yaml 加服务,nacos 加配置
|
||||||
|
|
||||||
## 如何加一个新服务
|
## 如何加一个新服务
|
||||||
|
|
||||||
以加 `order` 为例(对标现有 `product`)。
|
以加 `order` 为例(对标现有 `product`)。
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package logic
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"lone-services/pkg/utils"
|
"lone-services/pkg/utils"
|
||||||
chore "lone-services/rpc/chore/pb"
|
chore "lone-services/rpc/chore/pb"
|
||||||
@@ -21,12 +22,12 @@ type PolicyLogic struct {
|
|||||||
logx.Logger
|
logx.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// StsToken 对齐阿里云 STS 返回字段,并附带前端上传所需信息
|
// StsToken 对齐阿里云 STS Credentials,并附带前端上传所需信息
|
||||||
type StsToken struct {
|
type StsToken struct {
|
||||||
AccessKeyId string `json:"AccessKeyId"`
|
AccessKeyId string `json:"access_key_id"`
|
||||||
AccessKeySecret string `json:"AccessKeySecret"`
|
AccessKeySecret string `json:"access_key_secret"`
|
||||||
SecurityToken string `json:"SecurityToken"`
|
SecurityToken string `json:"security_token"`
|
||||||
Expiration string `json:"Expiration"`
|
Expiration string `json:"expiration"`
|
||||||
Bucket string `json:"bucket"`
|
Bucket string `json:"bucket"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region"`
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
@@ -34,6 +35,17 @@ type StsToken struct {
|
|||||||
Dir string `json:"dir"`
|
Dir string `json:"dir"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatExpiration(raw string) string {
|
||||||
|
if raw == "" {
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
t, err := time.Parse(time.RFC3339, raw)
|
||||||
|
if err != nil {
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
return t.Local().Format(utils.YMDHIS)
|
||||||
|
}
|
||||||
|
|
||||||
func NewPolicyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PolicyLogic {
|
func NewPolicyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PolicyLogic {
|
||||||
return &PolicyLogic{
|
return &PolicyLogic{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
@@ -42,6 +54,24 @@ func NewPolicyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PolicyLogi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateClient(accessKeyId, accessKeySecret, endpoint *string) (*sts20150401.Client, error) {
|
||||||
|
config := &openapi.Config{
|
||||||
|
AccessKeyId: accessKeyId,
|
||||||
|
AccessKeySecret: accessKeySecret,
|
||||||
|
}
|
||||||
|
config.Endpoint = endpoint
|
||||||
|
return sts20150401.NewClient(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AssumeRole(client *sts20150401.Client, roleArn, roleSessionName string, durationSeconds int64) (*sts20150401.AssumeRoleResponse, error) {
|
||||||
|
assumeRoleRequest := &sts20150401.AssumeRoleRequest{
|
||||||
|
DurationSeconds: tea.Int64(durationSeconds),
|
||||||
|
RoleArn: tea.String(roleArn),
|
||||||
|
RoleSessionName: tea.String(roleSessionName),
|
||||||
|
}
|
||||||
|
return client.AssumeRoleWithOptions(assumeRoleRequest, &util.RuntimeOptions{})
|
||||||
|
}
|
||||||
|
|
||||||
func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) {
|
func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) {
|
||||||
accessKeyId := utils.GetConfigString("oss.accessKeyId")
|
accessKeyId := utils.GetConfigString("oss.accessKeyId")
|
||||||
accessKeySecret := utils.GetConfigString("oss.accessKeySecret")
|
accessKeySecret := utils.GetConfigString("oss.accessKeySecret")
|
||||||
@@ -88,18 +118,13 @@ func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) {
|
|||||||
expire = 3600
|
expire = 3600
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := createStsClient(accessKeyId, accessKeySecret, stsEndpoint)
|
client, err := CreateClient(tea.String(accessKeyId), tea.String(accessKeySecret), tea.String(stsEndpoint))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Errorf("create STS client: %v", err)
|
l.Errorf("create STS client: %v", err)
|
||||||
return failResponse(utils.Fail), nil
|
return failResponse(utils.Fail), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
assumeRoleRequest := &sts20150401.AssumeRoleRequest{
|
resp, err := AssumeRole(client, roleArn, roleSessionName, expire)
|
||||||
DurationSeconds: tea.Int64(expire),
|
|
||||||
RoleArn: tea.String(roleArn),
|
|
||||||
RoleSessionName: tea.String(roleSessionName),
|
|
||||||
}
|
|
||||||
resp, err := client.AssumeRoleWithOptions(assumeRoleRequest, &util.RuntimeOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Errorf("AssumeRole: %v", err)
|
l.Errorf("AssumeRole: %v", err)
|
||||||
return failResponse(utils.Fail), nil
|
return failResponse(utils.Fail), nil
|
||||||
@@ -114,7 +139,7 @@ func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) {
|
|||||||
AccessKeyId: tea.StringValue(cred.AccessKeyId),
|
AccessKeyId: tea.StringValue(cred.AccessKeyId),
|
||||||
AccessKeySecret: tea.StringValue(cred.AccessKeySecret),
|
AccessKeySecret: tea.StringValue(cred.AccessKeySecret),
|
||||||
SecurityToken: tea.StringValue(cred.SecurityToken),
|
SecurityToken: tea.StringValue(cred.SecurityToken),
|
||||||
Expiration: tea.StringValue(cred.Expiration),
|
Expiration: formatExpiration(tea.StringValue(cred.Expiration)),
|
||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
Region: region,
|
Region: region,
|
||||||
Endpoint: endpoint,
|
Endpoint: endpoint,
|
||||||
@@ -123,12 +148,3 @@ func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) {
|
|||||||
}
|
}
|
||||||
return okResponse(token), nil
|
return okResponse(token), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createStsClient(accessKeyId, accessKeySecret, endpoint string) (*sts20150401.Client, error) {
|
|
||||||
config := &openapi.Config{
|
|
||||||
AccessKeyId: tea.String(accessKeyId),
|
|
||||||
AccessKeySecret: tea.String(accessKeySecret),
|
|
||||||
Endpoint: tea.String(endpoint),
|
|
||||||
}
|
|
||||||
return sts20150401.NewClient(config)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
login_out_time=43200 #api接口超时时间分
|
login_out_time=43200 #api接口超时时间分
|
||||||
login_refresh_out_time=83200
|
login_refresh_out_time=83200
|
||||||
name = "chore-service"
|
name = "chore-service"
|
||||||
listenOn = "0.0.0.0:10500"
|
listenOn = "0.0.0.0:10300"
|
||||||
mode = "dev"
|
mode = "dev"
|
||||||
[log]
|
[log]
|
||||||
path = "logs"
|
path = "logs"
|
||||||
@@ -18,8 +18,8 @@
|
|||||||
[oss]
|
[oss]
|
||||||
accessKeyId = "LTAI5t7U8KvxSiPE5auwQUuu"
|
accessKeyId = "LTAI5t7U8KvxSiPE5auwQUuu"
|
||||||
accessKeySecret = "xjfgbQQRpL4TcIspNuClg6bYADa3pk"
|
accessKeySecret = "xjfgbQQRpL4TcIspNuClg6bYADa3pk"
|
||||||
roleArn = "acs:ram::你的账号ID:role/你的角色名"
|
roleArn = "acs:ram::1663896742753915:role/oss-upload"
|
||||||
roleSessionName = "chore-oss-upload"
|
roleSessionName = "oss-upload"
|
||||||
region = "oss-cn-hangzhou"
|
region = "oss-cn-hangzhou"
|
||||||
bucketName = "lone-images"
|
bucketName = "lone-images"
|
||||||
endpoint = "https://lone-images.oss-accelerate.aliyuncs.com"
|
endpoint = "https://lone-images.oss-accelerate.aliyuncs.com"
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ type UserListRow struct {
|
|||||||
OnTrialNum int `gorm:"column:on_trial_num" json:"on_trial_num"`
|
OnTrialNum int `gorm:"column:on_trial_num" json:"on_trial_num"`
|
||||||
Gender int `gorm:"column:gender" json:"gender"`
|
Gender int `gorm:"column:gender" json:"gender"`
|
||||||
Birthday string `gorm:"column:birthday" json:"birthday"`
|
Birthday string `gorm:"column:birthday" json:"birthday"`
|
||||||
|
Status uint8 `gorm:"column:status" json:"status"`
|
||||||
CreatedAt utils.CustomTime `gorm:"column:created_at" json:"created_at"`
|
CreatedAt utils.CustomTime `gorm:"column:created_at" json:"created_at"`
|
||||||
UpdatedAt utils.CustomTime `gorm:"column:updated_at" json:"updated_at"`
|
UpdatedAt utils.CustomTime `gorm:"column:updated_at" json:"updated_at"`
|
||||||
}
|
}
|
||||||
@@ -102,6 +103,7 @@ type UserListItem struct {
|
|||||||
OnTrialNum int `json:"on_trial_num"`
|
OnTrialNum int `json:"on_trial_num"`
|
||||||
Gender int `json:"gender"`
|
Gender int `json:"gender"`
|
||||||
Birthday string `json:"birthday"`
|
Birthday string `json:"birthday"`
|
||||||
|
Status uint8 `json:"status"`
|
||||||
CreatedAt utils.CustomTime `json:"created_at"`
|
CreatedAt utils.CustomTime `json:"created_at"`
|
||||||
UpdatedAt utils.CustomTime `json:"updated_at"`
|
UpdatedAt utils.CustomTime `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ func (l *UserItemsLogic) UserItems(in *user.UserItemsReq) (*user.Response, error
|
|||||||
OnTrialNum: row.OnTrialNum,
|
OnTrialNum: row.OnTrialNum,
|
||||||
Gender: row.Gender,
|
Gender: row.Gender,
|
||||||
Birthday: row.Birthday,
|
Birthday: row.Birthday,
|
||||||
|
Status: row.Status,
|
||||||
CreatedAt: row.CreatedAt,
|
CreatedAt: row.CreatedAt,
|
||||||
UpdatedAt: row.UpdatedAt,
|
UpdatedAt: row.UpdatedAt,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user