Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Add a general method for retrieving profile configuration values #111

Merged
merged 1 commit into from
Jan 22, 2019

Conversation

lsowen
Copy link
Contributor

@lsowen lsowen commented Jan 17, 2019

No description provided.

@lsowen
Copy link
Contributor Author

lsowen commented Jan 17, 2019

@nickatsegment A separate PR implementing what I was talking about in #108 (comment)

If this is acceptable (and merged) I'll update #108 to use this.

@nickatsegment
Copy link
Contributor

nickatsegment commented Jan 18, 2019

Cool. I think this introduces some different behaviour? For instance, previously you could only potentially get the value from the profile, its parent, or the root okta. Now ancestry could be arbitrarily long, right?

(BTW, I think arbitrary ancestry chains means that one could make loops, which this code would just spin on.)

Can you please point out any such changes? Generally I have a bit of a distaste for refactoring and changing behaviour in the same PR/commit.

lib/config.go Outdated
@@ -65,3 +65,27 @@ func sourceProfile(p string, from profiles) string {
}
return p
}

func GetValueFromProfile(profile string, from profiles, config_key string) (string, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you feel about making this a method on the profiles type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nickatsegment the one complication is that profiles is not an exported type, which I think makes https://github.com/segmentio/aws-okta/pull/111/files#diff-aed93a53379775027b6616ae133e3815R57 not work? I think it is cleaner to put it on profiles, but should I export the profiles type?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think exporting Profiles is reasonable. It'd require more changes though. If you think it's not a lot more work/changes, I'm all for it; seems more proper to me.

If you decide to go that route, I would say you should shorten the name of this method. Get(profile, key string) ... is probably descriptive enough.

Copy link
Contributor

@nickatsegment nickatsegment left a comment

Choose a reason for hiding this comment

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

A few small things. Want a list of behaviour changes.

lib/config_test.go Outdated Show resolved Hide resolved
lib/provider.go Outdated Show resolved Hide resolved
lib/provider.go Outdated Show resolved Hide resolved
lib/provider.go Outdated Show resolved Hide resolved
lib/provider.go Show resolved Hide resolved
@lsowen
Copy link
Contributor Author

lsowen commented Jan 18, 2019

@nickatsegment Where/how would you like the changed behaviour documented?

Also, I can make it so that the general helper function doesn't support arbitrarily long heritage (ie implements the previous "current, parent, or okta" logic).

@nickatsegment
Copy link
Contributor

Documenting new behaviour: I was thinking just in the PR to start.

But I'd say just keep the behaviour the same. I think you're anticipating needs that no user has shown. We can cross that bridge later.

@lsowen
Copy link
Contributor Author

lsowen commented Jan 18, 2019

@nickatsegment it no longer searches recursively, so implements the previous behaviour. Additionally, changed the function name to GetValue() (Get seemed like it should return a profile, so I opted for a slightly more descriptive name).

lib/config.go Outdated
if conf, ok := from[p]; ok {
if source := conf["source_profile"]; source != "" {
return source
}
}
return p
}

func (p Profiles) GetValue(profile string, config_key string) (string, string, error) {
for i := 0; i < 2; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this would be shorter and clearer if you unrolled the loop.

lib/config.go Outdated
return config_value, profile, nil
}

return "", "", fmt.Errorf("Could not find %s in %s, parent profiles, or okta", config_key, profile)
Copy link
Contributor

Choose a reason for hiding this comment

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

For parent profiles, it should just be source profile maybe?

Copy link
Contributor

@nickatsegment nickatsegment left a comment

Choose a reason for hiding this comment

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

Small style thing. But good enough!

@lsowen
Copy link
Contributor Author

lsowen commented Jan 21, 2019

I'll address the last few items today.

@lsowen lsowen force-pushed the feature/profile-config branch 2 times, most recently from ea9a898 to 5b11c95 Compare January 21, 2019 22:11
@lsowen
Copy link
Contributor Author

lsowen commented Jan 21, 2019

@nickatsegment This is ready for final review and merging.

Copy link
Contributor

@nickatsegment nickatsegment left a comment

Choose a reason for hiding this comment

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

🎉 Thanks so much.

@nickatsegment nickatsegment merged commit a0b71df into segmentio:master Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants