Skip to content

Commit

Permalink
Merge pull request #14 from go-cinch/piupuer/dev
Browse files Browse the repository at this point in the history
[feat]add hotspot
  • Loading branch information
piupuer authored Oct 12, 2024
2 parents 41070c4 + 0632533 commit 7668e2b
Show file tree
Hide file tree
Showing 37 changed files with 1,823 additions and 1,034 deletions.
893 changes: 447 additions & 446 deletions api/auth/auth.pb.go

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions api/auth/auth.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions api/auth/auth_http.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions cmd/auth/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions configs/hotspot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hotspot:
# cache name prefix
name: 'hotspot'
# cache expire time for each key
expire: 86400s
15 changes: 15 additions & 0 deletions configs/task.yml
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
task:
# cron task list
cron:
refresh.hotspot:
name: 'refresh.hotspot'
expr: '0 0/5 * * * * *'
# all group name list(cron or once)
group:
# login failed will delay to update wrong count(once)
loginFailed: 'login.failed'
# login success will delay to update last login time(once)
loginLast: 'login.last'
# refresh hotspot(cron)
refreshHotspot: 'refresh.hotspot'
# refresh hotspot manual(once)
refreshHotspotManual: 'refresh.hotspot.manual'
114 changes: 57 additions & 57 deletions docs/auth-proto/auth.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,43 +122,78 @@ paths:
"200":
description: OK
content: {}
/captcha:
/idempotent:
get:
tags:
- Auth
operationId: Auth_Captcha
operationId: Auth_Idempotent
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/auth.v1.CaptchaReply'
/idempotent:
$ref: '#/components/schemas/auth.v1.IdempotentReply'
/info:
get:
tags:
- Auth
operationId: Auth_Idempotent
operationId: Auth_Info
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/auth.v1.IdempotentReply'
/info:
$ref: '#/components/schemas/auth.v1.InfoReply'
/logout:
post:
tags:
- Auth
operationId: Auth_Logout
requestBody:
content:
application/json: {}
required: true
responses:
"200":
description: OK
content: {}
/permission:
get:
tags:
- Auth
operationId: Auth_Info
operationId: Auth_Permission
parameters:
- name: resource
in: query
schema:
type: string
- name: method
in: query
schema:
type: string
- name: uri
in: query
schema:
type: string
responses:
"200":
description: OK
content: {}
/pub/captcha:
get:
tags:
- Auth
operationId: Auth_Captcha
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/auth.v1.InfoReply'
/login:
$ref: '#/components/schemas/auth.v1.CaptchaReply'
/pub/login:
post:
tags:
- Auth
Expand All @@ -176,41 +211,38 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/auth.v1.LoginReply'
/logout:
/pub/register:
post:
tags:
- Auth
operationId: Auth_Logout
operationId: Auth_Register
requestBody:
content:
application/json: {}
application/json:
schema:
$ref: '#/components/schemas/auth.v1.RegisterRequest'
required: true
responses:
"200":
description: OK
content: {}
/permission:
/pub/status:
get:
tags:
- Auth
operationId: Auth_Permission
operationId: Auth_Status
parameters:
- name: resource
in: query
schema:
type: string
- name: method
in: query
schema:
type: string
- name: uri
- name: username
in: query
schema:
type: string
responses:
"200":
description: OK
content: {}
content:
application/json:
schema:
$ref: '#/components/schemas/auth.v1.StatusReply'
/pwd:
post:
tags:
Expand Down Expand Up @@ -244,21 +276,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/auth.v1.LoginReply'
/register:
post:
tags:
- Auth
operationId: Auth_Register
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/auth.v1.RegisterRequest'
required: true
responses:
"200":
description: OK
content: {}
/role:
get:
tags:
Expand Down Expand Up @@ -370,23 +387,6 @@ paths:
"200":
description: OK
content: {}
/status:
get:
tags:
- Auth
operationId: Auth_Status
parameters:
- name: username
in: query
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/auth.v1.StatusReply'
/user:
get:
tags:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/google/wire v0.6.0
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.2.1
github.com/samber/lo v1.47.0
github.com/thoas/go-funk v0.9.3
go.opentelemetry.io/otel v1.30.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ github.com/go-cinch/common/idempotent v1.0.4 h1:E/Ab+FHWjs1ym0U0mips6MyHEzucEded
github.com/go-cinch/common/idempotent v1.0.4/go.mod h1:t4rBikz+RhpmF0tdGx+rm0Z1FzDy/6GtelgFB7RlaiY=
github.com/go-cinch/common/jwt v1.0.3 h1:/jznvjevW+2KsmWm666O1NxkHLSfVmrjoWwkuWAqewk=
github.com/go-cinch/common/jwt v1.0.3/go.mod h1:++p7kddWh9SyCYIYWEb5mfiR+ljKC3I5puiyjz7oGNs=
github.com/go-cinch/common/log v1.1.0/go.mod h1:O4k/ArEdZS6c+YPKdESWJnVfhQ0QlwtIQ6mYxJZt5po=
github.com/go-cinch/common/log v1.1.1 h1:9ot3Qw4BKDfOZ7IC/3ZreuYJb953YD7pmM6ev6xT9FY=
github.com/go-cinch/common/log v1.1.1/go.mod h1:O4k/ArEdZS6c+YPKdESWJnVfhQ0QlwtIQ6mYxJZt5po=
github.com/go-cinch/common/middleware/i18n v1.0.5 h1:SmxEMljqYF8xraaaa3KZgvNbKIE06ShQAZ34w87wkvs=
Expand Down Expand Up @@ -209,6 +208,8 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rubenv/sql-migrate v1.5.1 h1:WsZo4jPQfjmddDTh/suANP2aKPA7/ekN0LzuuajgQEo=
github.com/rubenv/sql-migrate v1.5.1/go.mod h1:H38GW8Vqf8F0Su5XignRyaRcbXbJunSWxs+kmzlg0Is=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/shirou/gopsutil/v3 v3.23.6 h1:5y46WPI9QBKBbK7EEccUPNXpJpNrvPuTD0O2zHEHT08=
github.com/shirou/gopsutil/v3 v3.23.6/go.mod h1:j7QX50DrXYggrpN30W0Mo+I4/8U2UUIQrnrhqUeWrAU=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
Expand Down
1 change: 1 addition & 0 deletions internal/biz/biz.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var ProviderSet = wire.NewSet(
NewUserGroupUseCase,
NewPermissionUseCase,
NewWhitelistUseCase,
NewHotspotUseCase,
)

type Transaction interface {
Expand Down
35 changes: 35 additions & 0 deletions internal/biz/hotspot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package biz

import (
"context"

"auth/internal/conf"
)

type HotspotRepo interface {
Refresh(ctx context.Context) error
GetUserByCode(ctx context.Context, code string) *User
GetUserByUsername(ctx context.Context, username string) *User
GetRoleByID(ctx context.Context, id uint64) *Role
GetActionByWord(ctx context.Context, word string) *Action
GetActionByCode(ctx context.Context, code string) *Action
FindActionByCode(ctx context.Context, codes ...string) []Action
FindWhitelistResourceByCategory(ctx context.Context, category uint32) []string
FindUserGroupByUserCode(ctx context.Context, code string) []UserGroup
}

type HotspotUseCase struct {
c *conf.Bootstrap
repo HotspotRepo
}

func NewHotspotUseCase(c *conf.Bootstrap, repo HotspotRepo) *HotspotUseCase {
return &HotspotUseCase{
c: c,
repo: repo,
}
}

func (uc *HotspotUseCase) Refresh(ctx context.Context) error {
return uc.repo.Refresh(ctx)
}
Loading

0 comments on commit 7668e2b

Please sign in to comment.