Пример #1
0
    def default(self):
        if self.arguments.no_color:
            self.keyword_color = ""
            self.reset = ""
            self.reset_error = ""
            self.reset_success = ""

        self.line_break()
        old_pass = self.get_pass("Please enter your %scurrent password%s:" % (self.keyword_color, self.reset))
        self.line_break()
        new_pass = self.get_pass("Please enter your %snew password%s:" % (self.keyword_color, self.reset))
        self.line_break()
        new_pass_check = self.get_pass("Please enter your %snew password again%s:" % (self.keyword_color, self.reset))

        if new_pass != new_pass_check:
            self.line_break()
            self.abort("New password check failed. Please try again.")
            self.line_break()
            return

        with connected_controller(self):
            response = self.post("/user/change-pass", data={"old_pass": old_pass, "new_pass": new_pass})

            if response.status_code == 403:
                self.line_break()
                self.abort("The original password didn't match. Please try again")
                self.line_break()
            elif response.status_code == 200:
                self.line_break()
                self.putsuccess("Password changed successfully.")
                self.line_break()
            else:
                self.line_break()
                self.abort("Wight API returned an unexpected status code!")
                self.line_break()
Пример #2
0
    def default(self):
        with connected_controller(self):
            self.log.info("Authenticating with %s." % self.app.user_data.target)

            email = self.arguments.email
            if email is None:
                self.line_break()
                email = self.ask_for("%sPlease enter the %se-mail%s to authenticate with:" % (
                    self.reset, self.keyword_color, self.reset)
                )

            if not email:
                self.abort()
                return False

            password = self.arguments.password
            if password is None:
                password = self.get_pass("%sPlease enter the %spassword%s to authenticate with (nothing will be displayed):" % (
                    self.reset, self.keyword_color, self.reset)
                )

            if not password:
                self.abort()
                return False

            response = self.get("/auth/user", headers={
                'email': email,
                'password': password
            })

            if response.status_code == 400:
                self.abort("Invalid email or password")
                return False
            if response.status_code == 403:
                self.abort("Authentication failed.")
                return False
            elif response.status_code == 404:
                register = self.ask_for("%sUser does not exist. Do you wish to register? [%sy/n%s]" % (
                    self.reset, self.keyword_color, self.reset)
                )

                if not register or register.lower() not in ("y", "n") or register.lower() == "n":
                    self.abort()
                    return False

                response = self.get("/auth/register", headers={
                    'email': email,
                    'password': password
                })

                self.line_break()
                self.putsuccess("User registered and authenticated.")
                self.line_break()
            elif response.status_code == 200:
                self.line_break()
                self.putsuccess("Authenticated.")
                self.line_break()

            self.__update_token(response)
        return True
Пример #3
0
    def default(self):
        self.load_conf()
        team_name = self.arguments.team
        teams_names = []
        with connected_controller(self):
            if team_name:
                teams_names.append(team_name)
            else:
                user_info = self.get("/user/info")
                user_info = loads(user_info.content)
                teams_names = [team["name"] for team in user_info["user"]["teams"]]

            project_name = self.arguments.project
            teams_and_projects = self.__get_teams_and_projects_names(project_name, team_name, teams_names)
            load_tests = []
            quantity = self.__define_quantity(team_name, project_name)
            for team_and_project in teams_and_projects:
                team, project = team_and_project
                load_test_info = self.get("/teams/%s/projects/%s/load_tests/?quantity=%s" % (team, project, quantity))
                if load_test_info.status_code == 403:
                    self.puterror(
                        "You are not the owner or a team member for '%s%s%s' and thus can't list its tests in target '%s%s%s'." % (
                            self.keyword_color, team, self.reset_error,
                            self.keyword_color, self.app.user_data.target, self.reset_error
                        ))
                    return
                load_tests.append({"header": team_and_project, "load_tests": loads(load_test_info.content)})

            self.__print_load_tests(load_tests)
Пример #4
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        name = self.arguments.team_name

        log_message = "Created '%s%s%s' team in '%s%s%s' target." % (
            self.keyword_color, name, self.reset_success,
            self.keyword_color, target, self.reset_success
        )

        with connected_controller(self):
            response = self.post("/teams", {"name": name})

            self.line_break()

            if response.status_code == 200:
                self.putsuccess(log_message)
            elif response.status_code == 409:
                self.puterror("The team '%s%s%s' already exists in target '%s%s%s'." % (
                    self.keyword_color, name, self.reset_error,
                    self.keyword_color, target, self.reset_error
                ))
            elif response.status_code == 400:
                self.puterror("You should define a name for the team to be created.")

            self.line_break()
