2021-02-21 03:02:19 +00:00
|
|
|
;; -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;; Manage AWS profiles
|
|
|
|
(defvar aws-profiles '("default")
|
|
|
|
"AWS profile names")
|
|
|
|
(defvar aws-current-profile nil
|
|
|
|
"Currently active AWS profile")
|
|
|
|
|
|
|
|
(defun aws-local-profile ()
|
|
|
|
(make-local-variable 'aws-current-profile))
|
|
|
|
|
|
|
|
(add-hook 'eshell-mode-hook #'aws-local-profile)
|
|
|
|
(add-hook 'vterm-mode-hook #'aws-local-profile)
|
|
|
|
(add-hook 'term-mode-hook #'aws-local-profile)
|
|
|
|
|
|
|
|
(add-to-list 'aws-profiles "personal")
|
|
|
|
(add-to-list 'aws-profiles "lola-cde")
|
|
|
|
|
|
|
|
(defun aws-switch-profile (profile)
|
|
|
|
(interactive (list (completing-read "Profile: " aws-profiles)))
|
|
|
|
(setenv "AWS_PROFILE" profile)
|
2021-02-23 03:54:32 +00:00
|
|
|
(when (eq major-mode 'vterm-mode)
|
|
|
|
(vterm-send-C-e)
|
|
|
|
(vterm-send-C-u)
|
|
|
|
(vterm-send-string (format "export AWS_PROFILE=%s\n" profile)))
|
2021-02-21 03:02:19 +00:00
|
|
|
(setq aws-current-profile profile))
|
|
|
|
|
2021-02-23 03:54:32 +00:00
|
|
|
(add-hook 'emacs-startup-hook
|
|
|
|
(lambda ()
|
|
|
|
(aws-switch-profile "default")))
|
|
|
|
|
2021-02-21 03:02:19 +00:00
|
|
|
;; A command to MFA to AWS
|
|
|
|
(defun aws-mfa (mfa-token)
|
|
|
|
(interactive (list
|
|
|
|
(let ((prompt (if aws-current-profile
|
|
|
|
(format "MFA code for %s: " aws-current-profile)
|
|
|
|
"MFA code: ")))
|
|
|
|
(read-from-minibuffer prompt))))
|
|
|
|
(let ((proc (start-process "aws-mfa"
|
|
|
|
"*aws-mfa*"
|
|
|
|
"aws-mfa"
|
|
|
|
"--force")))
|
|
|
|
(set-process-sentinel
|
|
|
|
proc
|
|
|
|
(make-success-err-msg-sentinel "*aws-mfa*"
|
|
|
|
"AWS MFA succeeded"
|
|
|
|
"AWS MFA failed, check *aws-mfa* buffer for details"))
|
|
|
|
(process-send-string proc (concat mfa-token "\n"))))
|
|
|
|
|
2021-02-23 00:36:56 +00:00
|
|
|
;; A dired interface to S3
|
|
|
|
(use-package s3ed
|
|
|
|
:commands (s3ed-find-file
|
|
|
|
s3ed-save-file))
|
|
|
|
|
2021-02-21 03:02:19 +00:00
|
|
|
(provide 'init-aws)
|