def send_message(self, report_text): """ Post the report to a Slack channel or DM a specific user.""" url = self.settings.get('slackURL') user = self.settings.get('slackUser') payload = {} payload['text'] = report_text payload['new-bot-name'] = user direct = self.settings.get('slackRecipient') channel = self.settings.get('slackChannel') if direct: payload['channel'] = '@' + direct elif channel: payload['channel'] = '#' + direct Utils.api_call(url, 'Slack', 'post', data=json.dumps(payload))
def get_session_id(self): """ Get a session ID from AtTask. """ attask_pword = self.settings.get('attaskPword') attask_user = self.settings.get('attaskUser') at_params = {'username': attask_user, 'password': attask_pword} login_url = urljoin(self._attask_api_url, self.settings.get('attaskLoginUrl')) response = Utils.api_call(login_url, self._pm_label, 'post', params=at_params) if response == False: return False else: return response['data']['sessionID']
def submit_deploy_ticket(self, site, environments, description, target_date): """ Submit a deployment ticket to JIRA/Agile Ready. """ issue_uri = self.settings.get("jiraIssueURL") issue_url = urljoin(self._jira_api_url, issue_uri) jira_user = self.settings.get("jiraUser") jira_pword = self.settings.get("jiraPword") message = {} for environment in environments: request = self.build_reqest(site, environment, description, target_date) headers = {"content-type": "application/json"} response = Utils.api_call( issue_url, "Jira", "post", data=request, auth=(jira_user, jira_pword), headers=headers ) if not response == False: url = response["key"] message[environment] = "The {0} deploy ticket is {1}".format(environment, url) else: message[environment] = "JIRA ticket submission failed for {0}".format(environment) return message
def git_repos(self): """ Get list of Stash repos from a specific Project. Note: this request will only bring back 9,999 repos, which should suffice, if it doesn't updaqte the stashLimit setting. """ stash_url = self.settings.get('stashURL') git_repo_name = self.settings.get('gitRepoName') stash_user = self.settings.get('stashUser') stash_pword = self.settings.get('stashPword') stash_cert_verify = self.settings.get('stashCertVerify') stash_limit = self.settings.get('stashLimit') stash_params = {'limit' : stash_limit} response = Utils.api_call(stash_url, git_repo_name, 'get', auth=(stash_user, stash_pword), verify=stash_cert_verify, params=stash_params) if not response == False: repos = Stash.parse_repos(response['values']) return repos else: return {}
def submit_deploy_ticket(self, site, environments, description, target_date): """ Submit a Deployment request to AtTask. site -- The site the ticket is for environments -- The name(s) of the environments to deploy to description -- The description text to go in the task targetDate -- The date to put in the label fo the ticket """ sessparam = {} session_id = self.get_session_id() # Make sure you can get a Session ID if session_id: sessparam['sessionID'] = session_id else: return False # Set-up AtTask request attask_project_id = self.settings.get('attaskProjectID') dev_ops_team_id = self.settings.get('devOpsTeamID') attask_base_url = self.settings.get('attaskBaseURL') attask_assignee_type = self.settings.get('attaskAssigneeType') task_url = urljoin(self._attask_api_url, self.settings.get('attaskTaskURL')) message = {} for environment in environments: title = environment + ' Deployment for ' + site +' w.e. ' + target_date at_params = {'name': title, 'projectID': attask_project_id, attask_assignee_type: dev_ops_team_id, 'description': description} response = Utils.api_call(task_url, self._pm_label, 'post', params=at_params, headers=sessparam) if not response == False: data = response['data'] msg = "The {0} deploy ticket is".format(environment) msg += " <{0}task/view?ID={1}>".format(attask_base_url, data['ID']) message[environment] = msg else: msg = "The {0} deploy ticket did not submit to".format(environment) msg += "{0} properly".format(self._pm_label) message[environment] = msg return message