Пример #5
0
 def default(self):
     self.load_conf()
     target = self.app.user_data.target
     name = self.arguments.team_name
     self.write("")
     self.write(
         "This operation will delete all projects and all tests of team '%s'."
         % name)
     self.write("You have to retype the team name to confirm deletion.")
     self.write("")
     name_confirmation = self.ask_for("Team name: ")
     if name_confirmation != name:
         self.write(
             "The team name you type ('%s') is not the same you pass ('%s')."
             % (name, name_confirmation))
         self.write("Operation aborted...")
         return
     log_message = "Deleted '%s' team, all its projects and tests in '%s' target." % (
         name, target)
     with connected_controller(self):
         response = self.delete("/teams/%s" % name)
         if response.status_code == 200:
             self.log.info(log_message)
             self.write(log_message)
         elif response.status_code == 403:
             self.write(
                 "You are not the owner of team '%s' in target '%s' (which means you can't delete it)."
                 % (name, target))
         elif response.status_code == 404:
             self.write("Team '%s' does not exist in target '%s'." %
                        (name, target))
Пример #6
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        name = self.arguments.team_name
        new_name = self.arguments.new_name
        log_message = "Updated '%s%s%s' team to '%s%s%s' in '%s%s%s' target." % (
            self.keyword_color, name, self.reset_success, self.keyword_color,
            new_name, self.reset_success, self.keyword_color, target,
            self.reset_success)

        with connected_controller(self):
            response = self.put("/teams/%s" % name, {"name": new_name})

            self.line_break()
            if response.status_code == 200:
                self.putsuccess(log_message)
            elif response.status_code == 403:
                self.puterror(
                    "You are not the owner of team '%s%s%s' in target '%s%s%s' (which means you can't update it)."
                    % (self.keyword_color, name, self.reset_error,
                       self.keyword_color, target, self.reset_error))
            elif response.status_code == 404:
                self.puterror(
                    "Team '%s%s%s' does not exist in target '%s%s%s'." %
                    (self.keyword_color, name, self.reset_error,
                     self.keyword_color, target, self.reset_error))
            elif response.status_code == 400:
                self.puterror("The team's new name can't be null or empty.")
            self.line_break()
Пример #7
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        name = self.arguments.team_name
        with connected_controller(self):
            response = self.get("/teams/%s" % name)
            if response.status_code == 200:
                self.line_break()
                self.puts("%s%s" % (self.title_color, name))
                self.puts("-" * len(name))
                self.line_break()

                content = response.content
                if isinstance(content, six.binary_type):
                    content = content.decode('utf-8')
                team_data = loads(content)

                self.__print_members(team_data['owner'], team_data['members'])

                self.line_break()
                if 'projects' in team_data and team_data['projects']:
                    self.__print_projects(team_data['projects'])
                else:
                    self.puterror("This team has no projects. To create a project use '%swight project-create%s'." % (
                        self.commands_color, self.reset_error
                    ))

                self.line_break()
            elif response.status_code == 404:
                self.line_break()
                self.puterror("The team '%s%s%s' does not exists in target '%s%s%s'." % (
                    self.keyword_color, name, self.reset_error,
                    self.keyword_color, target, self.reset_error)
                )
                self.line_break()
Пример #8
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        name = self.arguments.team_name
        new_name = self.arguments.new_name
        log_message = "Updated '%s%s%s' team to '%s%s%s' in '%s%s%s' target." % (
            self.keyword_color, name, self.reset_success,
            self.keyword_color, new_name, self.reset_success,
            self.keyword_color, target, self.reset_success
        )

        with connected_controller(self):
            response = self.put("/teams/%s" % name, {"name": new_name})

            self.line_break()
            if response.status_code == 200:
                self.putsuccess(log_message)
            elif response.status_code == 403:
                self.puterror("You are not the owner of team '%s%s%s' in target '%s%s%s' (which means you can't update it)." % (
                    self.keyword_color, name, self.reset_error,
                    self.keyword_color, target, self.reset_error
                ))
            elif response.status_code == 404:
                self.puterror("Team '%s%s%s' does not exist in target '%s%s%s'." % (
                    self.keyword_color, name, self.reset_error,
                    self.keyword_color, target, self.reset_error
                ))
            elif response.status_code == 400:
                self.puterror("The team's new name can't be null or empty.")
            self.line_break()
