12
12
from kibana import Kibana , RuleResource
13
13
14
14
from .main import root
15
- from .misc import set_param_values
15
+ from .misc import getdefault
16
16
from .utils import normalize_timing_and_sort , unix_time_to_formatted , get_path
17
17
from .rule_loader import get_rule , rta_mappings , load_rule_files , load_rules
18
18
@@ -179,10 +179,10 @@ def run(self, agent_hostname, indexes, verbose=True, **match):
179
179
180
180
@es_group .command ('collect-events' )
181
181
@click .argument ('agent-hostname' )
182
- @click .option ('--elasticsearch-url' , '-u' , callback = set_param_values , expose_value = True )
183
- @click .option ('--cloud-id' , callback = set_param_values , expose_value = True )
184
- @click .option ('--user' , '-u' , callback = set_param_values , expose_value = True , hide_input = False )
185
- @click .option ('--password' , '-p' , callback = set_param_values , expose_value = True , hide_input = True )
182
+ @click .option ('--elasticsearch-url' , '-u' , default = getdefault ( "elasticsearch_url" ) )
183
+ @click .option ('--cloud-id' , default = getdefault ( "cloud_id" ) )
184
+ @click .option ('--user' , '-u' , default = getdefault ( "user" ) )
185
+ @click .option ('--password' , '-p' , default = getdefault ( "password" ) )
186
186
@click .option ('--index' , '-i' , multiple = True , help = 'Index(es) to search against (default: all indexes)' )
187
187
@click .option ('--agent-type' , '-a' , help = 'Restrict results to a source type (agent.type) ex: auditbeat' )
188
188
@click .option ('--rta-name' , '-r' , help = 'Name of RTA in order to save events directly to unit tests data directory' )
@@ -193,6 +193,13 @@ def collect_events(agent_hostname, elasticsearch_url, cloud_id, user, password,
193
193
"""Collect events from Elasticsearch."""
194
194
match = {'agent.type' : agent_type } if agent_type else {}
195
195
196
+ if not cloud_id or elasticsearch_url :
197
+ raise click .ClickException ("Missing required --cloud-id or --elasticsearch-url" )
198
+
199
+ # don't prompt for these until there's a cloud id or elasticsearch URL
200
+ user = user or click .prompt ("user" )
201
+ password = password or click .prompt ("password" , hide_input = True )
202
+
196
203
try :
197
204
client = get_es_client (elasticsearch_url = elasticsearch_url , use_ssl = True , cloud_id = cloud_id , user = user ,
198
205
password = password )
@@ -229,16 +236,23 @@ def normalize_file(events_file):
229
236
230
237
@root .command ("kibana-upload" )
231
238
@click .argument ("toml-files" , nargs = - 1 , required = True )
232
- @click .option ('--kibana-url' , '-u' , callback = set_param_values , expose_value = True )
233
- @click .option ('--cloud-id' , callback = set_param_values , expose_value = True )
234
- @click .option ('--user' , '-u' , callback = set_param_values , expose_value = True , hide_input = False )
235
- @click .option ('--password' , '-p' , callback = set_param_values , expose_value = True , hide_input = True )
239
+ @click .option ('--kibana-url' , '-u' , default = getdefault ( "kibana_url" ) )
240
+ @click .option ('--cloud-id' , default = getdefault ( "cloud_id" ) )
241
+ @click .option ('--user' , '-u' , default = getdefault ( "user" ) )
242
+ @click .option ('--password' , '-p' , default = getdefault ( "password" ) )
236
243
def kibana_upload (toml_files , kibana_url , cloud_id , user , password ):
237
244
"""Upload a list of rule .toml files to Kibana."""
238
245
from uuid import uuid4
239
246
from .packaging import manage_versions
240
247
from .schemas import downgrade
241
248
249
+ if not cloud_id or kibana_url :
250
+ raise click .ClickException ("Missing required --cloud-id or --kibana-url" )
251
+
252
+ # don't prompt for these until there's a cloud id or kibana URL
253
+ user = user or click .prompt ("user" )
254
+ password = password or click .prompt ("password" , hide_input = True )
255
+
242
256
with Kibana (cloud_id = cloud_id , url = kibana_url ) as kibana :
243
257
kibana .login (user , password )
244
258
0 commit comments