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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get temporary credentials from credentials file #88

Merged
merged 4 commits into from
Jul 21, 2023

Conversation

idastambuk
Copy link
Contributor

Sets up to use shared credentials file for grafana_assume_role, as agreed, plus adding tests (thanks @fridgepoet for the help!) 馃檹馃徎

@idastambuk idastambuk requested a review from a team as a code owner July 19, 2023 15:06
pkg/awsds/sessions.go Outdated Show resolved Hide resolved
Copy link
Member

@sarahzinger sarahzinger left a comment

Choose a reason for hiding this comment

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

just asking questions for my own knowledge!

pkg/awsds/sessions.go Outdated Show resolved Hide resolved
@@ -61,8 +61,8 @@ func TestNewSession_AssumeRole(t *testing.T) {
settings := AWSDatasourceSettings{
AssumeRoleARN: roleARN,
}
os.Setenv(AllowedAuthProvidersEnvVarKeyName, "default")
os.Setenv(AssumeRoleEnabledEnvVarKeyName, "true")
require.NoError(t, os.Setenv(AllowedAuthProvidersEnvVarKeyName, "default"))
Copy link
Member

Choose a reason for hiding this comment

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

just curious what this does, is it checking that setenv doesn't error out? seems maybe overly cautious no? Or is there an expected error that could happen?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's unlikely an error will happen, but it would be nice to know if it does instead of silently continuing in any case.


assert.Equal(t, "grafanamagic", *p.ExternalID)
return credentials.NewCredentials(p)
}
Copy link
Member

Choose a reason for hiding this comment

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

hey i think i must be missing something obvious but when I read through this test I don't really see where we use newSTSCredentials. It seems like we make a function, but then we never call that function. I see we do this pattern in other tests so I'm assuming I'm missing something? Like does it overwrite something being used in getSession somehow?

Copy link
Member

Choose a reason for hiding this comment

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

Yup it overwrites what's being used here.
The overwriting in the test just happens here and it's cleaned up here.

(For what it's worth: newSTSCredentials is a global variable, it was stubbed, and it effectively hides what GetSession is depending on. We could instead use dependency injection (i.e. The dependency is directly attached to the thing that depends on it. The method receiver could contain the dependency OR the signature of this function could either pass in the dependency as an argument.). In my opinion stubbing has made both the production code and test code confusing to read/understand and not explicit -- (sorry but) I think it's a bit of an anti-pattern... )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to add, @fridgepoet has already taken a look at if/how we could replace the stubs in this branch and we might start replacing the tests soon. But we agreed it's probably not worth it in this PR

Copy link
Member

Choose a reason for hiding this comment

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

(not sure if it's injected in the right places or if things are "proper" and didn't test manually to see if it all works)

@idastambuk idastambuk merged commit edbfbff into temp-credentials Jul 21, 2023
3 checks passed
@idastambuk idastambuk deleted the temp-creds/shared branch July 21, 2023 13:32
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.

None yet

3 participants