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 new option should_infer_types to optionally not infer the type of the secret #72

Conversation

cepages
Copy link
Contributor

@cepages cepages commented Jul 3, 2024

Description

This PR allows to set an option to not use inference to find out the secret type. If inference_secret_types = false the type will be always String.

Discussion

@rogerluan ( CarlosNano = cepages ) I've created this initial PR, I'm not a ruby developer but this seem to be a plausible way of doing it.

Resources

Resolves #70

Copy link
Owner

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

Hi @cepages 👋

Thank you so much for this! You definitely went in the right direction — congrats on your first open source PR in Ruby! 😁

I just made some minor nitpick comments about the interface of this new config with the developers, as well as keeping the codebase consistent, I hope you don't mind!

Also, you should check the failing unit and integration tests, as the changes you made are okay in isolation but the tests will need to be updated 🙏 to run the tests, you can run bundle exec rspec

Thanks once again and well done! 🙌

template.yml Outdated Show resolved Hide resolved
lib/arkana/models/config.rb Outdated Show resolved Hide resolved
lib/arkana/models/type.rb Outdated Show resolved Hide resolved
@rogerluan rogerluan changed the title Added new option to not infere the type of the secret and leave it as… Add new option should_infer_types to optionally not infer the type of the secret Jul 3, 2024
Co-authored-by: Roger Oba <[email protected]>
@cepages
Copy link
Contributor Author

cepages commented Jul 3, 2024

bundle exec rspec nice thanks. That's what I was searching. I will do the changes and run the tests

rogerluan
rogerluan previously approved these changes Jul 12, 2024
Copy link
Owner

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

👏 Great work @cepages !! Thank you for this contribution!

(Just pending fixing the unit tests 😊)

@cepages
Copy link
Contributor Author

cepages commented Jul 28, 2024

@rogerluan I keep changing the test files and they keep failing.

For example: templates_arguments_spec.rb, I add:

      expect(subject.instance_variable_get(:@should_infer_types)).to eq config.should_infer_types

in:

  describe ".new" do

also added should_infer_types: true in arakan-fixture.yml

Could you point me how to fix that one and maybe I can replicate in the rest of them :/

@rogerluan
Copy link
Owner

rogerluan commented Jul 31, 2024

@cepages you have to read the reason why the specs are failing, not only which specs are failing. For example:

image

This test is failing because encode! is being called without the argument should_infer_types. To fix this, search where encode! is being used across the project and make sure all of its callers are passing this new argument you added to this function :)

Then repeat the process: read the error for each failing spec and fix them individually until they all pass 🤗

@cepages
Copy link
Contributor Author

cepages commented Aug 3, 2024

@rogerluan I've fixed the test locally and it seems the Swift test are failing installing dependencies?
An error occurred while installing strscan (3.1.0), and Bundler cannot continue.

Btw thanks for the tip to fix the tests, I was looking it wrong :)

@cepages cepages force-pushed the Keys_in_different_environment_does_not_conform_the_same_protocol_for_Debug_and_Release branch from 64e5cd8 to 60040c6 Compare August 3, 2024 20:41
@cepages cepages force-pushed the Keys_in_different_environment_does_not_conform_the_same_protocol_for_Debug_and_Release branch from 60040c6 to 33b9ffd Compare August 3, 2024 20:47
@rogerluan
Copy link
Owner

@cepages I confirmed that this bug is present in main (https://github.com/rogerluan/arkana/actions/runs/10235693630/job/28316834697), thus it's unrelated to this PR, and it's likely an issue with GitHub Actions. I'll investigate this later, dw :)

Meanwhile, congrats on fixing the existing tests! 🎉

Would you mind adding new tests, asserting that the new behavior you're adding is behaving as expected? That means it should be inferring the types when passing true, and forcing the usage of String (the default type) when passing false, for both generators we have (Swift, Kotlin) 😊

Thanks again! 🙌

@cepages
Copy link
Contributor Author

cepages commented Aug 4, 2024 via email

@rogerluan
Copy link
Owner

Hmm good point, I analyzed a bit further and probably there's not enough value in adding a unit test for this, but maybe a full integration test would be better, e.g. to make sure the final output produces code that compile and works as expected. What I'd probably do is duplicate the Swift and Kotlin tests in the Rakefile, using an arkana config file that is identical but with should_inter_types set to false, keeping everything else identical. That should guarantee that everything is working well for both generators 🙇

@cepages
Copy link
Contributor Author

cepages commented Aug 11, 2024

Done it, I hope I've done it in the way you mean in your previous comment. The swift test seems to persist but kotlin seems to pass ok.

It seems a bit of duplication of the files though.

Which leads me to another idea. It would be very cool if arkana in the command line, allows you to override any option from the config file, so we could do something like:

ARKANA_RUNNING_CI_INTEGRATION_TESTS=true arkana --config-filepath #{config_file} --dotenv-filepath #{dotenv_file} --include-environments dev,staging --should_inter_types false

Which would ignore the option for should_inter_types in the config file, forced to false. It would allows us to test any config option much easily.

Just an idea :)

Copy link
Owner

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

Just a couple more minor changes @cepages! 🤗

Your idea about overriding the config from the CLI is great!! I really think we should have that. If you'd like to take a stab at implementing that (probably wiser in a separate PR), I'd be happy to review it! I think it'd indeed be great to allow further customization and remove duplicated fixtures in this project 😅

Thanks again!

Rakefile Outdated Show resolved Hide resolved
spec/fixtures/kotlin-tests_with_no_infer_types.yml Outdated Show resolved Hide resolved
Copy link
Owner

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

I ran the rake test_swift locally and it runs just fine 💪 I think this PR is good to go! 🚀

Congrats @cepages on your first contribution being merged! 🤩

@rogerluan rogerluan merged commit 3a052ed into rogerluan:main Aug 14, 2024
13 of 14 checks passed
@cepages
Copy link
Contributor Author

cepages commented Aug 14, 2024

Nice!! 🥳

Thanks a lot for your help @rogerluan, I couldn't have done it without you 😄

I will open a MR for the other idea.

Thanks!

@rogerluan
Copy link
Owner

Glad I could help!

Awesome! 🤩 let me know if you need anything 🤗

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.

Keys in different environment doesn't conform the same protocol for Debug and Release
3 participants