Пример #9
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        name = self.arguments.team_name
        with connected_controller(self):
            response = self.get("/teams/%s" % name)
            if response.status_code == 200:
                self.line_break()
                self.puts("%s%s" % (self.title_color, name))
                self.puts("-" * len(name))
                self.line_break()

                content = response.content
                if isinstance(content, six.binary_type):
                    content = content.decode('utf-8')
                team_data = loads(content)

                self.__print_members(team_data['owner'], team_data['members'])

                self.line_break()
                if 'projects' in team_data and team_data['projects']:
                    self.__print_projects(team_data['projects'])
                else:
                    self.puterror(
                        "This team has no projects. To create a project use '%swight project-create%s'."
                        % (self.commands_color, self.reset_error))

                self.line_break()
            elif response.status_code == 404:
                self.line_break()
                self.puterror(
                    "The team '%s%s%s' does not exists in target '%s%s%s'." %
                    (self.keyword_color, name, self.reset_error,
                     self.keyword_color, target, self.reset_error))
                self.line_break()
Пример #10
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        name = self.arguments.team_name
        user_email = self.arguments.user_email

        with connected_controller(self):
            response = self.delete("/teams/%s/members" % name,
                                   {"user": user_email})

            self.line_break()

            if response.status_code == 200:
                self.putsuccess(
                    "User '%s%s%s' removed from Team '%s%s%s'." %
                    (self.keyword_color, user_email, self.reset_success,
                     self.keyword_color, name, self.reset_success))
            elif response.status_code == 403:
                self.puterror(
                    "You are not authenticated. Please use '%swight login%s'."
                    % (self.commands_color, self.reset_error))
            elif response.status_code == 404:
                self.puterror(
                    "Team '%s%s%s' does not exist in target '%s%s%s'." %
                    (self.keyword_color, name, self.reset_error,
                     self.keyword_color, target, self.reset_error))
            elif response.status_code == 401:
                self.puterror(
                    "You need to be the team owner or member to remove users.")

            self.line_break()
Пример #11
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        name = self.arguments.team_name
        user_email = self.arguments.user_email

        with connected_controller(self):
            response = self.delete("/teams/%s/members" % name, {"user": user_email})

            self.line_break()

            if response.status_code == 200:
                self.putsuccess("User '%s%s%s' removed from Team '%s%s%s'." % (
                    self.keyword_color, user_email, self.reset_success,
                    self.keyword_color, name, self.reset_success
                ))
            elif response.status_code == 403:
                self.puterror("You are not authenticated. Please use '%swight login%s'." % (
                    self.commands_color, self.reset_error
                ))
            elif response.status_code == 404:
                self.puterror("Team '%s%s%s' does not exist in target '%s%s%s'." % (
                    self.keyword_color, name, self.reset_error,
                    self.keyword_color, target, self.reset_error
                ))
            elif response.status_code == 401:
                self.puterror("You need to be the team owner or member to remove users.")

            self.line_break()
Пример #12
0
    def default(self):
        self.line_break()
        old_pass = self.get_pass("Please enter your current password:"******"Please enter your new password:"******"Please enter your new password again:")

        if new_pass != new_pass_check:
            self.line_break()
            self.puterror("New password check failed. Please try again.")
            self.line_break()
            return

        with connected_controller(self):
            response = self.post("/user/change-pass", data={"old_pass": old_pass, "new_pass": new_pass})

            if response.status_code == 403:
                self.line_break()
                self.puterror("The original password didn't match. Please try again")
                self.line_break()
            elif response.status_code == 200:
                self.line_break()
                self.puts("Password changed successfuly.")
                self.line_break()
            else:
                self.line_break()
                self.puterror("Wight API returned an unexpected status code!")
                self.line_break()
