Пример #1
0
    def RequestCronJobApproval(self,
                               cron_job_id,
                               requestor=None,
                               reason=None,
                               email_cc_address=None,
                               approver="approver"):
        """Request cron job approval for a given cron job."""

        if not requestor:
            requestor = self.token.username

        if not reason:
            reason = self.token.reason

        self.CreateUser(requestor)
        self.CreateUser(approver)

        args = api_user.ApiCreateCronJobApprovalArgs(
            cron_job_id=cron_job_id,
            approval=api_user.ApiCronJobApproval(
                reason=reason,
                notified_users=[approver],
                email_cc_addresses=([email_cc_address]
                                    if email_cc_address else [])))
        handler = api_user.ApiCreateCronJobApprovalHandler()
        result = handler.Handle(
            args, token=access_control.ACLToken(username=requestor))

        return result.id
Пример #2
0
    def Run(self):
        with test_lib.FakeTime(42):
            self.CreateUser("approver")

        cron_manager = aff4_cronjobs.CronManager()
        cron_args = aff4_cronjobs.CreateCronJobFlowArgs(periodicity="1d",
                                                        allow_overruns=False)
        cron_urn = cron_manager.ScheduleFlow(cron_args=cron_args,
                                             token=self.token)
        cron_id = cron_urn.Basename()

        def ReplaceCronAndApprovalIds():
            approvals = self.ListCronJobApprovals()
            return {
                approvals[0].id: "approval:112233",
                cron_id: "CronJob_123456"
            }

        with test_lib.FakeTime(126):
            self.Check("CreateCronJobApproval",
                       args=user_plugin.ApiCreateCronJobApprovalArgs(
                           cron_job_id=cron_id,
                           approval=user_plugin.ApiCronJobApproval(
                               reason="really important reason!",
                               notified_users=["approver1", "approver2"],
                               email_cc_addresses=["*****@*****.**"])),
                       replace=ReplaceCronAndApprovalIds)