diff --git a/emacs/init.org b/emacs/init.org index 0049bab..89ab9ac 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -4704,17 +4704,32 @@ Syntax highlighting for Dockerfiles: (leader-def-key "fSf" #'s3ed-find-file) (leader-def-key "fSs" #'s3ed-save-file) :config - (defun s3ed-open-blob-log () - "Opens the blob log at point via the cloudfront proxy." - (interactive) + (defun browse-blob-in-emacs (url bufname) + (let* ((token (password-store-get "blob-logs-token")) + (buf (generate-new-buffer bufname)) + (blob (shell-command-to-string (concat "curl " + "-s " + "--cookie 'TOKEN=" token "' " + url + " | jq")))) + (with-current-buffer buf + (insert blob) + (json-mode)) + (switch-to-buffer-other-window buf))) + + (defun s3ed-open-blob-log (arg) + "Opens the blob log at point via the cloudfront proxy. + + If given prefix arg ARG, opens in browser, otherwise opens in Emacs." + (interactive "P") (let ((fname-at-point (dired-file-name-at-point))) (if (string-match "\\(bloblogs.ops.lola.co[m]*\\)\/blobs\/\\(\\(production\\|dev\\|local\\|smoke\\|staging\\)\/[0-9]+/.*\\)" fname-at-point) - (let* ((host (match-string 1 fname-at-point)) - (path (match-string 2 fname-at-point)) - (proxy-url (format "https://%s/%s" host path))) - (browse-url proxy-url)) + (let* ((proxy-url (format "https://%s" (match-string 0 fname-at-point)))) + (if arg + (browse-url proxy-url) + (browse-blob-in-emacs proxy-url fname-at-point))) (error "Not in a blob logs directory")))) :general ((normal) s3ed-mode-map "B" #'s3ed-open-blob-log))