Пример #13
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        name = self.arguments.team_name

        log_message = "Created '%s%s%s' team in '%s%s%s' target." % (
            self.keyword_color, name, self.reset_success, self.keyword_color,
            target, self.reset_success)

        with connected_controller(self):
            response = self.post("/teams", {"name": name})

            self.line_break()

            if response.status_code == 200:
                self.putsuccess(log_message)
            elif response.status_code == 409:
                self.puterror(
                    "The team '%s%s%s' already exists in target '%s%s%s'." %
                    (self.keyword_color, name, self.reset_error,
                     self.keyword_color, target, self.reset_error))
            elif response.status_code == 400:
                self.puterror(
                    "You should define a name for the team to be created.")

            self.line_break()
Пример #14
0
    def default(self):
        self.load_conf()
        with connected_controller(self):
            content = self._load_response()

            while self.arguments.track and (content['status'] == "Running" or content['status'] == "Scheduled"):
                try:
                    time.sleep(5)
                    self.line_break()
                    self.write("-" * 80)
                    content = self._load_response()
                except KeyboardInterrupt:
                    sys.exit(1)
                except CaughtSignal:
                    sys.exit(1)
Пример #15
0
    def default(self):
        self.load_conf()
        with connected_controller(self):
            url = '/load_tests/%s/results/' % self.arguments.load_test_uuid

            response = self.get(url)

            if response.status_code == 404:
                return self.write("Load test %s doesn't exist" % self.arguments.load_test_uuid)

            content = response.content
            if isinstance(content, six.binary_type):
                content = content.decode('utf-8')
            content = loads(content)
            self._print_response(content)
Пример #16
0
    def default(self):
        self.load_conf()
        with connected_controller(self):
            content = self._load_response()

            while self.arguments.track and (content['status'] == "Running" or
                                            content['status'] == "Scheduled"):
                try:
                    time.sleep(5)
                    self.line_break()
                    self.write("-" * 80)
                    content = self._load_response()
                except KeyboardInterrupt:
                    sys.exit(1)
                except CaughtSignal:
                    sys.exit(1)
Пример #17
0
    def default(self):
        self.load_conf()
        team_name = self.arguments.team
        teams_names = []
        with connected_controller(self):
            if team_name:
                teams_names.append(team_name)
            else:
                user_info = self.get("/user/info")
                user_info = loads(user_info.content)
                teams_names = [
                    team["name"] for team in user_info["user"]["teams"]
                ]

            project_name = self.arguments.project
            try:
                teams_and_projects = self.__get_teams_and_projects_names(
                    project_name, team_name, teams_names)
            except TeamNotExist:
                err = sys.exc_info()[1]
                self.puterror(
                    "Team '%s%s%s' was not found in target '%s%s%s'." %
                    (self.keyword_color, str(err), self.reset_error,
                     self.keyword_color, self.app.user_data.target,
                     self.reset_error))
                return

            load_tests = []
            quantity = self.__define_quantity(team_name, project_name)
            for team_and_project in teams_and_projects:
                team, project = team_and_project
                load_test_info = self.get(
                    "/teams/%s/projects/%s/load_tests/?quantity=%s" %
                    (team, project, quantity))
                if load_test_info.status_code == 403:
                    self.puterror(
                        "You are not the owner or a team member for '%s%s%s' and thus can't list its tests in target '%s%s%s'."
                        % (self.keyword_color, team, self.reset_error,
                           self.keyword_color, self.app.user_data.target,
                           self.reset_error))
                    return
                load_tests.append({
                    "header": team_and_project,
                    "load_tests": loads(load_test_info.content)
                })

            self.__print_load_tests(load_tests)
Пример #18
0
 def default(self):
     self.load_conf()
     with connected_controller(self):
         response = self.get("/user/info")
         if response.status_code == 200:
             content = response.content
             if isinstance(content, six.binary_type):
                 content = content.decode('utf-8')
             content = loads(content)
             self.write("User: %s" % content['user']['email'])
             members_table = PrettyTable(["team", "role"])
             members_table.align["team"] = "l"
             members_table.align["role"] = "l"
             for team in content['user']['teams']:
                 members_table.add_row([team['name'], team['role']])
             self.write(members_table)
         elif response.status_code == 401:
             self.write("You are not authenticated. Try running wight login before using user-info.")
