rogerluan / arkana

Use dotenv files for Android and iOS projects.
BSD 2-Clause "Simplified" License
379 stars 18 forks source link

Failed to load command: arkana - Undefined method capitalize_first_letter #57

Open JeanBaptisteBolh opened 5 months ago

JeanBaptisteBolh commented 5 months ago

I added arkana to my gem file: gem 'arkana'

And installed with bundle install

It appears to be a success. However, when I try to run "bundle exec arkana" in my command line, I get the following error:

bundler: failed to load command: arkana (/Users/jean-baptistebolh/.rbenv/versions/2.7.3/bin/arkana)
NoMethodError: undefined method `capitalize_first_letter' for #<Array:0x0000000155b08f00>
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/models/config.rb:47:in `each'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/models/config.rb:47:in `map'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/models/config.rb:47:in `initialize'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/config_parser.rb:14:in `new'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/config_parser.rb:14:in `parse'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana.rb:16:in `run'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/bin/arkana:8:in `<top (required)>'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/bin/arkana:23:in `load'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/bin/arkana:23:in `<top (required)>'
alexspurlock25 commented 5 months ago

@JeanBaptisteBolh have you initialized your .arkana.yml file for Arkana? There isn't really an onboarding process. But I remember getting this error as well. Somewhere in the documentation, you will find a template for this file.

JeanBaptisteBolh commented 5 months ago

@alexspurlock25 I added the .arkana.yml file at my project root. Do you see anything wrong with it?

environments:
  debug:
    OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"
  release:
    OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"

secrets:
  - key: OPEN_API_KEY
    env_var: API_KEY_ENV

To me it looks like for some reason arkana can't find the definition for that capitalize_first_letter function. I saw it defined for String in the source code though: https://github.com/rogerluan/arkana/blob/main/lib/arkana/helpers/string.rb

alexspurlock25 commented 5 months ago

@JeanBaptisteBolh That looks right (I THINK). However, for me, my env vars are in a file called .env. I believe that this is a requirement - to have this file that has your keys, urls, etc.

This is mine:

the .arkana.yml file:

import_name: 'ArkanaKeys' # Optional. Name of the framework to be imported. Defaults to ArkanaKeys.
namespace: 'Keys' # Optional. Namespace used to access the secrets in the codebase. Defaults to ArkanaKeys.
result_path: 'dependencies' # Optional. Destination path of the generated code, related to the path of this config file. Defaults to ArkanaKeys.
flavors: # Optional. Flavors are keywords added as a prefix to every secret when reading them from environment variables. This is useful for instance in white-label projects. Check the "Usage" section of the README for more information.
  - FrostedFlakes
  - FrootLoops
swift_declaration_strategy: let # Optional. One of: lazy var, var, let. Defaults to let.
should_generate_unit_tests: true # Optional. One of: true, false. Defaults to true.
package_manager: spm # Optional. This setting defines which type of dependency management you're going to use to integrate Arkana into your project. One of: spm, cocoapods. If you use both in your project, use cocoapods here. Defaults to spm.
environments: # Optional. List of environments that will be used to generate secret keys when you have keys that are different between environments (e.g. debug/staging/prod). Defaults to empty.
  - Debug -- I DID NOT CHANGE THIS, so idk anything about it - sorry
  - Release -- I DID NOT CHANGE THIS, so idk anything about it - sorry
global_secrets: # Optional. List of secrets that are the same regardless of which environment is being built. Defaults to empty.
  - SECRET_URL
  - SECRET_KEY

The .env file:

SECRET_URL=abc123
SECRET_KEY=abc123

Notice that the keys are the same name in both files. ALSO: this is where the capitalization error happens. Arkana tries to capitalize the vars in the .env file and if they don't exist, BOOM.

alexspurlock25 commented 5 months ago

I think what you have to do is:

environments:
  debug:
    DEBUG_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"
  release:
    PROD_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"

in your .env file:

DEBUG_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"
PROD_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"
JeanBaptisteBolh commented 5 months ago

Haven't yet been able to get this to work unfortunately...

.arkana.yml

environments:
  debug:
    DEBUG_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"
  release:
    PROD_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"

.env

DEBUG_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"
PROD_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"

Result after running bundle exec arkana (I also tried with the -e option to point to the .env file)

bundler: failed to load command: arkana (/Users/jean-baptistebolh/.rbenv/versions/2.7.3/bin/arkana)
NoMethodError: undefined method `capitalize_first_letter' for #<Array:0x00000001422ca310>
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/models/config.rb:47:in `each'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/models/config.rb:47:in `map'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/models/config.rb:47:in `initialize'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/config_parser.rb:14:in `new'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana/config_parser.rb:14:in `parse'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/lib/arkana.rb:16:in `run'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/arkana-2.0.0/bin/arkana:8:in `<top (required)>'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/bin/arkana:23:in `load'
  /Users/jean-baptistebolh/.rbenv/versions/2.7.3/bin/arkana:23:in `<top (required)>'
alexspurlock25 commented 5 months ago

@JeanBaptisteBolh Sorry I am not much of a help.

In your .yml file, you have a value set for your var like so

DEBUG_OPEN_API_KEY: "abcdefghijklmnopqrstuv123456789"

remove the value like so:

DEBUG_OPEN_API_KEY

Also, remove the double quotes from keys.

Arkana looks for that var and its value in your .env file. This is because we want to remove .env from source control and keep the .yml file in source control.

alexspurlock25 commented 5 months ago

I also noticed that your local ruby version is set to be below 3. I believe that Arkana needs ruby to be above version 3

rogerluan commented 5 months ago

Hey everyone! Sorry I'm late for the party πŸ˜„

I really appreciate your input here @alexspurlock25, I love to see this community engagement ❀️

@JeanBaptisteBolh it seems like you're struggling with setting Arkana up for the first time. I suggest reading the Usage section of the README: https://github.com/rogerluan/arkana?tab=readme-ov-file#usage β€” it points to a template .yml file you could be using as your starting point for your .arkana.yml file 😊

I don't know where/how you came up with the syntax for that yaml file you wrote, but it should be like this instead:

# here don't forget to set all the other settings related to the project, e.g. spm vs cocoapods, swift vs kotlin, etc…

environments: # Optional. List of environments that will be used to generate secret keys when you have keys that are different between environments (e.g. debug/staging/prod). Defaults to empty.
  - Debug
  - Release
environment_secrets: # Optional. List of secrets that are the same regardless of which environment is being built. Defaults to empty.
  - OpenAPIKey

I hope this helps! Let me know if you still have issues πŸ€—

rogerluan commented 5 months ago

I also noticed that your local ruby version is set to be below 3. I believe that Arkana needs ruby to be above version 3

Despite being a nice-to-have, Ruby 3 is not enforced at the moment! Arkana currently supports Ruby 2.7 and up, despite being a version long deprecated, so I really recommend upgrading to Ruby 3+ sooner rather than later :)

rogerluan commented 5 months ago

@alexspurlock25

There isn't really an onboarding process.

We have [what I believed to be] an extensive documentation in the project's README, would you be able to point out areas we could improve it? And/or perhaps @JeanBaptisteBolh could contribute too with some fresh ideas? πŸ˜ƒ I'd love to hear them all!

alexspurlock25 commented 5 months ago

@alexspurlock25

There isn't really an onboarding process.

We have [what I believed to be] an extensive documentation in the project's README, would you be able to point out areas we could improve it? And/or perhaps @JeanBaptisteBolh could contribute too with some fresh ideas? πŸ˜ƒ I'd love to hear them all!

Right, so when I started using Arkana - works great by the way - I wasn't told that I HAD to create two files. Maybe I missed that somewhere, but I did get lost initially. I hope this helps someway.

I love the library by the way.

rogerluan commented 5 months ago

Thank you so much for the feedback @alexspurlock25 ! I'll make sure the documentation is more clear πŸ™‡

I'm glad to hear you enjoy using Arkana! ❀️

rogerluan commented 5 months ago

@JeanBaptisteBolh please let me know if the info above resolves the issues you were seeing :) Looking forward to hearing back from you! πŸ™‡

JeanBaptisteBolh commented 5 months ago

Hi @rogerluan thanks for checking in! Apologies for not getting back quickly, been a busy day at work...

I think I figured it out since my command just ran successfully so first of all, THANK YOU!

For the README improvements, I'll try to spell out instructions as I would tell them to someone else after going through this experience. I'll admit this may be more verbose than what you will end up with, but here we go.

Example: Lets image a situation where you have the following for an API called "SomeAPI": production key: "ABCDEFG1234" debug key: "XYZLMNO1234"

  1. We may want to access these from two variables within our app called "SomeAPIDebug" and "SomeAPIRelease". We will define a naming scheme (in other words our 'environments') in a yaml file called .arkana.yml at the root of our project. We will put our actual api keys in a .env file, also at the root of our project. In our case the files will look like this: .arkana.yml
    
    environments:
    - Debug
    - Release

environment_secrets:

.env

OpenAPIKeyRelease: "ABCDEFG1234"
OpenAPIKeyDebug: "XYZLMNO1234"
  1. Notice how arkana needs you to name the variables in .env as the environment_secret followed by the environment name.

  2. If using bundle run bundle exec arkana


That's how it works in my brain... let me know if I'm not thinking about this correctly and thank you again for the help :)

rogerluan commented 3 months ago

@JeanBaptisteBolh what do you think of the new section in the README?

image

The majority of it came from a contribution added in this PR #61, but I just incorporated some of your feedback on it as well, from your message above πŸ™‡

I opted not to use a prose style (like you suggested above), keeping a procedural tone instead, but the content should be easier to digest now. I hope that makes it clearer!