@flow.StateHandler()
  def Start(self):
    approval_urn = self.BuildApprovalUrn()
    subject_title = self.BuildSubjectTitle()

    # Create a new Approval object.
    approval_request = aff4.FACTORY.Create(approval_urn,
                                           aff4_type=self.approval_type,
                                           token=self.token)

    approval_request.Set(approval_request.Schema.REASON(self.args.reason))
    approval_request.AddAttribute(
        approval_request.Schema.APPROVER(self.token.username))

    # This is a break glass approval.
    break_glass = approval_request.Schema.BREAK_GLASS().Now()

    # By default a break_glass approval only lasts 24 hours.
    break_glass += 60 * 60 * 24 * 1e6
    approval_request.Set(break_glass)
    approval_request.Close(sync=True)

    # Notify the user.
    fd = aff4.FACTORY.Create(aff4.ROOT_URN.Add("users").Add(
        self.token.username), "GRRUser", mode="rw", token=self.token)

    fd.Notify("ViewObject", self.args.subject_urn,
              "An Emergency Approval has been granted to access "
              "%s." % subject_title, self.session_id)
    fd.Close()

    template = u"""
<html><body><h1>Emergency Access Granted.</h1>

The user %(username)s has requested emergency access to %(subject_title)s.
for the purpose of: "%(reason)s".

This access has been logged and granted for 24 hours.

<p>Thanks,</p>
<p>%(signature)s</p>
</body></html>"""

    body = template % dict(
        client_id=self.client_id,
        username=self.token.username,
        subject_title=subject_title,
        reason=self.args.reason,
        signature=config_lib.CONFIG["Email.signature"]),

    email_alerts.EMAIL_ALERTER.SendEmail(
        config_lib.CONFIG["Monitoring.emergency_access_email"],
        self.token.username,
        u"Emergency approval granted for %s." % subject_title,
        utils.SmartStr(body), is_html=True,
        cc_addresses=config_lib.CONFIG["Email.approval_cc_address"])
Create the Approval object and notify the Approval Granter.
dataset/ETHPy150Open google/grr/grr/lib/aff4_objects/security.py/BreakGlassGrantApprovalWithReasonFlow.Start