Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

badaas as library #61

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dc408d6
update mockery version
FrancoLiberali Jul 27, 2023
e2c0776
fix typos in Authentication, resource and constructor
FrancoLiberali Jul 27, 2023
83e1446
fix route for auth unit tests
FrancoLiberali Jul 27, 2023
33e371c
remove error that is always nil
FrancoLiberali Jul 27, 2023
03c876c
add TODO to the changes to be done in the session service
FrancoLiberali Jul 27, 2023
960f598
add error management to middlewareJSON
FrancoLiberali Jul 27, 2023
1f7761f
add CommandInitializer to init configuration keys
FrancoLiberali Jul 27, 2023
28e3ecb
init database configuration keys
FrancoLiberali Jul 27, 2023
63de335
init session configuration keys
FrancoLiberali Jul 27, 2023
807e598
init initialization configuration keys
FrancoLiberali Jul 27, 2023
2de14ef
init server configuration keys
FrancoLiberali Jul 27, 2023
2dc5907
init logger configuration keys
FrancoLiberali Jul 27, 2023
cbb6f5c
remove unused r.md file in commands
FrancoLiberali Jul 27, 2023
d165eec
move time to utils
FrancoLiberali Jul 27, 2023
b80f2e4
create super user when adding the auth controller
FrancoLiberali Jul 27, 2023
88db618
update info controller and routes creation
FrancoLiberali Jul 27, 2023
1730a33
change the way badaas server is created
FrancoLiberali Jul 27, 2023
25f8e57
move test e2e to test_e2e/ and docker to docker/
FrancoLiberali Jul 28, 2023
f1bed03
do not run auto migration on test e2e execution + automigration refactor
FrancoLiberali Jul 28, 2023
f523952
update docs and developers utils
FrancoLiberali Jul 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
.editorconfig
.git
.gitignore
.github
sonar-project.properties
AUTHORS.md
CONTRIBUTING.md
*.md
LICENSE
Makefile
NOTICE
README.md
arm/
powerpc/
mips/
.golangci.yml
_temp
.vscode
node1
node2
node3
.gitignore
changelog.md
go.work
go.work.sum
tools/
test_e2e/
!test_e2e/test_api.go
!test_e2e/go.mod
!test_e2e/go.sum
mocks/
docker/
**/*_test.go
15 changes: 9 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@ title: ''
labels: Bug
---

**Describe the bug**
## Describe the bug

A clear and concise description of what the bug is.

**To Reproduce**
## To Reproduce

Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
## Expected behavior

A clear and concise description of what you expected to happen.

**Screenshots**
## Screenshots

If applicable, add screenshots to help explain your problem.

**Application (please complete the following information):**
## Application

Please complete the following information:

- badaas version [X.X.X] or commit hash

**Additional context**
## Additional context

Add any other context about the problem here.
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/user_story.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ labels: User Story, To be verify

`[Put all others constraints here, like list of acceptances values or other]`

## Resources:
## Resources

`[Put all your resources here, like mockups, diagrams or other here]`

Expand All @@ -37,4 +37,3 @@ labels: User Story, To be verify
## Links

`[Only use by the team, to link this feature with epic, technical tasks or bugs]`

4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:information_source: Don't forget to modify the changelog.md before merging this branch.

:information_source: Don't forget to modify config files:
- `badaas.example.yml`: the example file.
- `/scripts/e2e/api/ci-conf.yml`: otherwise you will probably break the CI. (*For local testing please use [act](https://github.com/nektos/act)*).

- `badaas.example.yml`: the example file.
53 changes: 26 additions & 27 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
branch-naming-rules:
name: Check branch name
Expand All @@ -18,8 +19,8 @@ jobs:
min_length: 5
max_length: 50

unit-tests:
name: Unit tests
check-style:
name: Code style
needs: [branch-naming-rules]
runs-on: ubuntu-latest
steps:
Expand All @@ -30,15 +31,16 @@ jobs:
with:
go-version: '^1.18'
cache: true
- name: Run test
run: go test $(go list ./... | sed 1d) -coverprofile=coverage.out -v
- uses: actions/upload-artifact@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
name: coverage
path: coverage.out
version: v1.52.2
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true

check-style:
name: Code style
unit-tests:
name: Unit tests
needs: [branch-naming-rules]
runs-on: ubuntu-latest
steps:
Expand All @@ -49,14 +51,12 @@ jobs:
with:
go-version: '^1.18'
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
- name: Run unit tests
run: go test ./... -coverprofile=coverage_unit.out -v
- uses: actions/upload-artifact@v3
with:
version: latest
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
name: coverage_unit
path: coverage_unit.out

e2e-tests:
name: E2E Tests
Expand All @@ -71,25 +71,25 @@ jobs:
go-version: '^1.18'
cache: true
- name: Start containers
run: docker compose -f "scripts/e2e/docker-compose.yml" up -d --build
run: docker compose -f "docker/test_db/docker-compose.yml" -f "docker/test_api/docker-compose.yml" up -d --build
- name: Wait for API server to be up
uses: mydea/action-wait-for-api@v1
with:
url: "http://localhost:8000/info"
timeout: 20
timeout: 60
- name: Run test
run: go test -v
run: go test ./test_e2e -v
- name: Get logs
if: always()
run: docker compose -f "scripts/e2e/docker-compose.yml" logs --no-color 2>&1 | tee app.log &
run: docker compose -f "docker/test_db/docker-compose.yml" -f "docker/test_api/docker-compose.yml" logs --no-color 2>&1 | tee app.log &
- name: Stop containers
if: always()
run: docker compose -f "scripts/e2e/docker-compose.yml" down
run: docker compose -f "docker/test_db/docker-compose.yml" -f "docker/test_api/docker-compose.yml" down
- uses: actions/upload-artifact@v3
with:
name: docker-compose-e2e-logs
path: app.log

sonarcloud:
name: SonarCloud
needs: [unit-tests, check-style]
Expand All @@ -98,14 +98,13 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download line coverage report
- name: Download unit tests line coverage report
uses: actions/download-artifact@v3
with:
name: coverage
path: coverage.out
name: coverage_unit
path: coverage_unit.out
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
11 changes: 4 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Go workspace file
go.work
# go.work

# cockroach files
node*

#Vscode conf
# vscode conf
.vscode

# binary output
badaas

# temporary directories
_temp
badaas
73 changes: 31 additions & 42 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

### Unit tests

We use the standard test suite in combination with [github.com/stretchr/testify](https://github.com/stretchr/testify) to do our unit testing. Mocks are generated using [mockery](https://github.com/vektra/mockery) a mock generator using this command `mockery --all --keeptree`.
We use the standard test suite in combination with [github.com/stretchr/testify](https://github.com/stretchr/testify) to do our unit testing. Mocks are generated using [mockery](https://github.com/vektra/mockery) a mock generator using this command `make test_generate_mocks`.

To run them, please run:

```sh
go test $(go list ./... | sed 1d) -v
make test_unit
```

### Feature tests (of end to end tests)
Expand All @@ -29,75 +29,64 @@ We use docker to run a Badaas instance in combination with one node of Cockroach
Run:

```sh
docker compose -f "scripts/e2e/docker-compose.yml" up -d --build
make test_e2e
```

Then in an another shell:

```sh
go test -v
```

The feature files can be found in the `feature` folder.
The feature files can be found in the `test_e2e/features` folder.

## Logger

We use ubber's [zap](https://pkg.go.dev/go.uber.org/zap) to log stuff, please take `zap.Logger` as an argument for your services constructors. [fx](https://github.com/uber-go/fx) will provide your service with an instance.
We use uber's [zap](https://pkg.go.dev/go.uber.org/zap) to log stuff, please take `zap.Logger` as an argument for your services constructors. [fx](https://github.com/uber-go/fx) will provide your service with an instance.

## Directory structure

This is the directory structure we use for the project:

- `commands/` *(Go code)*: Contains all the CLI commands. This package relies heavily on github.com/ditrit/verdeter.
- `configuration/` *(Go code)*: Contains all the configuration holders. Please only use the interfaces, they are all mocked for easy testing
- `configuration/` *(Go code)*: Contains all the configuration keys and holders. Please only use the interfaces, they are all mocked for easy testing.
- `controllers/` *(Go code)*: Contains all the http controllers, they handle http requests and consume services.
- `docs/`: Contains the documentation.
- `features/`: Contains all the feature tests (or end to end tests).
- `docker/` : Contains the docker, docker-compose file and configuration files for different environments.
- `test_db/` : Contains the Dockerfile to build a development/test version of CockroachDB.
- `test_api/` : Contains files to build a development/test version of the api.
- `test_e2e/`: Contains all the feature and steps for e2e tests.
- `logger/` *(Go code)*: Contains the logger creation logic. Please don't call it from your own services and code, use the dependency injection system.
- `persistance/` *(Go code)*:
- `/gormdatabase/` *(Go code)*: Contains the logic to create a <https://gorm.io> database. Also contains a go package named `gormzap`: it is a compatibility layer between *gorm.io/gorm* and *github.com/uber-go/zap*.
- `/models/` *(Go code)*: Contains the models. (For a structure to me considered a valid model, it has to embed `models.BaseModel` and satisfy the `models.Tabler` interface. This interface returns the name of the sql table.)
- `/dto/` *(Go code)*: Contains the Data Transfert Objects. They are used mainly to decode json payloads.
- `/pagination/` *(Go code)*: Contains the pagination logic.
- `/repository/` *(Go code)*: Contains the repository interface and implementation. Use uint as ID when using gorm models.
- `resources/` *(Go code)*: Contains the resources shared with the rest of the codebase (ex: API version).
- `persistance/` *(Go code)*:
- `gormdatabase/` *(Go code)*: Contains the logic to create a <https://gorm.io> database. Also contains a go package named `gormzap`: it is a compatibility layer between *gorm.io/gorm* and *github.com/uber-go/zap*.
- `models/` *(Go code)*: Contains the models. (For a structure to me considered a valid model, it has to embed `models.BaseModel` and satisfy the `models.Tabler` interface. This interface returns the name of the sql table.).
- `dto/` *(Go code)*: Contains the Data Transfer Objects. They are used mainly to decode json payloads.
- `pagination/` *(Go code)*: Contains the pagination logic.
- `repository/` *(Go code)*: Contains the repository interfaces and implementations to manage queries to the database.
- `router/` *(Go code)*: Contains http router of badaas.
- `/middlewares/` *(Go code)*: Contains the various http middlewares that we use.
- `scripts/e2e/` : Contains the docker-compose file for end-to-end test.
- `/api/` : Contains the Dockerfile to build badaas with a dedicated config file.
- `/db/` : Contains the Dockerfile to build a developpement version of CockroachDB.
- `services/` *(Go code)*: Contains the Dockerfile to build a developpement version of CockroachDB.
- `/auth/protocols/`: Contains the implementations of authentication clients for differents protocols.
- `/basicauth/` *(Go code)*: Handle the authentification using email/password.
- `/oidc/` *(Go code)*: Handle the authentication via Open-ID Connect.
- `/sessionservice/` *(Go code)*: Handle sessions and their lifecycle.
- `/userservice/` *(Go code)*: Handle users.
- `validators/` *(Go code)*: Contains validators such as an email validator.
- `middlewares/` *(Go code)*: Contains the various http middlewares that we use.
- `services/` *(Go code)*: Contains services.
- `auth/protocols/`: Contains the implementations of authentication clients for different protocols.
- `basicauth/` *(Go code)*: Handle the authentication using email/password.
- `sessionservice/` *(Go code)*: Handle sessions and their lifecycle.
- `userservice/` *(Go code)*: Handle users.
- `utils/` *(Go code)*: Contains utility functions that can be used all around the project.
- `validators/` *(Go code)*: Contains validators such as an email validator.

At the root of the project, you will find:

- The README.
- The changelog.
- The files for the E2E test http support.
- The LICENCE file.
- The LICENSE file.

## Git

### Branch naming policy

`[BRANCH_TYPE]/[BRANCH_NAME]`

- `BRANCH_TYPE` is a prefix to describe the purpose of the branch.

- `BRANCH_TYPE` is a prefix to describe the purpose of the branch.
Accepted prefixes are:
- `feature`, used for feature development
- `bugfix`, used for bug fix
- `improvement`, used for refacto
- `improvement`, used for refactor
- `library`, used for updating library
- `prerelease`, used for preparing the branch for the release
- `release`, used for releasing project
- `hotfix`, used for applying a hotfix on main
- `poc`, used for proof of concept
- `poc`, used for proof of concept
- `BRANCH_NAME` is managed by this regex: `[a-z0-9._-]` (`_` is used as space character).

### Default branch
Expand All @@ -113,9 +102,9 @@ We use [Semantic Versioning](https://semver.org/spec/v2.0.0.html) as guideline f
Steps to release:

- Create a new branch labeled `release/vX.Y.Z` from the latest `main`.
- Improve the version number in `changelog.md` and `resources/api.go`.
- Improve the version number in `changelog.md`.
- Verify the content of the `changelog.md`.
- Commit the modifications with the label `Release version X.Y.Z`.
- Create a pull request on github for this branch into `main`.
- Once the pull request validated and merged, tag the `main` branch with `vX.Y.Z`
- After the tag is pushed, make the release on the tag in GitHub
- Once the pull request validated and merged, tag the `main` branch with `vX.Y.Z`.
- After the tag is pushed, make the release on the tag in GitHub.
13 changes: 0 additions & 13 deletions Dockerfile

This file was deleted.

Loading
Loading