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

Add option to exclude S3 #69

Closed
wants to merge 19 commits into from

Conversation

wasabigeek
Copy link

@wasabigeek wasabigeek commented Feb 15, 2020

Fixes #64.

I'm not familiar with Go so this was pretty much winging it. Appreciate some advice on the implementation (passing a param to Fetch doesn’t feel ideal to me), then I'll make the required changes.

@patrobinson patrobinson self-assigned this Feb 17, 2020
@wasabigeek
Copy link
Author

wasabigeek commented Feb 28, 2020

Sorry I realise this doesn't quite work the way I think it does for Push, there are some edge cases if it was synced with S3 and then later an exclude attempt was made >_<

@wasabigeek
Copy link
Author

wasabigeek commented Feb 28, 2020

Made such that the flag is set on the Fetcher struct instead, also added it to the YamlDumper so it should work even if there was a previous S3 pull which has been desynced. Would love to hear your thoughts - I do think it’ll be nice to set a more permanent config (perhaps an environment variable or a special YAML config?) but that could be a separate enhancement.

Copy link
Contributor

@patrobinson patrobinson left a comment

Choose a reason for hiding this comment

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

I've been meaning to have a shot at implementing this myself.
Other than the tests this looks good

@@ -38,6 +39,7 @@ func main() {
pushDir = push.Flag("dir", "The directory to load yaml files from").Default(defaultDir).Short('d').ExistingDir()
)
dryRun = kingpin.Flag("dry-run", "Show what would happen, but don't prompt to do it").Bool()
excludeS3 = kingpin.Flag("exclude-s3", "Exclude S3 policies from pull or push").Bool()
Copy link
Contributor

Choose a reason for hiding this comment

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

Aside from this PR, I'd love there to be a config file we could use to set these per account/repository.

iamy/aws.go Outdated
// Wrapper around getAccount method to make mocking easier
var getAccount = func (a *AwsFetcher) (*Account, error) {
return a.getAccount()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Using Globals to facilitate mocking isn't a very idiomatic way to do this.
How I'd approach it is to create an interface

type AwsFetcherIface interface {
	GetAccount() (*Account, error)
	FetchIAMData() error
	FetchS3Data() error
}

Then instantiate AwsFetcher and pass it into the function being tested. That way we can define our own implementation in the test suite and pass it in to the function.

Copy link
Author

Choose a reason for hiding this comment

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

Got it! Will probably steal your work in #58 - I tried to do it but didn't grok interfaces well and ended up with a very long declaration.

Copy link
Author

@wasabigeek wasabigeek Mar 4, 2020

Choose a reason for hiding this comment

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

Struggling a little - the function under test is a method of AwsFetcher as well (AwsFetcher's Fetch(), which is used by push/pull, will call getAccount(), fetchIamData() and fetchS3Data methods). My limited understanding is that in creating an interface for AwsFetcher, I would also be mocking Fetch, which makes the test meaningless.

Do you have any advice? I'm deliberating:

  • creating interfaces for S3/IAM clients and mocking those before passing into Fetcher - it's quite tedious though, there's potentially a lot to mock when all I want to do is check if fetchS3Data / fetchIamData is being called
  • creating a separate type to hold the 3 methods and embedding that into Fetcher (something like this), but it feels a little contrived

EDIT: decided I'd try breaking apart Fetcher. A bit tricky due to the lack of tests, I did try running manually, seemed to work.

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 breaking it up is a great idea, but also would like @mtibben to weigh in.

Copy link
Author

Choose a reason for hiding this comment

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

👌

@wasabigeek
Copy link
Author

@mtibben hope I'm not being a bother, let me know if I can help this along (e.g. adding more tests). I've stopped short of moving the split up Fetchers to their own files

Copy link
Contributor

@patrobinson patrobinson left a comment

Choose a reason for hiding this comment

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

+1

@wasabigeek wasabigeek changed the title Spike to try excluding S3 Add option to exclude S3 Jun 18, 2020
@wasabigeek
Copy link
Author

Thanks @patrobinson! I don’t have permissions to merge this, is this still pending something?

@patrobinson
Copy link
Contributor

I want to do some local testing and cut a release, so it's pending me for now.

@wasabigeek
Copy link
Author

@patrobinson is this still something you'd like to include? I can try to clean it up and resolve conflicts if so :)

@patrobinson
Copy link
Contributor

@wasabigeek sorry for taking so long to get back to you. If you could resolve the conflicts I will take a look at this.

@vquangna2
Copy link

are this feature ready?

@wasabigeek
Copy link
Author

@mtibben @patrobinson am trying to set aside some time to look at this again, wanted to get your thoughts on implementation.

In this PR I attempted to split some of the AwsFetcher logic into AwsAccountFetcher, AwsIamFetcher, AwsS3Fetcher, mostly so they could be mocked in tests. Now that #72 is merged, I'm also thinking of extracting the isSkippableManagedResource logic into an AwsSkippableResourceChecker, which will be injected into the previously mentioned classes. How does that sound?

Also, were there any concerns previously that prevented this from being merged in?

@wasabigeek wasabigeek closed this Oct 18, 2021
@wasabigeek wasabigeek deleted the feat/exclude-s3 branch October 18, 2021 03:41
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.

provide option to make s3 policies optional
3 participants