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

Extended documentation: where should it go? #40

Closed
mroach opened this issue Feb 19, 2021 · 2 comments
Closed

Extended documentation: where should it go? #40

mroach opened this issue Feb 19, 2021 · 2 comments

Comments

@mroach
Copy link

mroach commented Feb 19, 2021

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...

@ankane
Copy link
Owner

ankane commented Mar 4, 2021

Hey @mroach, thanks for sharing! Just added a section on load balancer geocoding to the readme with a link to this example (this seems like a good place for it).

@mroach
Copy link
Author

mroach commented Mar 4, 2021

Cool! I'll close this then as there's no action to be taken.

@mroach mroach closed this as completed Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants