Example #1
0
    def terminate(self):
        args = self.fetch_args()

        data = {"reason": args["reason"]}

        # Calling Pipeline Execute API
        url = get_pipeline_execute_url(args["environment"],
                                       args["enterprise_id"],
                                       args["pipeline_id"],
                                       args["execution_id"], "terminate")

        try:
            self.app.log.debug("Terminating Pipeline Execution...")
            response = execute_pipeline(url, args["api_key"], data)
        except APIException:
            self.app.render("ERROR in connecting to Environment!\n")
            return

        if not response.ok:
            self.handle_response_failure(response)
            return

        # Rendering table with populated values
        data = render_single_dict(response.json())

        self.app.render(f"Pipeline execution Terminated! Details: \n")
        self.app.render(data,
                        format=OutputFormat.TABULATED.value,
                        headers="keys",
                        tablefmt="plain")
Example #2
0
    def edit(self):
        validate_creds_exists(self.app)
        db = DBWrapper(self.app.creds)
        environment = db.get_configure().get("environment")
        enterprise_id = db.get_enterprise_id()

        pipeline_id = self.app.pargs.pipeline_id
        if not pipeline_id:
            pipeline_id = prompt.query("Enter the Pipeline ID: ")

        stage_id = self.app.pargs.stage_id
        if not stage_id:
            stage_id = prompt.query("Enter the Stage ID: ")

        operation_id = self.app.pargs.operation_id
        if not operation_id:
            operation_id = prompt.query("Enter the Operation ID: ")

        name = self.app.pargs.name
        if not name:
            name = input("Change the name of the Operation: ")

        desc = self.app.pargs.desc
        if not desc:
            desc = input(
                "Change the description for this Operation [optional]: ")

        action = self.app.pargs.action
        if not action:
            p = Prompt("Action for this Operation: ",
                       options=ActionEnums.choices_values(),
                       numbered=True)

            action = ActionEnums(p.input).name

        # Calling Pipeline Graphs API
        url = get_operation_url(environment,
                                enterprise_id,
                                pipeline_id=pipeline_id,
                                stage_id=stage_id,
                                operation_id=operation_id)
        api_key = db.get_configure().get("api_key")

        try:
            self.app.log.debug("Editing Operation...")
            response = edit_operation(url, api_key, name, action, desc)
        except APIException:
            self.app.render("ERROR in connecting to Environment!\n")
            return

        if not response.ok:
            self.app.log.debug(
                f"Response not OK. Status Code: {response.status_code}")
            self.app.log.debug(f"Response not OK. Response: {response.json()}")
            if response.status_code == 400:
                errors = response.json().get('meta',
                                             {}).get('non_field_errors')
                if errors:
                    self.app.log.error(f"Validation Error: {errors}")
                if response.json().get("errors"):
                    self.app.log.error(
                        f"Validation Error: {response.json().get('errors')}")

            if response.status_code == 404:
                self.app.log.error("Pipeline URL not found!")

            if response.status_code == 500:
                self.app.log.error(f"Internal Server Error! {response.json()}")
            return

        # Rendering table with populated values
        data = render_single_dict(response.json())

        self.app.render(
            f"Edited Operation for this Stage Successfully! Details: \n")
        self.app.render(data,
                        format=OutputFormat.TABULATED.value,
                        headers="keys",
                        tablefmt="plain")
Example #3
0
    def create(self):
        validate_creds_exists(self.app)
        db = DBWrapper(self.app.creds)
        environment = db.get_configure().get("environment")
        enterprise_id = db.get_enterprise_id()

        pipeline_id = self.app.pargs.pipeline_id
        if not pipeline_id:
            pipeline_id = prompt.query("Enter the Pipeline ID: ")

        stage_id = self.app.pargs.stage_id
        if not stage_id:
            stage_id = prompt.query("Enter the Stage ID: ")

        name = self.app.pargs.name
        if not name:
            name = input("Name of the Operation: ")

        action = self.app.pargs.action
        if not action:
            p = Prompt("Action for this Operation: ",
                       options=ActionEnums.choices_values(),
                       numbered=True)

            action = ActionEnums(p.input).name

        group = self.app.pargs.group_name
        if not group:
            name = input(
                "Name of the Group (to which the command must be fired): ")

        try:
            group_obj = self.validate_group_name(name)
            group_url = get_group_command_url(environment, enterprise_id,
                                              group_obj.id)

        except ApiException as e:
            self.app.log.error(
                f"[group-list] Failed to find group with name {name}: {e}")
            return

        desc = self.app.pargs.desc
        if not desc:
            desc = input("Description for this Operation [optional]: ")

        # Calling Pipeline API
        url = get_operation_url(environment, enterprise_id, pipeline_id,
                                stage_id)
        api_key = db.get_configure().get("api_key")

        try:
            self.app.log.debug("Creating Operation...")
            response = create_operation(url, api_key, name, action, desc,
                                        group_url)
        except APIException:
            self.app.render("ERROR in connecting to Environment!\n")
            return

        if not response.ok:
            self.app.log.debug(
                f"Response not OK. Status Code: {response.status_code}")
            self.app.log.debug(f"Response not OK. Response: {response.json()}")
            if response.status_code == 400:
                errors = response.json().get('meta',
                                             {}).get('non_field_errors')
                if errors:
                    self.app.log.error(f"Validation Error: {errors}")
                if response.json().get("errors"):
                    if "The fields pipeline, ordering must make a unique set." in response.json(
                    ).get("message"):
                        self.app.log.error(
                            f"Operation with same `name` already created for this Stage!"
                        )
                    else:
                        self.app.log.error(
                            f"Validation Error: {response.json().get('errors')}"
                        )
                self.app.log.error(f"400 Errors -> {response.json()}")

            if response.status_code == 404:
                self.app.log.error("Stage URL not found!")

            if response.status_code == 500:
                self.app.log.error(f"Internal Server Error! {response.json()}")
            return

        # Rendering table with populated values
        data = render_single_dict(response.json())

        self.app.render(f"Added Operation to Stage Successfully! Details: \n")
        self.app.render(data,
                        format=OutputFormat.TABULATED.value,
                        headers="keys",
                        tablefmt="plain")
