Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
fix #171: use X-Passport-ID as identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Oct 18, 2018
1 parent 25e4f62 commit e88f409
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
18 changes: 11 additions & 7 deletions env/client/rest.http
@@ -1,33 +1,37 @@
### API v1

GET http://localhost:8080/api/v1/10000000-2000-4000-8000-160000000004
Accept: text/html
Accept: text/html
Authorization: Bearer 10000000-2000-4000-8000-160000000003
X-Request-ID: 10000000-2000-4000-8000-160000000000

###

GET http://localhost:8080/api/v1/10000000-2000-4000-8000-160000000004
Accept: application/json
Accept: application/json
Authorization: Bearer 10000000-2000-4000-8000-160000000003
X-Request-ID: 10000000-2000-4000-8000-160000000000

###

GET http://localhost:8080/api/v1/10000000-2000-4000-8000-160000000004
Accept: application/xml
Accept: application/xml
Authorization: Bearer 10000000-2000-4000-8000-160000000003
X-Request-ID: 10000000-2000-4000-8000-160000000000

###

GET http://localhost:8080/api/v1/10000000-2000-4000-8000-160000000004
Accept: text/plain
Accept: text/plain
Authorization: Bearer 10000000-2000-4000-8000-160000000003
X-Request-ID: 10000000-2000-4000-8000-160000000000

###

POST http://localhost:8080/api/v1/10000000-2000-4000-8000-160000000004
Content-Type: application/x-www-form-urlencoded
Cookie: identifier=10000000-2000-4000-8000-160000000000
X-Request-ID: 10000000-2000-4000-8000-160000000011
Content-Type: application/x-www-form-urlencoded
X-Passport-ID: 10000000-2000-4000-8000-160000000000
X-Request-ID: 10000000-2000-4000-8000-160000000000

email=test@my.email

Expand Down
9 changes: 4 additions & 5 deletions env/docker/compose/docker-compose.base.yml
Expand Up @@ -4,29 +4,28 @@ services:

db:
image: postgres:10-alpine # https://hub.docker.com/_/postgres/
env_file: .env
env_file: ../../.env

migration:
image: kamilsk/form-api:3.x # https://hub.docker.com/r/kamilsk/form-api/
command: [ "migrate" ]
depends_on:
- db
env_file: .env
env_file: ../../.env
restart: on-failure

service:
image: kamilsk/form-api:3.x # https://hub.docker.com/r/kamilsk/form-api/
command: [ "run", "--with-profiling", "--with-monitoring" ]
depends_on:
- migration
env_file: .env
env_file: ../../.env

server:
image: kamilsk/nginx:alpine # https://hub.docker.com/r/kamilsk/nginx/
depends_on:
- service
env_file: .env
restart: on-failure
env_file: ../../.env
volumes:
- ./etc/nginx.conf:/etc/nginx/nginx.conf:ro
- ./etc/service.conf:/etc/nginx/conf.d/default.conf:ro
30 changes: 26 additions & 4 deletions pkg/domain/event_http.go
Expand Up @@ -6,10 +6,12 @@ import (
)

const (
cookieHeader = "Cookie"
optionsHeader = "X-Forma-Options"
refererHeader = "Referer"
userAgentHeader = "User-Agent"
cookieHeader = "Cookie"
identifierHeader = "X-Passport-ID"
optionsHeader = "X-Forma-Options"
refererHeader = "Referer"
requestHeader = "X-Request-ID"
userAgentHeader = "User-Agent"
)

// FromCookies returns converted value from request's cookies.
Expand Down Expand Up @@ -44,6 +46,16 @@ func (context InputContext) Header(key string) string {
return http.Header(context.Headers).Get(key)
}

// Identifier TODO issue#173
func (context InputContext) Identifier() *ID {
header := context.Header(identifierHeader)
if header != "" {
id := ID(header)
return &id
}
return nil
}

// Option TODO issue#173
func (context InputContext) Option() Option {
split := func(str string) []string {
Expand Down Expand Up @@ -74,6 +86,16 @@ func (context InputContext) Referer() string {
return context.Header(refererHeader)
}

// Request TODO issue#173
func (context InputContext) Request() *ID {
header := context.Header(requestHeader)
if header != "" {
id := ID(header)
return &id
}
return nil
}

// UserAgent TODO issue#173
func (context InputContext) UserAgent() string {
return context.Header(userAgentHeader)
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/service.go
Expand Up @@ -94,7 +94,7 @@ func (service *Forma) HandleInput(ctx context.Context, req v1.PostRequest) (resp
SchemaID: req.ID,
InputID: input.ID,
TemplateID: req.InputData.Template(),
Identifier: nil, // TODO issue#171
Identifier: req.Context.Identifier(),
Context: req.Context,
Code: http.StatusFound, // TODO issue#design
URL: resp.URL,
Expand Down

0 comments on commit e88f409

Please sign in to comment.