示例#1
0
 def is_token_valid(self, request_token_string):
     self.client = oauth.Client(self.consumer, request_token_string)
     self.client.set_signature_method(JiraSignature.JiraSignature())
     resp, content = self.request_info()
     if resp['status'] == '500':
         self.cache.add_log_entry(self.__class__.__name__, "Jira responded with status 500")
     return resp['status'] == '200'
示例#2
0
 def init_client(self):
     tries = 3
     while self.token is None and tries > 0:
         self.retrieve_token()
         tries -= 1
     if self.token is None or tries == 0:
         raise Exception("Unable to retrieve sd api token, shutting down.")
     self.client = oauth.Client(self.consumer, self.token)
     self.client.set_signature_method(JiraSignature.JiraSignature())
示例#3
0
 def get_access_token(self, request_token, request_secret):
     access_token_url = self.environment.get_endpoint_access_token()
     token = oauth.Token(request_token, request_secret)
     self.client = oauth.Client(self.consumer, token)
     self.client.set_signature_method(JiraSignature.JiraSignature())
     resp, content = self.client.request(access_token_url, "POST")
     access_token_response = dict(parse.parse_qsl(content))
     if b'oauth_problem' in access_token_response:
         access_problem = access_token_response[b'oauth_problem'].decode("utf-8")
         self.cache.add_log_entry(self.__class__.__name__, access_problem)
         raise Exception("No rights")
     access_token_final = access_token_response[b'oauth_token'].decode("utf-8")
     access_secret_final = access_token_response[b'oauth_token_secret'].decode("utf-8")
     access_token = oauth.Token(access_token_final, access_secret_final)
     return access_token
示例#4
0
 def retrieve_token_url(self):
     request_token_url = self.environment.get_endpoint_request_token()
     self.client = oauth.Client(self.consumer)
     self.client.set_signature_method(JiraSignature.JiraSignature())
     resp, content = self.client.request(request_token_url, "POST")
     if resp['status'] != '200':
         raise Exception("Invalid response %s: %s" % (resp['status'],  content))
     request_token = dict(parse.parse_qsl(content))
     request_token_string = request_token[b'oauth_token'].decode("utf-8")
     request_secret_string = request_token[b'oauth_token_secret'].decode("utf-8")
     authorize_url = self.environment.get_endpoint_authorize()
     print("%s?oauth_token=%s" % (authorize_url, request_token_string))
     input('Please visit the URL and hit Enter')
     token = self.get_access_token(request_token_string, request_secret_string)
     token_is_valid = self.is_token_valid(token)
     if not token_is_valid:
         raise Exception("Right violation - shutting down")
     else:
         self.cache_token(token)
     self.token = token