def __get_kiali_client__(config): if(config.get('kiali_ssl_enabled') is True): context = ssl._create_unverified_context() return KialiClient(host=config.get('kiali_hostname'), username=config.get('kiali_username'), password=config.get('kiali_password'), port=443, context=context, scheme='https') else: return KialiClient(host=config.get('kiali_hostname'), username=config.get('kiali_username'), password=config.get('kiali_password'))
def make_request(auth_type="auth"): with timeout(seconds=180, error_message='Timed out waiting for API call to complete'): while True: if auth_type == AUTH_LOGIN: kiali_client = conftest.get_new_kiali_client() response = kiali_client.request(method_name='namespaceList', path=None, params=None) elif auth_type == AUTH_NOAUTH: kiali_client = KialiClient( hostname=conftest.get_kiali_hostname(), auth_type=AUTH_NOAUTH, verify=False, swagger_address=conftest.get_kiali_swagger_address()) response = kiali_client.request(method_name='namespaceList', path=None, params=None) else: assert False, "Error: Unsupported Auth Strategy Type: {}".format( auth_type) if response.status_code == 200: break time.sleep(2) return True
def __get_kiali_client__(config): if(config.get('kiali_scheme') == 'https'): return KialiClient(hostname=config.get('kiali_hostname'), auth_type=config.get( 'kiali_auth_method'), username=config.get('kiali_username'), password=config.get('kiali_password'), verify=config.get( 'kiali_verify_ssl_certificate'), swagger_address=config.get('kiali_swagger_address'), custom_base_path=config.get('kiali_custom_base_context')) else: return KialiClient(hostname=config.get('kiali_hostname'), username=config.get('kiali_username'), password=config.get('kiali_password'), auth_type=config.get('kiali_auth_method'), swagger_address=config.get('kiali_swagger_address'), custom_base_path=config.get('kiali_custom_base_context'))
def do_auth_strategy_test(auth_type): config = conftest.__get_environment_config__(conftest.ENV_FILE) swagger = config.get('kiali_swagger_address') hostname = config.get('kiali_hostname') if AUTH_NOAUTH in auth_type: kiali_client = KialiClient(hostname=hostname, auth_type=AUTH_NOAUTH, verify=False, swagger_address=swagger) response = kiali_client.request(method_name='namespaceList', path=None, params=None) # Make API call - expected to pass with no authentication assert response.status_code == 200, "Unexpected status code \'response.status_code\'" else: assert False, "To Do" return True
def __get_kiali_client__(config): print "\nGet Kiali Client for Kiali hostname: {}\n".format(config.get('kiali_hostname')) return KialiClient(host=config.get('kiali_hostname'), username=config.get('kiali_username'), password=config.get('kiali_password'))
def main(): module = AnsibleModule( argument_spec=dict( kiali_api_hostname= dict( default=os.environ.get('KIALI_HOSTNAME'), type='str'), kiali_api_port= dict( default=os.environ.get('KIALI_PORT'), type='int'), kiali_api_username=dict( default=os.environ.get('KIALI_USERNAME'), type='str'), kiali_api_password=dict( default=os.environ.get('KIALI_PASSWORD'), type='str'), kiali_api_swagger_address=dict( default=os.environ.get('KIALI_SWAGGER_ADDRESS'), type='str'), kiali_api_scheme= dict(required=False, type='str', choices=['https', 'http'], default='https'), kiali_api_auth_type = dict(required=False, type='str', choices=['https-user-password', 'no-auth'], default='https-user-password'), kiali_api_request= dict(required=True, type='dict'), kiali_api_verify_ssl=dict(required=False, type='bool', default=False), ) ) for arg in ['kiali_api_hostname', 'kiali_api_port', 'kiali_api_username', 'kiali_api_password']: if module.params[arg] in (None, ''): module.fail_json(msg="missing required argument: {}".format(arg)) hostname = module.params['kiali_api_hostname'] port = module.params['kiali_api_port'] username = module.params['kiali_api_username'] password = module.params['kiali_api_password'] scheme = module.params['kiali_api_scheme'] auth_type = module.params['kiali_api_auth_type'] verify_ssl = module.params['kiali_api_verify_ssl'] request = module.params['kiali_api_request'] try: params = request['params'] except KeyError: params = None try: path = request['path'] except KeyError: path = None print(params) kiali_client = KialiClient(hostname=hostname, scheme=scheme, port=port, auth_type=auth_type, username=username, password=password, verify=verify_ssl) response = kiali_client.request(method_name=request['method_name'], path=path, params=params) full_response = {'status_code': response.status_code, 'url': response.url, 'text': response.text,'elapsed_time': response.elapsed.total_seconds()} module.exit_json(**full_response)
def __get_kiali_client__(config): return KialiClient(host=config.get('kiali_hostname'), username=config.get('kiali_username'), password=config.get('kiali_password'))