Add AWS utilities
This commit is contained in:
parent
9cd8d7d414
commit
8ccb8bf9c5
44
emacs/.emacs.d/config/init-aws.el
Normal file
44
emacs/.emacs.d/config/init-aws.el
Normal file
@ -0,0 +1,44 @@
|
||||
;; -*- 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)
|
||||
|
||||
(setq aws-current-profile (getenv "AWS_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)
|
||||
(setq aws-current-profile profile))
|
||||
|
||||
;; 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"))))
|
||||
|
||||
(provide 'init-aws)
|
@ -75,6 +75,7 @@
|
||||
(require 'init-yaml)
|
||||
(require 'init-terraform)
|
||||
(require 'init-run-command)
|
||||
(require 'init-aws)
|
||||
|
||||
;; Load the custom file
|
||||
(when (file-exists-p custom-file)
|
||||
|
Loading…
Reference in New Issue
Block a user