4
4
user which child CID to authenticate against.
5
5
"""
6
6
7
- import os
8
-
9
7
from typing import Dict , Optional
10
8
9
+ import click
11
10
import keyring
12
11
13
12
from caracara import Client
@@ -94,15 +93,17 @@ def dump_config(self) -> Dict[str, object]:
94
93
keyring.
95
94
"""
96
95
config : Dict [str , object ] = {}
97
- config ["client_id" ]: str = self .client_id
98
- config ["cloud_name" ]: str = self .cloud_name
99
- config ["ssl_verify" ]: bool = self .ssl_verify
100
- config ["proxy" ]: Dict [ str , str ] = self .proxy
96
+ config ["client_id" ] = self .client_id
97
+ config ["cloud_name" ] = self .cloud_name
98
+ config ["ssl_verify" ] = self .ssl_verify
99
+ config ["proxy" ] = self .proxy
101
100
102
101
return config
103
102
104
- def authenticate (self ) -> Client :
103
+ def authenticate (self , ctx : click . Context ) -> Client :
105
104
"""Log the Toolkit into Falcon using the settings and keys configured at instance setup."""
105
+ chosen_cid_str = ctx .obj ["cid" ]
106
+
106
107
parent_client = Client (
107
108
client_id = self .client_id ,
108
109
client_secret = self .client_secret ,
@@ -111,18 +112,39 @@ def authenticate(self) -> Client:
111
112
proxy = self .proxy ,
112
113
)
113
114
child_cids = parent_client .flight_control .get_child_cids ()
114
- chosen_cid_str = os .environ .get ("FALCON_MSSP_CHILD_CID" )
115
- if chosen_cid_str and chosen_cid_str .lower () in child_cids :
116
- chosen_cid = parent_client .flight_control .get_child_cid_data (cids = [chosen_cid_str ])[
117
- chosen_cid_str
118
- ]
119
- else :
120
- child_cids_data = parent_client .flight_control .get_child_cid_data (cids = child_cids )
121
- chosen_cid_str = choose_cid (cids = child_cids_data , prompt_text = "MSSP Child CID Search" )
122
- chosen_cid = child_cids_data [chosen_cid_str ]
123
-
124
- chosen_cid_name = chosen_cid ["name" ]
125
- print (f"Connecting to { chosen_cid_name } " )
115
+
116
+ if chosen_cid_str and chosen_cid_str in child_cids :
117
+ click .echo (
118
+ click .style ("Valid member CID " , fg = "blue" )
119
+ + click .style (chosen_cid_str , fg = "blue" , bold = True )
120
+ + click .style (" provided. Skipping CID selection." , fg = "blue" )
121
+ )
122
+ elif chosen_cid_str :
123
+ click .echo (click .style ("An invalid CID was provided at the command line." , fg = "red" ))
124
+ click .echo ("Please search for an alternative CID:" )
125
+ # Blank out a bad value
126
+ chosen_cid_str = None
127
+
128
+ if not chosen_cid_str :
129
+ if chosen_cid_str and chosen_cid_str .lower () in child_cids :
130
+ chosen_cid = parent_client .flight_control .get_child_cid_data (
131
+ cids = [chosen_cid_str ],
132
+ )[chosen_cid_str ]
133
+ else :
134
+ child_cids_data = parent_client .flight_control .get_child_cid_data (cids = child_cids )
135
+ if not child_cids_data :
136
+ raise RuntimeError (
137
+ "No child CIDs accessible. Please check your API credentials."
138
+ )
139
+
140
+ chosen_cid_str = choose_cid (
141
+ cids = child_cids_data ,
142
+ prompt_text = "MSSP Child CID Search" ,
143
+ )
144
+ chosen_cid = child_cids_data [chosen_cid_str ]
145
+
146
+ chosen_cid_name = chosen_cid ["name" ]
147
+ print (f"Connecting to { chosen_cid_name } " )
126
148
127
149
client = Client (
128
150
client_id = self .client_id ,
0 commit comments