Skip to content

Commit

Permalink
fix: put cli first, before env, updated options
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmmatos committed Jul 18, 2023
1 parent 650c3e6 commit 8801084
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions samples/incidents/crowd_score.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
options_parser.parse!

# Get API credentials from environment variables, cli options, or prompt for input
falcon_client_id = ENV["FALCON_CLIENT_ID"] || options_parser.options[:client_id] || Prompt.ask("Missing FALCON_CLIENT_ID environment variable. " \
falcon_client_id = options_parser.options[:client_id] || ENV["FALCON_CLIENT_ID"] || Prompt.ask("Missing FALCON_CLIENT_ID environment variable. " \
"Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform\n" \
"Falcon Client ID: ")

falcon_client_secret = ENV["FALCON_CLIENT_SECRET"] || options_parser.options[:client_secret] || Prompt.ask("Missing FALCON_CLIENT_SECRET environment variable. " \
falcon_client_secret = options_parser.options[:client_secret] || ENV["FALCON_CLIENT_SECRET"] || Prompt.ask("Missing FALCON_CLIENT_SECRET environment variable. " \
"Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform\n" \
"Falcon Client Secret: ", true)

Falcon.configure do |config|
# Grab the environment variable, otherwise, prompt for input
config.client_id = falcon_client_id
config.client_secret = falcon_client_secret
config.member_cid = options_parser.options[:member_cid] if options_parser.options[:member_cid]
config.cloud = ENV["FALCON_CLOUD"] || options_parser.options[:cloud]
end

Expand Down
8 changes: 2 additions & 6 deletions samples/oauth2/get_access_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@

# Sets up the command line options
# Use -h or --help to see the options
# In this case, we need to add a new option for :member_cid
options_parser = Options::BaseOptions.new
options_parser.add_option("-m", "--member-cid MEMBER_CID", "The member CID for the OAuth2 access token") do |member_cid|
options_parser.options[:member_cid] = member_cid
end
options_parser.parse!

# Get API credentials from environment variables, cli options, or prompt for input
falcon_client_id = ENV["FALCON_CLIENT_ID"] || options_parser.options[:client_id] || Prompt.ask("Missing FALCON_CLIENT_ID environment variable. " \
falcon_client_id = options_parser.options[:client_id] || ENV["FALCON_CLIENT_ID"] || Prompt.ask("Missing FALCON_CLIENT_ID environment variable. " \
"Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform\n" \
"Falcon Client ID: ")

falcon_client_secret = ENV["FALCON_CLIENT_SECRET"] || options_parser.options[:client_secret] || Prompt.ask("Missing FALCON_CLIENT_SECRET environment variable. " \
falcon_client_secret = options_parser.options[:client_secret] || ENV["FALCON_CLIENT_SECRET"] || Prompt.ask("Missing FALCON_CLIENT_SECRET environment variable. " \
"Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform\n" \
"Falcon Client Secret: ", true)

Expand Down
5 changes: 3 additions & 2 deletions samples/sensor_download/get_ccid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
options_parser.parse!

# Get API credentials from environment variables, cli options, or prompt for input
falcon_client_id = ENV["FALCON_CLIENT_ID"] || options_parser.options[:client_id] || Prompt.ask("Missing FALCON_CLIENT_ID environment variable. " \
falcon_client_id = options_parser.options[:client_id] || ENV["FALCON_CLIENT_ID"] || Prompt.ask("Missing FALCON_CLIENT_ID environment variable. " \
"Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform\n" \
"Falcon Client ID: ")

falcon_client_secret = ENV["FALCON_CLIENT_SECRET"] || options_parser.options[:client_secret] || Prompt.ask("Missing FALCON_CLIENT_SECRET environment variable. " \
falcon_client_secret = options_parser.options[:client_secret] || ENV["FALCON_CLIENT_SECRET"] || Prompt.ask("Missing FALCON_CLIENT_SECRET environment variable. " \
"Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform\n" \
"Falcon Client Secret: ", true)

Falcon.configure do |config|
# Grab the environment variable, otherwise, prompt for input
config.client_id = falcon_client_id
config.client_secret = falcon_client_secret
config.member_cid = options_parser.options[:member_cid] if options_parser.options[:member_cid]
config.cloud = ENV["FALCON_CLOUD"] || options_parser.options[:cloud]
end

Expand Down
8 changes: 6 additions & 2 deletions samples/shared/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def initialize
@options = { cloud: 'us-1' }

@opts = OptionParser.new do |opts|
opts.banner = "Usage: #{@base_file} -i FALCON_CLIENT_ID -s FALCON_CLIENT_SECRET [options]"
opts.banner = "Usage: #{@base_file} -k FALCON_CLIENT_ID -s FALCON_CLIENT_SECRET [options]"

opts.summary_width = 40
opts.separator ""

opts.on("-i", "--client-id FALCON_CLIENT_ID", "OAuth2 API Client ID.") do |client_id|
opts.on("-k", "--client-id FALCON_CLIENT_ID", "OAuth2 API Client ID.") do |client_id|
@options[:client_id] = client_id
end

Expand All @@ -29,6 +29,10 @@ def initialize
@options[:cloud] = cloud
end

opts.on("-m", "--member-cid MEMBER_CID", "Member CID for MSSP") do |member_cid|
options_parser.options[:member_cid] = member_cid
end

opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
Expand Down

0 comments on commit 8801084

Please sign in to comment.