Make blob logger easier to debug

This commit is contained in:
Jeremy Dormitzer 2020-05-18 10:34:14 -04:00
parent 8f2ec38efe
commit a38ec79c88

View File

@ -5115,8 +5115,8 @@ Syntax highlighting for Dockerfiles:
#+BEGIN_SRC emacs-lisp
(use-package s3ed
:commands (s3ed-mode
s3ed-find-file
s3ed-save-file)
s3ed-find-file
s3ed-save-file)
:init
(jdormit/define-prefix "fS" "s3")
(leader-def-key "fSf" #'s3ed-find-file)
@ -5124,16 +5124,22 @@ Syntax highlighting for Dockerfiles:
:config
(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)))
(buf (generate-new-buffer bufname))
(blob (shell-command-to-string (concat "curl "
"-s "
"--cookie 'TOKEN=" token "' "
url)))
(status
(with-current-buffer buf
(insert blob)
(json-mode)
(format-all-buffer))))
(if (not (equal status "Formatting error"))
(switch-to-buffer-other-window buf)
(with-current-buffer buf
(set-buffer-modified-p nil)
(kill-buffer))
(switch-to-buffer-other-window "*format-all-errors*"))))
(defun s3ed-open-blob-log (arg)
"Opens the blob log at point via the cloudfront proxy.
@ -5141,14 +5147,14 @@ Syntax highlighting for Dockerfiles:
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* ((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"))))
(if (string-match
"\\(bloblogs.ops.lola.co[m]*\\)\/blobs\/\\(\\(production\\|dev\\|local\\|smoke\\|staging\\)\/[0-9]+/.*\\)"
fname-at-point)
(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))
#+END_SRC