Skip to content

Commit 39264cc

Browse files
committed
rename project from service-http to nsqauthd and update related configurations
1 parent adfc736 commit 39264cc

24 files changed

+1450
-611
lines changed

.github/workflows/ci.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'docs/**'
7+
- '.github/**'
8+
- '.gitignore'
9+
branches:
10+
- main
11+
tags:
12+
- 'v*.*.*'
13+
pull_request:
14+
branches:
15+
- main
16+
17+
env:
18+
# Use docker.io for Docker Hub if empty
19+
REGISTRY: ghcr.io
20+
# github.repository as <account>/<repo>
21+
IMAGE_NAME: ${{ github.repository }}
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Setup golang
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version: 1.24
34+
- name: Start Redis
35+
uses: supercharge/redis-github-action@1.8.0
36+
with:
37+
redis-version: 7
38+
- name: Install dependencies
39+
run: make deps
40+
- name: Unit Test
41+
run: make test
42+
43+
- name: Convert coverage report to table
44+
run: go tool cover -func=coverage.out | tail -n +2 | awk '{print "|",$1,"|",$3,"|"}' > coverage_table.md
45+
46+
- name: Comment on PR with coverage table
47+
if: github.event_name == 'pull_request'
48+
working-directory: cmd/tools/pr
49+
run: go mod tidy && go run main.go
50+
continue-on-error: true
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
REPO_NAME: ${{ github.repository }}
54+
PR_NUMBER: ${{ github.event.number }}
55+
COVERAGE_FILE: ../../../coverage_table.md
56+
- name: Build
57+
run: make build
58+
- name: Vendor
59+
run: go mod vendor
60+
61+
# Login against a Docker registry except on PR
62+
# https://github.com/docker/login-action
63+
- name: Log into registry ${{ env.REGISTRY }}
64+
if: github.event_name != 'pull_request'
65+
uses: docker/login-action@v3
66+
with:
67+
registry: ${{ env.REGISTRY }}
68+
username: ${{ github.actor }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Set up QEMU
72+
if: github.event_name != 'pull_request'
73+
uses: docker/setup-qemu-action@v3
74+
75+
- name: Set up Docker Buildx
76+
if: github.event_name != 'pull_request'
77+
uses: docker/setup-buildx-action@v3
78+
79+
# Extract metadata (tags, labels) for Docker
80+
# https://github.com/docker/metadata-action
81+
- name: Extract Docker metadata
82+
id: meta
83+
if: github.event_name != 'pull_request'
84+
uses: docker/metadata-action@v5
85+
with:
86+
images: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}'
87+
flavor: |
88+
latest=auto
89+
tags: |
90+
type=schedule
91+
type=ref,event=tag
92+
type=sha,prefix=,format=long,enable=true,priority=100
93+
94+
# Build and push Docker image with Buildx (don't push on PR)
95+
# https://github.com/docker/build-push-action
96+
- name: Build and push Docker image
97+
if: github.event_name != 'pull_request'
98+
uses: docker/build-push-action@v5
99+
with:
100+
context: .
101+
file: Dockerfile
102+
push: ${{ github.event_name != 'pull_request' }}
103+
tags: ${{ steps.meta.outputs.tags }}
104+
labels: ${{ steps.meta.outputs.labels }}
105+
platforms: linux/amd64

