Skip to content

Commit 540dc5f

Browse files
authored
Merge pull request #38 from satisfactorymodding/staging
feat: dedis
2 parents 4aa7cb0 + 004a8c7 commit 540dc5f

File tree

132 files changed

+2545
-760
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2545
-760
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use nix

.github/workflows/build.yml

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,78 @@ jobs:
1616
uses: actions/checkout@v3
1717

1818
- name: Download dependencies
19-
run: sudo apt update && sudo apt install -y build-essential libpng-dev
19+
run: |
20+
sudo apt update && sudo apt install -y build-essential libpng-dev protobuf-compiler
21+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
22+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
23+
24+
- name: Go Generate
25+
run: go generate -tags tools -x ./...
26+
27+
- name: Build
28+
run: go build -v -o api-linux-amd64 .
29+
env:
30+
CGO_ENABLED: 1
31+
32+
lint:
33+
name: Lint
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Set up Go
37+
uses: actions/setup-go@v3
38+
with:
39+
go-version: 1.19
40+
41+
- name: Check out code into the Go module directory
42+
uses: actions/checkout@v3
43+
44+
- name: Download dependencies
45+
run: |
46+
sudo apt update && sudo apt install -y build-essential libpng-dev protobuf-compiler
47+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
48+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
2049
2150
- name: Go Generate
2251
run: go generate -tags tools -x ./...
2352

2453
- name: golangci-lint
2554
uses: golangci/golangci-lint-action@v3
2655
with:
56+
version: v1.49.0
2757
skip-pkg-cache: true
2858
skip-build-cache: true
2959
args: --timeout 5m
3060

31-
- name: Build
32-
run: go build -v -o api-linux-amd64 .
61+
test:
62+
name: Test
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Set up Go
66+
uses: actions/setup-go@v3
67+
with:
68+
go-version: 1.19
69+
70+
- name: Check out code into the Go module directory
71+
uses: actions/checkout@v3
72+
73+
- name: Download dependencies
74+
run: |
75+
sudo apt update && sudo apt install -y build-essential libpng-dev protobuf-compiler
76+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
77+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
78+
79+
- name: Go Generate
80+
run: go generate -tags tools -x ./...
81+
82+
- name: Start stack
83+
run: docker-compose -f docker-compose-dev.yml up -d
84+
85+
- name: Test
86+
run: go test -v -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... ./...
3387
env:
3488
CGO_ENABLED: 1
89+
REPO_PASETO.PUBLIC_KEY: 408c5155a389aeabf1c1b0da73ff5a3079b6aa6628e4c661b1e1ce412181cc8a
90+
REPO_PASETO.PRIVATE_KEY: a5f7409588f6b72d443db0d432f37f1214a5ec88cb55a70e24b90194ed549465408c5155a389aeabf1c1b0da73ff5a3079b6aa6628e4c661b1e1ce412181cc8a
91+
92+
- name: Codecov
93+
uses: codecov/codecov-action@v1

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ jobs:
2121
fetch-depth: 0
2222

2323
- name: Download dependencies
24-
run: sudo apt update && sudo apt install -y build-essential libpng-dev
24+
run: |
25+
sudo apt update && sudo apt install -y build-essential libpng-dev protobuf-compiler
26+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
27+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
2528
2629
- name: Run GoReleaser
2730
uses: goreleaser/goreleaser-action@v3