Пример #19
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        project_name = self._get_parameter(self.arguments.project, "project")

        if not team_name or not project_name:
            return

        base_url = self.arguments.url

        log_message = self._get_log_message(project_name, target, team_name)

        with connected_controller(self):
            simple = "true" if self.arguments.simple else "false"
            query_parameters = {
                'base_url': base_url,
                'simple': simple
            }

            branch = self.arguments.branch
            if branch:
                query_parameters['branch'] = branch
                log_message = self._get_log_message(project_name, target, team_name, branch=branch)

            response = self.post(
                "/teams/%(team_name)s/projects/%(project_name)s/load_tests/" % {
                    "team_name": team_name,
                    "project_name": project_name
                },
                query_parameters
            )

            self.line_break()

            if response.status_code == 200:
                self.app.user_data.set_last_schedule(team_name, project_name)
                self.putsuccess(log_message)
            elif response.status_code == 404:
                self.puterror("Project or Team not found at target '%s%s%s'." % (
                    self.keyword_color, target, self.reset_success
                ))

            self.line_break()
Пример #20
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        if not team_name:
            return

        name = self.arguments.project
        repo = self.arguments.repo

        with connected_controller(self):
            response = self.post("/teams/%s/projects/" % team_name, {"name": name, "repository": repo})
            self.line_break()
            if response.status_code == 200:
                self.putsuccess("Created '%s%s%s' project in '%s%s%s' team at '%s%s%s'." % (
                    self.keyword_color, name, self.reset_success,
                    self.keyword_color, team_name, self.reset_success,
                    self.keyword_color, target, self.reset_success
                ))
                self.line_break()
                return
            elif response.status_code == 409:
                self.puterror(
                    "The project '%s%s%s' already exists in team '%s%s%s' at '%s%s%s'." % (
                        self.keyword_color, name, self.reset_error,
                        self.keyword_color, team_name, self.reset_error,
                        self.keyword_color, target, self.reset_error,
                    )
                )
                self.line_break()
                return
            elif response.status_code == 400:
                self.puterror("Both name and repository are required in order to save a team.")
                self.line_break()
                return

            self.puterror(
                "The project '%s%s%s' was not created! (API Result: '%s%s%s', Status Code: '%s%s%s')." % (
                    self.keyword_color, name, self.reset_error,
                    self.keyword_color, response.content, self.reset_error,
                    self.keyword_color, response.status_code, self.reset_error,
                )
            )
            self.line_break()
Пример #21
0
    def default(self):
        if self.arguments.no_color:
            self.keyword_color = ""
            self.reset = ""
            self.reset_error = ""
            self.reset_success = ""

        self.line_break()
        old_pass = self.get_pass("Please enter your %scurrent password%s:" %
                                 (self.keyword_color, self.reset))
        self.line_break()
        new_pass = self.get_pass("Please enter your %snew password%s:" %
                                 (self.keyword_color, self.reset))
        self.line_break()
        new_pass_check = self.get_pass(
            "Please enter your %snew password again%s:" %
            (self.keyword_color, self.reset))

        if new_pass != new_pass_check:
            self.line_break()
            self.abort("New password check failed. Please try again.")
            self.line_break()
            return

        with connected_controller(self):
            response = self.post("/user/change-pass",
                                 data={
                                     "old_pass": old_pass,
                                     "new_pass": new_pass
                                 })

            if response.status_code == 403:
                self.line_break()
                self.abort(
                    "The original password didn't match. Please try again")
                self.line_break()
            elif response.status_code == 200:
                self.line_break()
                self.putsuccess("Password changed successfully.")
                self.line_break()
            else:
                self.line_break()
                self.abort("Wight API returned an unexpected status code!")
                self.line_break()
Пример #22
0
    def default(self):
        self.load_conf()
        with connected_controller(self):
            url = '/load_tests/%s/results/' % self.arguments.load_test_uuid

            response = self.get(url)

            if response.status_code == 404:
                self.line_break()
                self.write("%sLoad test '%s%s%s' doesn't exist" % (
                    self.error_text_color, self.keyword_color, self.arguments.load_test_uuid, self.reset_error)
                )
                return self.line_break()

            content = response.content
            if isinstance(content, six.binary_type):
                content = content.decode('utf-8')
            content = loads(content)
            self._print_response(content)
