def post(self, user_id=None, name=None, key_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) delete_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() AuditLog.log(self.session, self.current_user.id, 'delete_public_key', 'Deleted public key: {}'.format(key.fingerprint), on_user_id=user.id) email_context = { "actioner": self.current_user.name, "changed_user": user.name, "action": "removed", } send_email(self.session, [user.name], 'Public SSH key removed', 'ssh_keys_changed', settings, email_context) return self.redirect("/users/{}?refresh=yes".format(user.name))
def post(self, user_id=None, name=None, key_id=None, tag_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() tag = PublicKeyTag.get(self.session, id=tag_id) if not tag: return self.notfound() try: remove_tag_from_public_key(self.session, key, tag) except TagNotOnKey: return self.redirect("/users/{}?refresh=yes".format(user.name)) AuditLog.log(self.session, self.current_user.id, 'untag_public_key', 'Untagged public key: {}'.format(key.fingerprint), on_tag_id=tag.id, on_user_id=user.id) return self.redirect("/users/{}?refresh=yes".format(user.name))
def post(self, user_id=None, name=None, key_id=None, tag_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() tag = PublicKeyTag.get(self.session, id=tag_id) if not tag: return self.notfound() try: remove_tag_from_public_key(self.session, key, tag) except TagNotOnKey: return self.redirect("/users/{}?refresh=yes".format(user.name)) AuditLog.log( self.session, self.current_user.id, "untag_public_key", "Untagged public key: {}".format(key.fingerprint_sha256), on_tag_id=tag.id, on_user_id=user.id, ) return self.redirect("/users/{}?refresh=yes".format(user.name))
def post(self, user_id=None, name=None, key_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) delete_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() AuditLog.log(self.session, self.current_user.id, 'delete_public_key', 'Deleted public key: {}'.format(key.fingerprint_sha256), on_user_id=user.id) email_context = { "actioner": self.current_user.name, "changed_user": user.name, "action": "removed", } send_email(self.session, [user.name], 'Public SSH key removed', 'ssh_keys_changed', settings, email_context) return self.redirect("/users/{}?refresh=yes".format(user.name))
def post(self, user_id=None, name=None, key_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() form = PublicKeyAddTagForm(self.request.arguments) form.tagname.choices = [] for tag in self.session.query(PublicKeyTag).filter_by( enabled=True).all(): form.tagname.choices.append([tag.name, tag.name]) if not form.validate(): return self.render("public-key-add-tag.html", form=form, user=user, key=key, alerts=self.get_form_alerts(form.errors)) tag = PublicKeyTag.get(self.session, name=form.data["tagname"]) if not tag: form.tagname.errors.append("Unknown tag name {}".format( form.data["tagname"])) return self.render("public-key-add-tag.html", form=form, user=user, key=key, alerts=self.get_form_alerts(form.errors)) try: add_tag_to_public_key(self.session, key, tag) except DuplicateTag: return self.render("public-key-add-tag.html", form=form, user=user, key=key, alerts=["This key already has that tag!"]) AuditLog.log(self.session, self.current_user.id, 'tag_public_key', 'Tagged public key: {}'.format(key.fingerprint_sha256), on_tag_id=tag.id, on_user_id=user.id) return self.redirect("/users/{}?refresh=yes".format(user.name))
def get(self, user_id=None, name=None, key_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() self.render("public-key-delete.html", user=user, key=key)
def get(self, *args: Any, **kwargs: Any) -> None: name = self.get_path_argument("name") key_id = int(self.get_path_argument("key_id")) user = User.get(self.session, name=name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() self.render("public-key-delete.html", user=user, key=key)
def post(self, user_id=None, name=None, key_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() form = PublicKeyAddTagForm(self.request.arguments) form.tagname.choices = [] for tag in self.session.query(PublicKeyTag).filter_by(enabled=True).all(): form.tagname.choices.append([tag.name, tag.name]) if not form.validate(): return self.render( "public-key-add-tag.html", form=form, user=user, key=key, alerts=self.get_form_alerts(form.errors) ) tag = PublicKeyTag.get(self.session, name=form.data["tagname"]) if not tag: form.tagname.errors.append("Unknown tag name {}".format(form.data["tagname"])) return self.render( "public-key-add-tag.html", form=form, user=user, key=key, alerts=self.get_form_alerts(form.errors) ) try: add_tag_to_public_key(self.session, key, tag) except DuplicateTag: return self.render( "public-key-add-tag.html", form=form, user=user, key=key, alerts=["This key already has that tag!"] ) AuditLog.log(self.session, self.current_user.id, 'tag_public_key', 'Tagged public key: {}'.format(key.fingerprint_sha256), on_tag_id=tag.id, on_user_id=user.id) return self.redirect("/users/{}?refresh=yes".format(user.name))
def get(self, *args, **kwargs): # type: (*Any, **Any) -> None user_id = kwargs.get("user_id") # type: Optional[int] name = kwargs.get("name") # type: Optional[str] key_id = kwargs["key_id"] # type: int user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() self.render("public-key-delete.html", user=user, key=key)
def get(self, user_id=None, name=None, key_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() form = PublicKeyAddTagForm() form.tagname.choices = [] for tag in self.session.query(PublicKeyTag).filter_by(enabled=True).all(): form.tagname.choices.append([tag.name, tag.name]) self.render("public-key-add-tag.html", user=user, key=key, form=form)
def post(self, *args, **kwargs): # type: (*Any, **Any) -> None user_id = kwargs.get("user_id") # type: Optional[int] name = kwargs.get("name") # type: Optional[str] key_id = kwargs["key_id"] # type: int user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) delete_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() AuditLog.log( self.session, self.current_user.id, "delete_public_key", "Deleted public key: {}".format(key.fingerprint_sha256), on_user_id=user.id, ) email_context = { "actioner": self.current_user.name, "changed_user": user.name, "action": "removed", } send_email( self.session, [user.name], "Public SSH key removed", "ssh_keys_changed", settings(), email_context, ) return self.redirect("/users/{}?refresh=yes".format(user.name))
def get(self, user_id=None, name=None, key_id=None): user = User.get(self.session, user_id, name) if not user: return self.notfound() if not self.check_access(self.session, self.current_user, user): return self.forbidden() try: key = get_public_key(self.session, user.id, key_id) except KeyNotFound: return self.notfound() form = PublicKeyAddTagForm() form.tagname.choices = [] for tag in self.session.query(PublicKeyTag).filter_by( enabled=True).all(): form.tagname.choices.append([tag.name, tag.name]) self.render("public-key-add-tag.html", user=user, key=key, form=form)