Ejemplo n.º 1
0
    def CreateApproval(
        self,
        reason: str,
        notified_users: Sequence[str],
        email_cc_addresses: Optional[Sequence[str]] = None,
    ) -> HuntApproval:
        """Create a new approval for the current user to access this hunt."""

        if not reason:
            raise ValueError("reason can't be empty")

        if not notified_users:
            raise ValueError("notified_users list can't be empty.")

        if email_cc_addresses is None:
            email_cc_addresses = []

        approval = user_pb2.ApiHuntApproval(
            reason=reason,
            notified_users=notified_users,
            email_cc_addresses=email_cc_addresses)
        args = user_pb2.ApiCreateHuntApprovalArgs(hunt_id=self.hunt_id,
                                                  approval=approval)

        data = self._context.SendRequest("CreateHuntApproval", args)
        if not isinstance(data, user_pb2.ApiHuntApproval):
            raise TypeError(f"unexpected response type: '{type(data)}'")

        return HuntApproval(data=data,
                            username=self._context.username,
                            context=self._context)
Ejemplo n.º 2
0
  def CreateApproval(self,
                     reason=None,
                     notified_users=None,
                     email_cc_addresses=None):
    """Create a new approval for the current user to access this hunt."""

    if not reason:
      raise ValueError("reason can't be empty")

    if not notified_users:
      raise ValueError("notified_users list can't be empty.")

    approval = user_pb2.ApiHuntApproval(
        reason=reason,
        notified_users=notified_users,
        email_cc_addresses=email_cc_addresses or [])
    args = user_pb2.ApiCreateHuntApprovalArgs(
        hunt_id=self.hunt_id, approval=approval)

    data = self._context.SendRequest("CreateHuntApproval", args)
    return HuntApproval(
        data=data, username=self._context.username, context=self._context)