class Fastlane::Actions::EncryptAppVarsAction

Public Class Methods

app_key_for(namespace) click to toggle source

Returns the app key for cryptex. optionally namespaced

# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 109
def self.app_key_for(namespace)
  default_app_key = Helper::ReactNativeReleaseHelper::APP_CRYPTEX_KEY 
  return default_app_key if namespace.strip.empty?

  "#{namespace}_#{default_app_key}"
end
authors() click to toggle source
# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 93
def self.authors
  # So no one will ever forget your contribution to fastlane :) You are awesome btw!
  ["cball", "isaiahgrey93", "cmejet"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 58
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :namespace,
                                 env_name: "FL_ENCRYPT_APP_VARS_NAMESPACE", # The name of the environment variable
                                 description: "What namespace should we use? (alpha, beta, release, ENTER = root)", # a short description of this parameter
                                 type: String,
                                 verify_block: lambda do |value|
                                  unless Helper::ReactNativeReleaseHelper::VALID_NAMESPACES.include?(value)
                                    UI.user_error!("Invalid namespace #{value}. Valid targets are #{Helper::ReactNativeReleaseHelper::VALID_NAMESPACES.join(', ')}") 
                                    next
                                  end
                                end),
    FastlaneCore::ConfigItem.new(key: :env_path,
                                 env_name: "FL_ENCRYPT_APP_VARS_ENV_PATH", # The name of the environment variable
                                 description: "A path to an ENV file that contains app related ENV vars", # a short description of this parameter
                                 type: String,
                                 optional: true),
     FastlaneCore::ConfigItem.new(key: :skip_confirmation,
                                 env_name: "FL_ENCRYPT_APP_VARS_SKIP_CONFIRMATION", # The name of the environment variable
                                 description: "Allows commands to be run from within CLI and skip the UI.message confirmation dialog", # a short description of this parameter
                                 type: Boolean,
                                 short_option:'s',
                                 default_value: false,
                                 optional: true),
  ]
end
default_env_path() click to toggle source
# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 116
def self.default_env_path
  Helper::ReactNativeReleaseHelper::APP_ENV_PATH
end
description() click to toggle source

@!group Documentation

# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 49
def self.description
  "Encrypts app env vars and stores them in the context repo."
end
details() click to toggle source
# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 53
def self.details
  # Optional:
  # this is your chance to provide a more detailed description of this action
end
env_path_for(namespace) click to toggle source

Returns a path for an env var. optionally namespaced

# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 103
def self.env_path_for(namespace)
  return default_env_path if namespace.strip.empty?
  "#{default_env_path}.#{namespace}"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 98
def self.is_supported?(platform)
  [:ios, :android].include?(platform)
end
return_value() click to toggle source
# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 85
def self.return_value
  # If your method provides a return value, you can describe here what it does
end
run(params) click to toggle source
# File lib/fastlane/plugin/react_native_release/actions/encrypt_app_vars.rb, line 7
def self.run(params)
  namespace = params[:namespace]
  cryptex_app_key = app_key_for(namespace)
  env_path = params[:env_path] || env_path_for(namespace)
  skip_confirmation= params[:skip_confirmation]

 
  if !File.exists?(env_path)
    UI.user_error!("#{env_path} not found!")
  end

  if(!skip_confirmation)
    if !UI.confirm("This will save values from #{env_path} to the #{cryptex_app_key} namespace in the encrypted context repo. Proceed?")
      UI.abort_with_message!("Stepping away...")
    end
  end

  app_vars = Dotenv.parse(env_path)
  existing_app_vars = {}

  begin
    existing_app_vars = other_action.cryptex(
      type: 'export_env',
      key: cryptex_app_key,
    )
  rescue => ex
    # If key doesn't exist cryptex will error
  end

  other_action.cryptex(
    type: "import_env",
    key: cryptex_app_key,
    hash: existing_app_vars.merge(app_vars)
  )

  UI.success('Encrypted app ENV vars')
end