common-fate / granted

The easiest way to access your cloud.
https://granted.dev
MIT License
955 stars 90 forks source link

Improve Granted startup time when HTTP registry is used #673

Closed chrnorm closed 4 weeks ago

chrnorm commented 4 weeks ago

What changed?

Defers calling config.LoadDefault() every time assume is called, which makes startup instant rather than taking ~1s to obtain an access token.

Why?

Makes assume run a lot faster when HTTP Profile Registries are used.

How did you test it?

Confirmed locally, by running GRANTED_LOG=debug dassume. Here's the latest release -- you can see in the debug logs that we fetch a token every time Granted runs:

❯ GRANTED_LOG=debug assume
[DEBUG] configured config sources   sources:[env,file]
[DEBUG] loading config      path:/Users/chrisnorman/.cf/config
[DEBUG] loaded config   cfg:{CurrentContext:default Contexts:map[default:{name:default APIURL:https://internal.commonfate.io AccessURL:https://commonfate.example.com AuthzURL: OIDCIssuer:https://auth.example.com OIDCClientID:XXXXXXX OIDCClientSecret: HTTPClient:<nil> OIDCProvider:<nil> TokenSource:<nil> TokenStore:<nil>}]}
[DEBUG] attempting to fetch token: https://auth.example.com

Whereas the dev build no longer fetches the token:

❯ GRANTED_LOG=debug dassume
[DEBUG] checking if autosync has been run for the day
[DEBUG] skipping profile registry sync until tomorrow=%s/Users/chrisnorman/Library/Application Support/commonfate/registry-sync
[DEBUG] process args    execFlag:   osargs:[dassumego]  c.args:[]
[DEBUG] processed profile name
[DEBUG] exec config:<nil>

Potential risks

Affects the HTTP profile registry component of Granted.

Is patch release candidate?

Yes