Example #4
0
    def create(self):
        validate_creds_exists(self.app)
        db = DBWrapper(self.app.creds)
        environment = db.get_configure().get("environment")
        enterprise_id = db.get_enterprise_id()

        pipeline_id = self.app.pargs.pipeline_id
        if not pipeline_id:
            pipeline_id = prompt.query("Enter the Pipeline ID: ")

        name = self.app.pargs.name
        if not name:
            name = input("Name of the Stage: ")

        order = self.app.pargs.order
        if not order:
            order = prompt.query("Order of this Stage: ")

        desc = self.app.pargs.desc
        if not desc:
            desc = input("Description for this Stage [optional]: ")

        # Calling Pipeline Graphs API
        url = get_stage_url(environment, enterprise_id, pipeline_id)
        api_key = db.get_configure().get("api_key")

        try:
            self.app.log.debug("Creating Pipeline...")
            response = create_stage(url, api_key, name, order, desc)
        except APIException:
            self.app.render("ERROR in connecting to Environment!\n")
            return

        if not response.ok:
            self.app.log.debug(
                f"Response not OK. Status Code: {response.status_code}")
            self.app.log.debug(f"Response not OK. Response: {response.json()}")
            if response.status_code == 400:
                errors = response.json().get('meta',
                                             {}).get('non_field_errors')
                if errors:
                    self.app.log.error(f"Validation Error: {errors}")
                if response.json().get("errors"):
                    self.app.log.error(
                        f"Validation Error: {response.json().get('errors')}")

            if response.status_code == 404:
                self.app.log.error("Stage URL not found!")

            if response.status_code == 500:
                self.app.log.error(f"Internal Server Error! {response.json()}")
            return

        # Rendering table with populated values
        data = render_single_dict(response.json())

        self.app.render(f"Added Stage to Pipeline Successfully! Details: \n")
        self.app.render(data,
                        format=OutputFormat.TABULATED.value,
                        headers="keys",
                        tablefmt="plain")
Example #5
0
    def create(self):
        validate_creds_exists(self.app)
        db = DBWrapper(self.app.creds)
        environment = db.get_configure().get("environment")
        enterprise_id = db.get_enterprise_id()

        name = self.app.pargs.name
        if not name:
            name = prompt.query("Name of the Pipeline: ")

        desc = self.app.pargs.desc
        if not desc:
            desc = input("Description for this Pipeline [optional]: ")

        # Setup Trigger
        trigger = prompt.options(
            "What type of trigger do you want for your Pipeline?",
            options=[
                {"selector": 1, "prompt": TriggerEventType.NEW_APP_VERSION_EVENT.value,
                 "return": TriggerEventType.NEW_APP_VERSION_EVENT.name},
                {"selector": 2, "prompt": "Skip for now...", "return": "skip"}
            ])

        if trigger != "skip":
            if trigger == TriggerEventType.NEW_APP_VERSION_EVENT.name:
                app_name = input("Enter the Application name: ")
                package_name = input("Enter the Package name: ")

                trigger = {
                    "trigger_event": TriggerEventType.NEW_APP_VERSION_EVENT.value,
                    "pre_conditions": {
                        "application_name": app_name,
                        "package_name": package_name
                    }
                }
        else:
            trigger = None

        # Calling Pipeline Graphs API
        url = get_pipeline_url(environment, enterprise_id)
        api_key = db.get_configure().get("api_key")

        try:
            self.app.log.debug("Creating Pipeline...")
            response = create_pipeline(url, api_key, name, desc, trigger)
        except APIException:
            self.app.render("ERROR in connecting to Environment!\n")
            return

        if not response.ok:
            self.app.log.debug(f"Response not OK. Status Code: {response.status_code}")
            self.app.log.debug(f"Response not OK. Response: {response.json()}")
            if response.status_code == 400:
                errors = response.json().get('meta', {}).get('non_field_errors')
                if errors:
                    self.app.log.error(f"Validation Error: {errors}")
                if response.json().get("errors"):
                    self.app.log.error(f"Validation Error: {response.json().get('errors')}")

            if response.status_code == 404:
                self.app.log.error("Pipeline URL not found!")

            if response.status_code == 500:
                self.app.log.error(f"Internal Server Error! {response.json()}")
            return

        # Rendering table with populated values
        data = render_single_dict(response.json())

        self.app.render(f"Created Pipeline Successfully! Details: \n")
        self.app.render(data, format=OutputFormat.TABULATED.value, headers="keys", tablefmt="plain")