def selftest_function(opts): """ Placeholder for selftest function. An example use would be to test package api connectivity. Suggested return values are be unimplemented, success, or failure. """ # Get app.config parameters. options = opts.get(CONFIG_DATA_SECTION, {}) validate_fields([ 'microsoft_graph_token_url', 'microsoft_graph_url', 'tenant_id', 'client_id', 'client_secret', 'max_messages', 'max_users' ], options) # Read configuration settings: token_url = options['microsoft_graph_token_url'] graph_url = options['microsoft_graph_url'] tenant_id = options['tenant_id'] client_id = options['client_id'] client_secret = options['client_secret'] max_messages = options['max_messages'] max_users = options['max_users'] try: log.info(u'Calling MS Graph API with: \n token_url: ' + token_url + u'\n MS Graph API url: ' + graph_url + u'\n tenant_id: ' + tenant_id + u'\n client_id: ' + client_id + u'\n max_messages: ' + max_messages + u'\n max_users: ' + max_users) state, reason = "", "" # Create MSGraphHelper class object ms_graph_helper = MSGraphHelper( token_url, graph_url, tenant_id, client_id, client_secret, max_messages, max_users, RequestsCommon(opts, options).get_proxies()) # Get a MS Graph session token session_token = ms_graph_helper.authenticate() if ms_graph_helper and session_token: state = "success" else: state = "failure" reason = "N/A" except IntegrationError as err: state = "failure" reason = err.value result = {"state": state, "reason": reason} log.info(result) return result
def selftest_function(opts): """ Placeholder for selftest function. An example use would be to test package api connectivity. Suggested return values are be unimplemented, success, or failure. """ # Get app.config parameters. options = opts.get(CONFIG_DATA_SECTION, {}) validate_fields([ 'microsoft_graph_token_url', 'microsoft_graph_url', 'tenant_id', 'client_id', 'client_secret', 'max_messages', 'max_users' ], options) # Read configuration settings: token_url = options.get('microsoft_graph_token_url') graph_url = options.get('microsoft_graph_url') tenant_id = options.get('tenant_id') client_id = options.get('client_id') client_secret = options.get('client_secret') max_messages = int(options.get('max_messages')) max_users = int(options.get('max_users')) max_retries_total = int(options.get('max_retries_total', MAX_RETRIES_TOTAL)) max_retries_backoff_factor = int( options.get('max_retries_backoff_factor', MAX_RETRIES_BACKOFF_FACTOR)) max_batched_requests = int( options.get("max_batched_requests", MAX_BATCHED_REQUESTS)) try: log.info(u'Calling MS Graph API with: \n token_url: %s', token_url) log.info(u'MS Graph API url: %s', graph_url) log.info(u'tenant_id: %s', tenant_id) log.info(u'client_id: %s', client_id) log.info(u'max_messages: %s', str(max_messages)) log.info(u'max_users: %s', str(max_users)) log.info(u'max_retries_total: %s', str(max_retries_total)) log.info(u'max_retries_backoff_factor: %s', str(max_retries_backoff_factor)) log.info(u'max_batched_requests: %s', str(max_batched_requests)) state, reason = "", "" # Create MSGraphHelper class object ms_graph_helper = MSGraphHelper( token_url, graph_url, tenant_id, client_id, client_secret, max_messages, max_users, max_retries_total, max_retries_backoff_factor, max_batched_requests, RequestsCommon(opts, options).get_proxies()) # Get a MS Graph session token session_token = ms_graph_helper.authenticate() if ms_graph_helper and session_token: state = "success" else: state = "failure" reason = "authenication failure" except IntegrationError as err: state = "failure" reason = err.value result = {"state": state, "reason": reason} log.info(result) return result