def post(self):
        """Handle a post request from the create/update/edit form"""

        # Handle a form submission from list page
        if self.request.get("edit_form"):
            authorization = db.get(self.request.get("authorization_key"))
            if not authorization:
                return self.error(404, _("No such Authorization entity."))
            return self.render_form(authorization)

        # Handle authorization form submission
        if not (self.params.contact_name and self.params.contact_email and self.params.organization_name):
            return self.error(400, _("Please fill in all the required fields."))

        original_key = self.request.get("key")
        if original_key:
            # just override the existing one
            existing_authorization = db.get(original_key)
            if not existing_authorization:
                return self.error(404, _("No such Authorization entity."))
            key_str = existing_authorization.api_key
            action = ApiKeyManagementLog.UPDATE
        else:
            key_str = utils.generate_random_key(API_KEY_LENGTH)
            action = ApiKeyManagementLog.CREATE

        authorization = Authorization.create(self.repo, key_str, **to_authorization_params(self.params))
        authorization.put()

        management_log = ApiKeyManagementLog(repo=self.repo, api_key=authorization.api_key, action=action)
        management_log.put()

        self.redirect("/admin/api_keys?repo=%s&log_key=%s" % (self.repo, management_log.key()))
 def get(self):
     user = users.get_current_user()
     q = Authorization.all().filter('repo =', self.repo or '*')
     authorizations = q.fetch(KEYS_PER_PAGE)
     nav_html = ('<a href="%s">%s</a> '
                 % (self.get_url('admin/api_keys'),
                    escape(_('Create a new API key'))))
     user_email_with_tags = ('<span class="email">%s</span>'
             % escape(user.email()))
     return self.render('admin_api_keys_list.html',
                        nav_html=nav_html,
                        admin_api_keys_url=self.get_url('/admin/api_keys'),
                        user=user, authorizations=authorizations,
                        user_email_with_tags=user_email_with_tags)
 def get(self):
     user = users.get_current_user()
     q = Authorization.all().filter("repo =", self.repo)
     authorizations = q.fetch(KEYS_PER_PAGE)
     nav_html = '<a href="%s">%s</a> ' % (self.get_url("admin/api_keys"), escape(_("Create a new API key")))
     user_email_with_tags = '<span class="email">%s</span>' % escape(user.email())
     return self.render(
         "admin_api_keys_list.html",
         nav_html=nav_html,
         admin_api_keys_url=self.get_url("/admin/api_keys"),
         user=user,
         authorizations=authorizations,
         user_email_with_tags=user_email_with_tags,
     )
Exemple #4
0
    def post(self):
        """Handle a post request from the create/update/edit form"""

        user = users.get_current_user()
        xsrf_tool = utils.XsrfTool()
        if not (self.params.xsrf_token and xsrf_tool.verify_token(
                self.params.xsrf_token, user.user_id(), 'admin_api_keys')):
            return self.error(403)

        # Handle a form submission from list page
        if self.request.get('edit_form'):
            authorization = db.get(self.request.get('authorization_key'))
            if not authorization:
                return self.error(404, _('No such Authorization entity.'))
            return self.render_form(authorization)

        # Handle authorization form submission
        if not (self.params.contact_name and self.params.contact_email
                and self.params.organization_name):
            return self.error(400,
                              _('Please fill in all the required fields.'))

        original_key = self.request.get('key')
        if original_key:
            # just override the existing one
            existing_authorization = db.get(original_key)
            if not existing_authorization:
                return self.error(404, _('No such Authorization entity.'))
            key_str = existing_authorization.api_key
            action = ApiKeyManagementLog.UPDATE
        else:
            key_str = utils.generate_random_key(API_KEY_LENGTH)
            action = ApiKeyManagementLog.CREATE
        repo = self.repo or '*'

        authorization = Authorization.create(
            repo, key_str, **to_authorization_params(self.params))
        authorization.put()

        management_log = ApiKeyManagementLog(repo=repo,
                                             api_key=authorization.api_key,
                                             action=action)
        management_log.put()

        self.redirect('/admin/api_keys?repo=%s&log_key=%s' %
                      (self.repo, management_log.key()))
Exemple #5
0
    def add_authorization(self, badge_id, person_email):
        """
        Add an authorization (allow someone to admin a certain badge)

        :type badge_id: str
        :param badge_id: ID of the badge

        :type person_email: str
        :param person_email: Email of the Person grant rights to
        """

        if self.person_exists(email=person_email) and \
           self.badge_exists(badge_id):

            person = self.get_person(person_email)

            new_authz = Authorization(badge_id=badge_id,
                                      person_id=person.id)
            self.session.add(new_authz)
            self.session.flush()

            return (person_email, badge_id)

        return False
Exemple #6
0
def bitbucketPr():
	# method with logic for the PR fetching
	team, username, password, repos = '', '', '', ''
	# inquiring user credentials
	while not username:
		username =  input("Please enter your BitBucket account username:"******"Please enter your BitBucket account email:")
	while not password:
		password =  input("Please enter your BitBucket account password:"******"Indicate either a reposiory or a list of repositories"+ \
								 "dividing each by space and press enter." + \
								 " Leave empty if you want to search in all team repositories:")
	
	# new instance of Authorisation class
	newAuth = Authorization(username, password, team, repos)

	links = [] 

	if not newAuth.repos: # method for handling no repo situationA
		links = newAuth.PrLinksNoRep()
		# handling PR's opening according to links' length
		if newAuth.CheckLinksLen(links) == True:  
			newAuth.openInBrowser(links)

		elif newAuth.CheckLinksLen(links) == False:
			print("")
			print("Two many pull requests. Try to filter by repository.")
			print("")
		elif newAuth.CheckLinksLen(links) == None:
			print("")
			print("Nothing was found. Try checking your credentials")
			print("")

	else: # if repo is specified
		links = newAuth.PRlinksWithRep()
		if newAuth.CheckLinksLen(links) == True:
			newAuth.openInBrowser(links)

		elif newAuth.CheckLinksLen(links) == False:
			print("")
			print('Two many PRs.')
			print('Opening 10 of them')
			print("*" *20)

			newAuth.openTenInBrowser(links)

		elif newAuth.CheckLinksLen(links) == None:
			print("")
			print("Nothing was found. Try checking your credentials")
			print("")