.github/workflows/release.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
env:
9+
# Use docker.io for Docker Hub if empty
10+
REGISTRY: ghcr.io
11+
# github.repository as <account>/<repo>
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
os: [linux, windows, darwin]
20+
arch: [amd64, arm64]
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
- name: Setup golang
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: 1.24
28+
- name: Start Redis
29+
uses: supercharge/redis-github-action@1.8.0
30+
with:
31+
redis-version: 7
32+
- name: Install dependencies
33+
run: make deps
34+
- name: Unit Test
35+
run: make test
36+
- name: Build
37+
run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o admin
38+
- name: Windows
39+
if: matrix.os == 'windows'
40+
run: mv admin admin.exe
41+
- name: Archive artifact
42+
if: matrix.os != 'windows'
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: admin-${{ matrix.os }}-${{ matrix.arch }}
46+
path: |
47+
admin
48+
public
49+
config/*.yml
50+
- name: Archive artifact
51+
if: matrix.os == 'windows'
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: admin-${{ matrix.os }}-${{ matrix.arch }}
55+
path: |
56+
admin.exe
57+
public
58+
config/*.yml
59+
60+
release:
61+
runs-on: ubuntu-latest
62+
needs: build
63+
steps:
64+
- name: Download artifact
65+
uses: actions/download-artifact@v4
66+
67+
- name: Get latest release version
68+
id: get_release
69+
run: |
70+
LATEST_RELEASE=$(curl -s https://api.github.com/repos/mss-boot-io/mss-boot-admin-antd/releases/latest)
71+
VERSION=$(echo $LATEST_RELEASE | jq -r '.tag_name')
72+
echo "LATEST_RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
73+
74+
- name: Download dist-local.tar.gz
75+
run: |
76+
wget https://github.com/mss-boot-io/mss-boot-admin-antd/releases/download/${{ env.LATEST_RELEASE_VERSION }}/dist-local.tar.gz
77+
tar -zxvf dist-local.tar.gz
78+
cp -r dist admin-linux-amd64/
79+
cp -r dist admin-linux-arm64/
80+
cp -r dist admin-darwin-amd64/
81+
cp -r dist admin-darwin-arm64/
82+
cp -r dist admin-windows-amd64/
83+
cp -r dist admin-windows-arm64/
84+
85+
- name: Package
86+
run: |
87+
zip -r admin-linux-amd64.zip admin-linux-amd64
88+
zip -r admin-linux-arm64.zip admin-linux-arm64
89+
zip -r admin-darwin-amd64.zip admin-darwin-amd64
90+
zip -r admin-darwin-arm64.zip admin-darwin-arm64
91+
zip -r admin-windows-amd64.zip admin-windows-amd64
92+
zip -r admin-windows-arm64.zip admin-windows-arm64
93+
94+
- name: Get version
95+
id: get_version
96+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
97+
98+
- name: Release
99+
uses: softprops/action-gh-release@v1
100+
with:
101+
generate_release_notes: true
102+
files: |
103+
admin-linux-amd64.zip
104+
admin-linux-arm64.zip
105+
admin-darwin-amd64.zip
106+
admin-darwin-arm64.zip
107+
admin-windows-amd64.zip
108+
admin-windows-arm64.zip
109+
prerelease: false
110+
body: |
111+
## Pull Image
112+
```shell
113+
docker pull ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.VERSION }}
114+
```
115+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ go.work*
2323
# idea
2424
.idea
2525
# vscode
26-
.vscode
26+
.vscode
27+
*.db

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# service-http
1+
# nsqauthd
22
mss-boot http service example

apis/auth.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package apis
2+
3+
import (
4+
"github.com/mss-boot-io/mss-boot/pkg/response/actions"
5+
"net/http"
6+
7+
"github.com/gin-gonic/gin"
8+
"github.com/mss-boot-io/mss-boot/pkg/config/gormdb"
9+
"github.com/mss-boot-io/mss-boot/pkg/response"
10+
"github.com/mss-boot-io/mss-boot/pkg/response/controller"
11+
12+
"nsqauthd/config"
13+
"nsqauthd/dto"
14+
"nsqauthd/models"
15+
)
16+
17+
func init() {
18+
e := &Auth{
19+
Simple: controller.NewSimple(
20+
controller.WithAuth(false),
21+
controller.WithModelProvider(actions.ModelProviderGorm),
22+
),
23+
}
24+
response.AppendController(e)
25+
}
26+
27+
type Auth struct {
28+
*controller.Simple
29+
}
30+
31+
func (e *Auth) GetAction(_ string) response.Action {
32+
return nil
33+
}
34+
35+
func (e *Auth) Other(r *gin.RouterGroup) {
36+
r.GET("/auth", e.Auth)
37+
}
38+
39+
// Auth authenticate
40+
// @Summary authenticate
41+
// @Description authenticate
42+
// @Tags auth
43+
// @Accept application/json
44+
// @Product application/json
45+
// @Param secret query string true "secret"
46+
// @Param remote_ip query string true "remote_ip"
47+
// @Param tls query bool false "tls"
48+
// @Success 200 {object} dto.AuthResp
49+
// @Router /auth [get]
50+
func (e *Auth) Auth(ctx *gin.Context) {
51+
api := response.Make(ctx)
52+
req := &dto.AuthReq{}
53+
if api.Bind(req).Error != nil {
54+
api.Err(http.StatusForbidden, "NOT_AUTHORIZED")
55+
return
56+
}
57+
resp := &dto.AuthResp{
58+
Identity: req.Secret,
59+
TTL: config.Cfg.TTL,
60+
Authorizations: make([]*dto.AuthAccount, 0),
61+
}
62+
auth := models.Auth{
63+
Login: req.Secret,
64+
}
65+
err := auth.GetByLogin(ctx, gormdb.DB)
66+
if err != nil {
67+
api.AddError(err).Log.Error("get auth failed", "err", err)
68+
api.Err(http.StatusForbidden, "NOT_AUTHORIZED")
69+
return
70+
}
71+
if req.TLS != auth.TlsRequired {
72+
api.Err(http.StatusForbidden, "NOT_AUTHORIZED")
73+
return
74+
}
75+
authAccount := &dto.AuthAccount{}
76+
authAccount.Channels, authAccount.Topic, authAccount.Permissions = auth.ToAuthPermissions()
77+
resp.Authorizations = append(resp.Authorizations, authAccount)
78+
api.OK(resp)
79+
}

apis/model.go

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)