def build(self): """ Builds a Client and Application wrapper instance based on the configured *set_application_href*. See the Class-level docstring for usage scenarios. :returns a Client and Application wrapper instance based on the configured *set_application_href*. """ assert_not_none(self.application_href, "'application_href' property must be specified when using this builder implementation.") cleaned_href = self.application_href[0:len(self.application_href)] #just returning a copy at_sigh_index = cleaned_href.find('@') if at_sigh_index > 0: #otherwise an apiKey File/YAML/etc for the API Key is required parts = self._get_href_with_user_info_(cleaned_href, at_sigh_index) cleaned_href = parts[0] + parts[2] parts = parts[1].split(':', 1) api_key_properties = self._create_api_key_properties_(parts) self.set_api_key_properties(api_key_properties) assert_true(cleaned_href.find('http') == 0 and cleaned_href.find('://') > 0, 'Invalid application href URL') client = self._build_client_() application = client.data_store.get_resource(cleaned_href, Application) return ClientApplication(client, application)
def __init__(self, http_method, href, body = None, http_headers = None, query_string = None): assert_not_none(href, "href cannot be None.") split = href.split('?') self.query_string = query_string if query_string else {} if len(split) > 1: self.href = split[0] query_string_str = split[1] query_string_lst = query_string_str.split('&') for pair in query_string_lst: pair_lst = pair.split('=') self.query_string[pair_lst[0]] = pair_lst[1] else: self.href = href self.http_method = http_method.upper() self.http_headers = http_headers if http_headers else {} self.body = body if self.body is not None: self.http_headers['Content-Length'] = str(len(self.body))
def authenticate(self, parent_href, request): assert_not_none(parent_href, "parent_href must be specified.") assert_instance(request, UsernamePasswordRequest, 'request') username = request.principals if request.principals else '' password = request.credentials if request.credentials else '' value = base64.b64encode(bytes((username + ':' + password).encode())) attempt = self.data_store.instantiate(BasicLoginAttempt) attempt.type('basic') attempt.value(value.decode()) href = parent_href + '/loginAttempts' return self.data_store.create(href, attempt, AuthenticationResult)