Пример #23
0
    def default(self):
        self.load_conf()
        with connected_controller(self):
            url = '/load_tests/%s/results/' % self.arguments.load_test_uuid

            response = self.get(url)

            if response.status_code == 404:
                self.line_break()
                self.write("%sLoad test '%s%s%s' doesn't exist" %
                           (self.error_text_color, self.keyword_color,
                            self.arguments.load_test_uuid, self.reset_error))
                return self.line_break()

            content = response.content
            if isinstance(content, six.binary_type):
                content = content.decode('utf-8')
            content = loads(content)
            self._print_response(content)
Пример #24
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        project_name = self.arguments.project

        if not team_name:
            return

        self.line_break()
        self.write(
            "This operation will delete the project '%s%s%s' and all its tests."
            % (self.keyword_color, project_name, self.reset_error))
        confirmation = self.ask_for(
            "%sAre you sure you want to delete project '%s%s%s'? [%sy/n%s]" %
            (self.reset, self.keyword_color, project_name, self.reset_error,
             self.keyword_color, self.reset))
        self.line_break()
        if not confirmation or confirmation.lower() not in (
                "y", "n") or confirmation.lower() == "n":
            self.abort()
            return False
        log_message = "Deleted '%s%s%s' project and tests for team '%s%s%s' in '%s%s%s' target." % (
            self.keyword_color, project_name, self.reset_error,
            self.keyword_color, team_name, self.reset_error,
            self.keyword_color, target, self.reset_error)
        with connected_controller(self):
            response = self.delete("/teams/%s/projects/%s" %
                                   (team_name, project_name))
            self.line_break()
            if response.status_code == 200:
                self.log.info(log_message)
                self.write(log_message)
            elif response.status_code == 403:
                self.puterror(
                    "You are not member of the team for the project '%s%s%s' and cannot delete it."
                    % (
                        self.keyword_color,
                        project_name,
                        self.reset_error,
                    ))
            self.line_break()
Пример #25
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        project_name = self._get_parameter(self.arguments.project, "project")

        if not team_name or not project_name:
            return

        base_url = self.arguments.url

        log_message = self._get_log_message(project_name, target, team_name)

        with connected_controller(self):
            simple = "true" if self.arguments.simple else "false"
            query_parameters = {'base_url': base_url, 'simple': simple}

            branch = self.arguments.branch
            if branch:
                query_parameters['branch'] = branch
                log_message = self._get_log_message(project_name,
                                                    target,
                                                    team_name,
                                                    branch=branch)

            response = self.post(
                "/teams/%(team_name)s/projects/%(project_name)s/load_tests/" %
                {
                    "team_name": team_name,
                    "project_name": project_name
                }, query_parameters)

            self.line_break()

            if response.status_code == 200:
                self.app.user_data.set_last_schedule(team_name, project_name)
                self.putsuccess(log_message)
            elif response.status_code == 404:
                self.puterror("Project or Team not found at target '%s%s%s'." %
                              (self.keyword_color, target, self.reset_success))

            self.line_break()
Пример #26
0
 def default(self):
     self.load_conf()
     with connected_controller(self):
         response = self.get("/user/info")
         if response.status_code == 200:
             content = response.content
             if isinstance(content, six.binary_type):
                 content = content.decode('utf-8')
             content = loads(content)
             self.write("User: %s" % content['user']['email'])
             members_table = PrettyTable(["team", "role"])
             members_table.align["team"] = "l"
             members_table.align["role"] = "l"
             for team in content['user']['teams']:
                 members_table.add_row([team['name'], team['role']])
             self.write(members_table)
         elif response.status_code == 401:
             self.write(
                 "You are not authenticated. Try running wight login before using user-info."
             )
Пример #27
0
    def default(self):
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        project_name = self._get_parameter(self.arguments.project, "project")

        if not team_name or not project_name:
            return

        name = self.arguments.name
        repo = self.arguments.repo

        with connected_controller(self):
            response = self.put(
                "/teams/%s/projects/%s" % (team_name, project_name), {
                    "name": name,
                    "repository": repo
                })
            self.line_break()
            if response.status_code == 200:
                name = name or project_name
                self.putsuccess(
                    "Updated '%s%s%s' project in '%s%s%s' team at '%s%s%s'." %
                    (self.keyword_color, name, self.reset_success,
                     self.keyword_color, team_name, self.reset_success,
                     self.keyword_color, target, self.reset_success))
            elif response.status_code == 403:
                self.puterror(
                    "You are not member of the team for the project '%s%s%s' and cannot update it."
                    % (
                        self.keyword_color,
                        project_name,
                        self.reset_error,
                    ))
            elif response.status_code == 404:
                self.puterror(
                    "The team '%s%s%s' or the project '%s%s%s' does not exists in target '%s%s%s'."
                    % (self.keyword_color, team_name, self.reset_error,
                       self.keyword_color, project_name, self.reset_error,
                       self.keyword_color, target, self.reset_error))
            self.line_break()
