8000 Extended documentation: where should it go? · Issue #40 · ankane/authtrail · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Extended documentation: where should it go? #40
Closed
@mroach

Description

@mroach

I just got this setup in our environment and it's solving our needs perfectly!

I wanted to share a bit of setup that might be useful to others, but didn't want to open a PR until chatting about where it should go.

The situation: when running apps on Google Cloud, their load balancers/ingresses will provide client geocode information to your application so you don't have to do it yourself.

config/initializers/authtrail.rb

AuthTrail.geocode = false

AuthTrail.transform_method = lambda do |data, request|
  data[:country] = request.headers['HTTP_X_CLIENT_REGION']
  data[:region] = request.headers['HTTP_X_CLIENT_REGION_SUBDIVISION']
  data[:city] = request.headers['HTTP_X_CLIENT_CITY']

  if (value = request.headers['HTTP_X_CLIENT_CITY_LATLONG'])
    lat, long = value.split(',').map(&:to_f)
    data[:latitude] = lat
    data[:longitude] = long
  end
end

When using Kubernetes, you get these headers by creating a BackendConfig and wiring it up to your Service

---
apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: myapp-backend-beconf
  labels:
    app: myapp
    tier: backend
spec:
  customRequestHeaders:
    headers:
      - "X-Client-Region:{client_region}"
      - "X-Client-Region-Subdivision:{client_region_subdivision}"
      - "X-Client-City:{client_city}"
      - "X-Client-City-LatLong:{client_city_lat_long}"

---
apiVersion: v1
kind: Service
metadata:
  name: myapp-backend
  labels:
    app: myapp
    tier: backend
  annotations:
    cloud.google.com/backend-config: '{"default": "myapp-backend-beconf"}'

See https://cloud.google.com/load-balancing/docs/custom-headers#variables

Google puts the country code in the 'region' field, probably because of Hong Kong, Macau, Taiwan, Kosovo, etc...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0