Add ability to open blob logs in Emacs

This commit is contained in:
Jeremy Dormitzer 2020-04-22 16:48:52 -04:00
parent 56a332187b
commit 71f995464e

View File

@ -4704,17 +4704,32 @@ Syntax highlighting for Dockerfiles:
(leader-def-key "fSf" #'s3ed-find-file) (leader-def-key "fSf" #'s3ed-find-file)
(leader-def-key "fSs" #'s3ed-save-file) (leader-def-key "fSs" #'s3ed-save-file)
:config :config
(defun s3ed-open-blob-log () (defun browse-blob-in-emacs (url bufname)
"Opens the blob log at point via the cloudfront proxy." (let* ((token (password-store-get "blob-logs-token"))
(interactive) (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))) (let ((fname-at-point (dired-file-name-at-point)))
(if (string-match (if (string-match
"\\(bloblogs.ops.lola.co[m]*\\)\/blobs\/\\(\\(production\\|dev\\|local\\|smoke\\|staging\\)\/[0-9]+/.*\\)" "\\(bloblogs.ops.lola.co[m]*\\)\/blobs\/\\(\\(production\\|dev\\|local\\|smoke\\|staging\\)\/[0-9]+/.*\\)"
fname-at-point) fname-at-point)
(let* ((host (match-string 1 fname-at-point)) (let* ((proxy-url (format "https://%s" (match-string 0 fname-at-point))))
(path (match-string 2 fname-at-point)) (if arg
(proxy-url (format "https://%s/%s" host path))) (browse-url proxy-url)
(browse-url proxy-url)) (browse-blob-in-emacs proxy-url fname-at-point)))
(error "Not in a blob logs directory")))) (error "Not in a blob logs directory"))))
:general :general
((normal) s3ed-mode-map "B" #'s3ed-open-blob-log)) ((normal) s3ed-mode-map "B" #'s3ed-open-blob-log))