Skip to content

Conversation

sarahzinger
Copy link
Contributor

When working on grafana/timestream-datasource#285 we noticed that in order to not rely on env variables we have to grab auth settings from the datasource instance's context and pass them along to GetSession.

However this is easy to forget/miss. This pr will create a new method for getting session which is passed in the datasource instance's context with auth settings and sets it as appropriate.

@sarahzinger sarahzinger requested a review from a team as a code owner June 4, 2024 17:37
}

// When calling, be sure that the context passed is the datasource instance's context which contains auth settings
func (sc *SessionCache) GetSessionWithContext(ctx context.Context, c GetSessionWithContextConfig) (*session.Session, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that I'm the one that suggested this approach, but if we need to use the instance context every time we get a session, it may be better to make this something like GetSessionWithAuthSettings(authSettings AuthSettings, c SessionConfig) and remove the AuthSettings from the SessionConfig to make it a clearer separation (cloudwatch is the only one using SessionConfig.AuthSettings so it's fine). This implementation is going to end up requiring us to store the context, which is discouraged in Go, while if we take the AuthSettings as an argument we can store those on the instance instead.

@njvrzm do you have any ideas/preferences for how to organize this?

@sarahzinger sarahzinger changed the title Create GetSessionWithContext Create GetSessionWithAuthSettings Jun 5, 2024
@sarahzinger
Copy link
Contributor Author

Ok updated as you suggested @iwysiu so that auth settings are now explicitly required to be passed in (with instructions on how to do so), rather than read from the env (or pulled from a stored context)

@sarahzinger sarahzinger requested a review from iwysiu June 5, 2024 19:14
return credentials.NewCredentials(defaults.RemoteCredProvider(*sess.Config, sess.Handlers))
}

type GetSessionConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably just use SessionConfig for GetSessionWithAuthSettings but this works too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i guess my thinking is that sessionConfig has authsettings in there which seems confusing to have a property in there we never would fill out idk.

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

Successfully merging this pull request may close these issues.

2 participants