.golangci.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,58 @@ linters-settings:
1414
ignorePackageGlobs:
1515
- github.com/satisfactorymodding/smr-api/*
1616

17+
govet:
18+
check-shadowing: true
19+
enable-all: true
20+
disable:
21+
- shadow
22+
23+
gocritic:
24+
disabled-checks:
25+
- ifElseChain
26+
27+
gci:
28+
custom-order: true
29+
sections:
30+
- standard
31+
- default
32+
- prefix(github.com/satisfactorymodding/smr-api)
33+
- blank
34+
- dot
35+
36+
run:
37+
skip-files:
38+
- ./generated/generated.go
39+
- ./generated/models_gen.go
40+
skip-dirs:
41+
- ./docs/
42+
1743
issues:
1844
exclude:
1945
- should pass the context parameter
2046

2147
linters:
2248
disable-all: true
2349
enable:
24-
- deadcode
2550
- errcheck
2651
- gosimple
2752
- govet
2853
- ineffassign
2954
- staticcheck
30-
- structcheck
3155
- typecheck
3256
- unused
33-
- varcheck
3457
- bidichk
3558
- contextcheck
3659
- durationcheck
3760
- errorlint
3861
- goconst
3962
- goimports
4063
- revive
41-
- ifshort
4264
- misspell
4365
- prealloc
4466
- whitespace
45-
- wrapcheck
67+
- wrapcheck
68+
- gci
69+
- gocritic
70+
- gofumpt
71+
- nonamedreturns

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
FROM golang:1.18-alpine AS builder
1+
FROM golang:1.19-alpine3.18 AS builder
22

3-
RUN apk add --no-cache git build-base libpng-dev
3+
RUN apk add --no-cache git build-base libpng-dev protoc
4+
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
5+
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
46

57
WORKDIR $GOPATH/src/github.com/satisfactorymodding/smr-api/
68

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SMR API [![build](https://github.com/satisfactorymodding/smr-api/actions/workflows/build.yml/badge.svg)](https://github.com/satisfactorymodding/smr-api/actions/workflows/build.yml)
1+
# SMR API ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/satisfactorymodding/smr-api/build) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/satisfactorymodding/smr-api) [![codecov](https://codecov.io/gh/satisfactorymodding/smr-api/branch/master/graph/badge.svg?token=LFNKYWS0N2)](https://codecov.io/gh/satisfactorymodding/smr-api) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/satisfactorymodding/smr-api)
22

33
The Satisfactory Mod Repository backend API
44

@@ -30,7 +30,7 @@ To run the API, you will need to have a working Postgres, Redis and Storage. The
3030
start via:
3131

3232
```bash
33-
docker-compose -f docker-compose.dev.yml up -d
33+
docker-compose -f docker-compose-dev.yml up -d
3434
```
3535

3636
It is suggested you create a configuration file at `config.json` (but you can also use environment variables).
@@ -49,6 +49,14 @@ Main configuration options:
4949

5050
The config format can be seen in `config/config.go` (each dot means a new level of nesting).
5151

52+
After startup requires the following minio commands to be executed:
53+
54+
```shell
55+
mc alias set local http://localhost:9000 minio minio123
56+
mc admin user svcacct add local minio --access-key REPLACE_ME_KEY --secret-key REPLACE_ME_SECRET
57+
mc anonymous set public local/smr
58+
```
59+
5260
## Contributing
5361

5462
Before contributing, please run the [linter](https://golangci-lint.run/) to ensure the code is clean and well-formed:

api.go

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@ import (
99
"syscall"
1010
"time"
1111

12-
"github.com/satisfactorymodding/smr-api/auth"
13-
"github.com/satisfactorymodding/smr-api/config"
14-
"github.com/satisfactorymodding/smr-api/dataloader"
15-
"github.com/satisfactorymodding/smr-api/db"
16-
"github.com/satisfactorymodding/smr-api/db/postgres"
17-
18-
"github.com/pkg/errors"
19-
20-
// Load REST docs
21-
_ "github.com/satisfactorymodding/smr-api/docs"
22-
"github.com/satisfactorymodding/smr-api/generated"
23-
"github.com/satisfactorymodding/smr-api/gql"
24-
"github.com/satisfactorymodding/smr-api/migrations"
25-
"github.com/satisfactorymodding/smr-api/nodes"
26-
"github.com/satisfactorymodding/smr-api/oauth"
27-
"github.com/satisfactorymodding/smr-api/redis"
28-
"github.com/satisfactorymodding/smr-api/redis/jobs"
29-
30-
// Load redis consumers
31-
_ "github.com/satisfactorymodding/smr-api/redis/jobs/consumers"
32-
"github.com/satisfactorymodding/smr-api/storage"
33-
"github.com/satisfactorymodding/smr-api/util"
34-
"github.com/satisfactorymodding/smr-api/validation"
35-
3612
"github.com/99designs/gqlgen/graphql/handler"
3713
"github.com/99designs/gqlgen/graphql/handler/extension"
3814
"github.com/99designs/gqlgen/graphql/handler/lru"
@@ -42,6 +18,7 @@ import (
4218
"github.com/labstack/echo-contrib/pprof"
4319
"github.com/labstack/echo/v4"
4420
"github.com/labstack/echo/v4/middleware"
21+
"github.com/pkg/errors"
4522
"github.com/rs/zerolog/log"
4623
"github.com/spf13/viper"
4724
echoSwagger "github.com/swaggo/echo-swagger"
@@ -54,6 +31,27 @@ import (
5431
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
5532
"go.opentelemetry.io/otel/trace"
5633
"gopkg.in/go-playground/validator.v9"
34+
35+
"github.com/satisfactorymodding/smr-api/auth"
36+
"github.com/satisfactorymodding/smr-api/config"
37+
"github.com/satisfactorymodding/smr-api/dataloader"
38+
"github.com/satisfactorymodding/smr-api/db"
39+
"github.com/satisfactorymodding/smr-api/db/postgres"
40+
"github.com/satisfactorymodding/smr-api/generated"
41+
"github.com/satisfactorymodding/smr-api/gql"
42+
"github.com/satisfactorymodding/smr-api/migrations"
43+
"github.com/satisfactorymodding/smr-api/nodes"
44+
"github.com/satisfactorymodding/smr-api/oauth"
45+
"github.com/satisfactorymodding/smr-api/redis"
46+
"github.com/satisfactorymodding/smr-api/redis/jobs"
47+
"github.com/satisfactorymodding/smr-api/storage"
48+
"github.com/satisfactorymodding/smr-api/util"
49+
"github.com/satisfactorymodding/smr-api/validation"
50+
51+
// Load REST docs
52+
_ "github.com/satisfactorymodding/smr-api/docs"
53+
// Load redis consumers
54+
_ "github.com/satisfactorymodding/smr-api/redis/jobs/consumers"
5755
)
5856

5957
type CustomValidator struct {
@@ -64,8 +62,8 @@ func (cv *CustomValidator) Validate(i interface{}) error {
6462
return errors.Wrap(cv.validator.Struct(i), "validation error")
6563
}
6664

67-
func Serve() {
68-
ctx := config.InitializeConfig()
65+
func Initialize(baseCtx context.Context) context.Context {
66+
ctx := config.InitializeConfig(baseCtx)
6967

7068
if os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") != "" {
7169
cleanup := installExportPipeline(ctx)
@@ -81,9 +79,18 @@ func Serve() {
8179
auth.InitializeAuth()
8280
jobs.InitializeJobs(ctx)
8381
validation.InitializeVirusTotal()
82+
util.PrintFeatureFlags()
8483

84+
return ctx
85+
}
86+
87+
func Migrate(ctx context.Context) {
8588
migrations.RunMigrations(ctx)
89+
}
8690

91+
var e *echo.Echo
92+
93+
func Setup(ctx context.Context) {
8794
if viper.GetBool("profiler") {
8895
go func() {
8996
debugServer := echo.New()
@@ -101,7 +108,7 @@ func Serve() {
101108

102109
dataValidator := validator.New()
103110

104-
e := echo.New()
111+
e = echo.New()
105112
e.HideBanner = true
106113
e.Validator = &CustomValidator{validator: dataValidator}
107114

@@ -271,7 +278,9 @@ func Serve() {
271278
<-signals
272279
_ = e.Close()
273280
}()
281+
}
274282

283+
func Serve() {
275284
address := fmt.Sprintf(":%d", viper.GetInt("port"))
276285
log.Info().Str("address", address).Msg("starting server")
277286

@@ -311,3 +320,14 @@ func newResource() *resource.Resource {
311320
)
312321
return r
313322
}
323+
324+
func Start() {
325+
ctx := Initialize(context.Background())
326+
Migrate(ctx)
327+
Setup(ctx)
328+
Serve()
329+
}
330+
331+
func Stop() error {
332+
return errors.Wrap(e.Close(), "failed to stop http server")
333+
}

auth/permissions.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ var (
105105
}
106106
)
107107

108-
var idToGroupMapping = make(map[string]*Group)
109-
var roleToGroupMapping = make(map[*Role][]*Group)
108+
var (
109+
idToGroupMapping = make(map[string]*Group)
110+
roleToGroupMapping = make(map[*Role][]*Group)
111+
)
110112

111113
func initializePermissions() {
112114
groups := []*Group{GroupAdmin, GroupModerator, GroupSMLDev, GroupBootstrapDev, GroupCompatibilityOfficer}

cmd/api/serve.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
import smr "github.com/satisfactorymodding/smr-api"
3+
import "github.com/satisfactorymodding/smr-api"
44

55
// @title Satisfactory Mod Repo API
66
// @version 1
@@ -12,5 +12,5 @@ import smr "github.com/satisfactorymodding/smr-api"
1212
// @host api.ficsit.app
1313
// @BasePath /v1
1414
func main() {
15-
smr.Serve()
15+
smr.Start()
1616
}

cmd/paseto/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
func main() {
99
publicKey, privateKey, err := ed25519.GenerateKey(nil)
10-
1110
if err != nil {
1211
panic(err)
1312
}

0 commit comments

Comments
 (0)