diff --git a/README.template.md b/README.template.md index 25cd4bf..e672de1 100644 --- a/README.template.md +++ b/README.template.md @@ -188,14 +188,14 @@ The Homebrew formula installs a launchd job which can be used to automatically rotate your IAM keys daily. Unfortunately, Homebrew forumlae cannot automatically start launchd jobs, so you must manually enable it: -``` +```sh brew services start aws-rotate-iam-keys ``` A default/global configuration file for the launchd job is installed to: -``` -/usr/local/etc/aws-rotate-iam-keys +```sh +$(brew --prefix)/etc/aws-rotate-iam-keys ``` This default configuration rotates keys for your default AWS profile only. @@ -203,8 +203,8 @@ To customise the configuration, for example to rotate multiple keys, create a copy of this file named `.aws-rotate-iam-keys` in your home directory and edit it, e.g. -``` -cp /usr/local/etc/aws-rotate-iam-keys ~/.aws-rotate-iam-keys +```sh +cp $(brew --prefix)/etc/aws-rotate-iam-keys ~/.aws-rotate-iam-keys nano ~/.aws-rotate-iam-keys ``` @@ -221,7 +221,7 @@ multiple lines to the configuration, e.g. If you do customise the configuration, you can test that it works by restarting the service: -``` +```sh brew services restart aws-rotate-iam-keys ``` @@ -229,7 +229,7 @@ That's it. Your keys should have been rotated, and will now be rotated every day for you. You can use the AWS CLI to check that your access keys have been rotated as expected, e.g. -``` +```sh aws iam list-access-keys --profile default ``` @@ -237,8 +237,8 @@ If it hasn't worked, check the MacOS system log for error entries matching `aws-rotate-iam-keys`. If you can't find anything useful, the launchd job also writes output to a file in the `/tmp` directory matching the job name, e.g. -``` -/tmp/homebrew.mxcl.aws-rotate-iam-keys.log +```sh +cat /tmp/homebrew.mxcl.aws-rotate-iam-keys.log ``` ### Other Linux @@ -251,7 +251,7 @@ EDITOR=nano crontab -e Copy and paste the following line into the end of the crontab file: -``` +```cron 33 4 * * * /usr/bin/aws-rotate-iam-keys --profile default >/dev/null #rotate AWS keys daily ``` @@ -307,4 +307,4 @@ PowerShell script file: `MD5 ${WIN_MD5}` ## Changes to this file -${TEMPLATE_DISCLAIMER} \ No newline at end of file +${TEMPLATE_DISCLAIMER} diff --git a/aws-rotate-iam-keys.template.rb b/aws-rotate-iam-keys.template.rb index 7509d56..0215bcc 100644 --- a/aws-rotate-iam-keys.template.rb +++ b/aws-rotate-iam-keys.template.rb @@ -8,14 +8,12 @@ class AwsRotateIamKeys < Formula homepage "https://aws-rotate-iam-keys.com" url "${HOMEBREW_URL}" sha256 "${HOMEBREW_SHA}" - depends_on "awscli" => :recommended depends_on "gnu-getopt" depends_on "jq" + depends_on "awscli" => :recommended head do - Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '../'))) do - url %x{git config --local --get remote.origin.url | tr -d '\n'}, using: :git - end + url "https://github.com/rhyeal/aws-rotate-iam-keys.git" end def install @@ -27,7 +25,7 @@ def install end def caveats - s = <<~EOS + <<~EOS We've installed a default/global configuration file to: #{etc}/aws-rotate-iam-keys @@ -50,42 +48,17 @@ def caveats EOS end - plist_options :startup => false - - def plist; <<~EOS - - - - - EnvironmentVariables - - PATH - /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin - - Label - #{plist_name} - ProgramArguments - - /bin/bash - -c - if ! curl -s www.google.com > /dev/null; then sleep 60; fi; cp /dev/null /tmp/#{plist_name}.log ; ( egrep '^[[:space:]]*-' ~/.aws-rotate-iam-keys 2>/dev/null || cat #{etc}/aws-rotate-iam-keys ) | while read line; do aws-rotate-iam-keys §line; done - - StandardOutPath - /tmp/#{plist_name}.log - StandardErrorPath - /tmp/#{plist_name}.log - RunAtLoad - - StartCalendarInterval - - Hour - 3 - Minute - 23 - - - - EOS + def log_path + "/tmp/#{plist_name}.log" + end + service do + run ["bash", "-c", "if ! curl -s www.google.com; then sleep 60; fi; cp /dev/null #{f.log_path} ; ( grep -E ^[[:space:]]*- ~/.aws-rotate-iam-keys || cat #{etc}/aws-rotate-iam-keys ) | while read line; do #{opt_bin}/aws-rotate-iam-keys $line; done"] + run_type :cron + run_at_load true + cron "23 3 * * *" + environment_variables PATH: std_service_path_env + log_path f.log_path + error_log_path f.log_path end test do