def config_valid(): """Does the config have the necessary bits for talking to the SAM SOAP API""" sam = CONFIG_BROKER.get('sam') or {} has_wsdl = bool(sam.get('wsdl')) has_user = bool(sam.get('username')) has_pass = bool(sam.get('password')) return has_wsdl and has_user and has_pass
def get_config(): sam_config = CONFIG_BROKER.get('sam_duns') if sam_config: return sam_config.get('username'), sam_config.get('password'), sam_config.get('host'), \ sam_config.get('port') return None, None, None, None, None
def service_config(service_type): """ We use or {} instead of get(key, {}) as an empty config is converted into None rather than an empty dict Args: service_type: type of service to ping (usually 'procurement_service' or 'grant_service') Returns: dictionary of config values for FSRS service """ fsrs_config = CONFIG_BROKER.get('fsrs') or {} return fsrs_config.get(service_type) or {}
def config_valid(): """ Does the config have the necessary bits for talking to the SAM SOAP API Returns: A boolean indicating whether the configs have a wsdl, user, and password defined """ sam = CONFIG_BROKER.get('sam') or {} has_wsdl = bool(sam.get('wsdl')) has_user = bool(sam.get('username')) has_pass = bool(sam.get('password')) return has_wsdl and has_user and has_pass
def get_config(): """ Simply retrieves the config data of SAM sftp Returns: Username, password, host, and port found in the configu file for the SAM sftp """ sam_config = CONFIG_BROKER.get('sam_duns') if sam_config: return sam_config.get('username'), sam_config.get('password'), sam_config.get('host'), \ sam_config.get('port') return None, None, None, None, None
def get_client(ssh_key=None): """ Connects to the SAM client and returns a usable object for interaction Arguments: ssh_key: private ssh key to connect to the secure API Returns: client object to interact with the SAM service """ sam_config = CONFIG_BROKER.get('sam_duns') if not sam_config: return None if ssh_key: host = sam_config.get('host_ssh') username = sam_config.get('username_ssh') password = sam_config.get('password_ssh') ssh_key_file = RetrieveFileFromUri( ssh_key, binary_data=False).get_file_object() pkey = paramiko.RSAKey.from_private_key( ssh_key_file, password=sam_config.get('ssh_key_password')) else: host = sam_config.get('host') username = sam_config.get('username') password = sam_config.get('password') pkey = None if None in (host, username, password) or ssh_key and not pkey: raise Exception("Missing config elements for connecting to SAM") client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(hostname=host, username=username, password=password, pkey=pkey) return client
def serviceConfig(serviceType): """We use or {} instead of get(key, {}) as an empty config is converted into None rather than an empty dict""" fsrsConfig = CONFIG_BROKER.get('fsrs') or {} return fsrsConfig.get(serviceType) or {}
def service_config(service_type): """We use or {} instead of get(key, {}) as an empty config is converted into None rather than an empty dict""" fsrs_config = CONFIG_BROKER.get('fsrs') or {} return fsrs_config.get(service_type) or {}