Пример #28
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        project_name = self.arguments.project

        if not team_name:
            return

        self.line_break()
        self.write(
            "This operation will delete the project '%s%s%s' and all its tests." %
            (self.keyword_color, project_name, self.reset_error)
        )
        confirmation = self.ask_for("%sAre you sure you want to delete project '%s%s%s'? [%sy/n%s]" % (
            self.reset, self.keyword_color, project_name, self.reset_error, self.keyword_color, self.reset)
        )
        self.line_break()
        if not confirmation or confirmation.lower() not in ("y", "n") or confirmation.lower() == "n":
            self.abort()
            return False
        log_message = "Deleted '%s%s%s' project and tests for team '%s%s%s' in '%s%s%s' target." % (
            self.keyword_color, project_name, self.reset_error,
            self.keyword_color, team_name, self.reset_error,
            self.keyword_color, target, self.reset_error
        )
        with connected_controller(self):
            response = self.delete("/teams/%s/projects/%s" % (team_name, project_name))
            self.line_break()
            if response.status_code == 200:
                self.log.info(log_message)
                self.write(log_message)
            elif response.status_code == 403:
                self.puterror(
                    "You are not member of the team for the project '%s%s%s' and cannot delete it." % (
                        self.keyword_color, project_name, self.reset_error,
                    )
                )
            self.line_break()
Пример #29
0
 def default(self):
     self.load_conf()
     target = self.app.user_data.target
     name = self.arguments.team_name
     self.write("")
     self.write("This operation will delete all projects and all tests of team '%s'." % name)
     self.write("You have to retype the team name to confirm deletion.")
     self.write("")
     name_confirmation = self.ask_for("Team name: ")
     if name_confirmation != name:
         self.write("The team name you type ('%s') is not the same you pass ('%s')." % (name, name_confirmation))
         self.write("Operation aborted...")
         return
     log_message = "Deleted '%s' team, all its projects and tests in '%s' target." % (name, target)
     with connected_controller(self):
         response = self.delete("/teams/%s" % name)
         if response.status_code == 200:
             self.log.info(log_message)
             self.write(log_message)
         elif response.status_code == 403:
             self.write("You are not the owner of team '%s' in target '%s' (which means you can't delete it)." % (name, target))
         elif response.status_code == 404:
             self.write("Team '%s' does not exist in target '%s'." % (name, target))
Пример #30
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        project_name = self._get_parameter(self.arguments.project, "project")
        pressure = self._get_parameter(self.arguments.pressure, "pressure")

        if not team_name or not project_name or pressure.lower() not in PRESSURES:
            return

        base_url = self.arguments.url

        log_message = "Scheduled a new load test for project '%s%s%s' in team '%s%s%s' at '%s%s%s' target." % (
            self.keyword_color, project_name, self.reset_success,
            self.keyword_color, team_name, self.reset_success,
            self.keyword_color, target, self.reset_success
        )

        with connected_controller(self):
            response = self.post("/teams/%(team_name)s/projects/%(project_name)s/load_tests/" % {
                "team_name": team_name,
                "project_name": project_name
            }, {
                'base_url': base_url,
                'pressure': pressure
            })

            self.line_break()

            if response.status_code == 200:
                self.putsuccess(log_message)
            elif response.status_code == 404:
                self.puterror("Project or Team not found at target '%s%s%s'." % (
                    self.keyword_color, target, self.reset_success
                ))

            self.line_break()
