Skip to content

Commit

Permalink
X-Showcase-User を debug 時無視するように (#531)
Browse files Browse the repository at this point in the history
* X-Showcase-User を debug 時無視するように

* fix
  • Loading branch information
ryoha000 authored Mar 12, 2023
1 parent d3e3d7e commit 6808496
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,56 @@
management tool for equipment and book rental

## Development environment

### Setup with docker and docker-compose

#### First Up (or entirely rebuild)

```
$ docker-compose up --build
$ docker compose -f .\compose-dev.yml up --build
```

Now you can access to `http://localhost:3000` for booQ

And you can access booQ MariaDB by executing commands
`docker-compose exec db bash` and `mysql -uroot -ppassword -Dbooq`
`docker-compose exec db bash` and `mysql -uroot -ppassword -Dbooq`

You can also execute build shell script

```
$ sh scripts/build.sh
```

And start development

```
$ sh scripts/up.sh
```
```

#### test

You can test this project

```
$ docker-compose -f docker/test/docker-compose.yml up --abort-on-container-exit
```

Or you can also execute test shell script

```
$ sh scripts/test.sh
```

#### Rebuild

`docker-compose up --no-deps --build`

#### Destroy Containers and Volumes

`docker-compose down -v`

## Contribution

The task list is in [issue](https://github.com/traPtitech/booQ/issues)

1. Fork it ( https://github.com/traPtitech/booQ )
Expand Down
47 changes: 47 additions & 0 deletions compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: "3"
services:
db:
image: mariadb:10.6.4
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: booq
MYSQL_USERNAME: root
MYSQL_PASSWORD: password
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
expose:
- '3306'
ports:
- '3306:3306'
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u$$MYSQL_USERNAME -p$$MYSQL_ROOT_PASSWORD
interval: 6s
timeout: 60s
retries: 20
start_period: 5s

booq-server:
build: .
environment:
BOOQ_ENV: development
MYSQL_HOST: db
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_DATABASE: booq
DEBUG_USER_NAME: ryoha
volumes:
- './:/app'
tty: true
ports:
- '8080:3001'
depends_on:
db:
condition: service_healthy

swagger:
image: swaggerapi/swagger-ui
volumes:
- ./docs/swagger.yml:/usr/share/nginx/html/sample.yaml
environment:
API_URL: sample.yaml
ports:
- "4000:8080"
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func main() {

db, err := model.EstablishConnection()
if err != nil {
panic(err)
Expand Down Expand Up @@ -65,7 +64,7 @@ func main() {
e.Use(middleware.Recover())

// Routing
router.SetupRouting(e, router.CreateUserProvider())
router.SetupRouting(e, router.CreateUserProvider(os.Getenv("DEBUG_USER_NAME")))

// Start server
e.Logger.Fatal(e.Start(":3001"))
Expand Down
11 changes: 7 additions & 4 deletions router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ func (client *UserProvider) MiddlewareAuthUser(next echo.HandlerFunc) echo.Handl
}
}

func CreateUserProvider() *UserProvider {
func CreateUserProvider(debugUserName string) *UserProvider {
return &UserProvider{AuthUser: func(c echo.Context) (echo.Context, error) {
res := c.Request().Header.Get("X-Showcase-User")
if res == "" {
return c, errors.New("認証に失敗しました(Headerに必要な情報が存在しません)")
res := debugUserName
if debugUserName == "" {
res = c.Request().Header.Get("X-Showcase-User")
if res == "" {
return c, errors.New("認証に失敗しました(Headerに必要な情報が存在しません)")
}
}
user, _ := model.GetUserByName(res)
if user.Name == "" {
Expand Down

0 comments on commit 6808496

Please sign in to comment.