Пример #31
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        project_name = self._get_parameter(self.arguments.project, "project")

        if not team_name or not project_name:
            return

        name = self.arguments.project_name
        repo = self.arguments.repo

        with connected_controller(self):
            response = self.put("/teams/%s/projects/%s" % (team_name, project_name), {"name": name, "repository": repo})
            self.line_break()
            if response.status_code == 200:
                name = name or project_name
                self.putsuccess("Updated '%s%s%s' project in '%s%s%s' team at '%s%s%s'." % (
                    self.keyword_color, name, self.reset_success,
                    self.keyword_color, team_name, self.reset_success,
                    self.keyword_color, target, self.reset_success
                ))
            elif response.status_code == 403:
                self.puterror(
                    "You are not member of the team for the project '%s%s%s' and cannot update it." % (
                        self.keyword_color, project_name, self.reset_error,
                    )
                )
            elif response.status_code == 404:
                self.puterror(
                    "The team '%s%s%s' or the project '%s%s%s' does not exists in target '%s%s%s'." % (
                        self.keyword_color, team_name, self.reset_error,
                        self.keyword_color, project_name, self.reset_error,
                        self.keyword_color, target, self.reset_error
                    )
                )
            self.line_break()
Пример #32
0
    def default(self):
        with connected_controller(self):
            self.log.info("Authenticating with %s." %
                          self.app.user_data.target)

            try:
                email = self.arguments.email
                if email is None:
                    self.line_break()
                    email = self.ask_for(
                        "%sPlease enter the %se-mail%s to authenticate with:" %
                        (self.reset, self.keyword_color, self.reset))

                if not email:
                    self.abort()
                    return False

                password = self.arguments.password
                if password is None:
                    password = self.get_pass(
                        "%sPlease enter the %spassword%s to authenticate with (nothing will be displayed):"
                        % (self.reset, self.keyword_color, self.reset))

                if not password:
                    self.abort()
                    return False

                response = self.get("/auth/user",
                                    headers={
                                        'email': email,
                                        'password': password
                                    })

                if response.status_code == 400:
                    self.abort("Invalid email or password")
                    return False
                if response.status_code == 403:
                    self.abort("Authentication failed.")
                    return False
                elif response.status_code == 404:
                    register = self.ask_for(
                        "%sUser does not exist. Do you wish to register? [%sy/n%s]"
                        % (self.reset, self.keyword_color, self.reset))

                    if not register or register.lower() not in (
                            "y", "n") or register.lower() == "n":
                        self.abort()
                        return False

                    password = self._confirming_password(password)

                    response = self.get("/auth/register",
                                        headers={
                                            'email': email,
                                            'password': password
                                        })

                    self.line_break()
                    self.putsuccess("User registered and authenticated.")
                    self.line_break()
                elif response.status_code == 200:
                    self.line_break()
                    self.putsuccess("Authenticated.")
                    self.line_break()

                self.__update_token(response)
                return True
            except cement.core.exc.CaughtSignal:
                exc = sys.exc_info()[1]

                if exc.signum == 2:
                    self.abort("Authentication aborted.")
                    return False
                else:
                    raise
Пример #33
0
    def default(self):
        self.load_conf()
        target = self.app.user_data.target
        team_name = self._get_parameter(self.arguments.team, "team")
        if not team_name:
            return

        name = self.arguments.project
        repo = self.arguments.repo

        with connected_controller(self):
            response = self.post("/teams/%s/projects/" % team_name, {
                "name": name,
                "repository": repo
            })
            self.line_break()
            if response.status_code == 200:
                self.putsuccess(
                    "Created '%s%s%s' project in '%s%s%s' team at '%s%s%s'." %
                    (self.keyword_color, name, self.reset_success,
                     self.keyword_color, team_name, self.reset_success,
                     self.keyword_color, target, self.reset_success))
                self.line_break()
                return
            elif response.status_code == 409:
                self.puterror(
                    "The project '%s%s%s' already exists in team '%s%s%s' at '%s%s%s'."
                    % (
                        self.keyword_color,
                        name,
                        self.reset_error,
                        self.keyword_color,
                        team_name,
                        self.reset_error,
                        self.keyword_color,
                        target,
                        self.reset_error,
                    ))
                self.line_break()
                return
            elif response.status_code == 400:
                self.puterror(
                    "Both name and repository are required in order to save a team."
                )
                self.line_break()
                return

            self.puterror(
                "The project '%s%s%s' was not created! (API Result: '%s%s%s', Status Code: '%s%s%s')."
                % (
                    self.keyword_color,
                    name,
                    self.reset_error,
                    self.keyword_color,
                    response.content,
                    self.reset_error,
                    self.keyword_color,
                    response.status_code,
                    self.reset_error,
                ))
            self.line_break()