-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (51 loc) · 1.58 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Variables
# ---------
OP_VAULT := perf
# Utilies
# ---------
# increment the parameter.
incr = $(shell echo $$(($(1)+1)))
# extract a list of fields secrets values from a 1password item
# usage: $(call op_secrets,my_vault,my_item,my_fields)
op_secrets = $(shell op item get --vault=$(1) --fields=$(shell echo $(3)| sed "s/ /,/g") -- "$(2)")
# extract one secret from secrets returned by op_secrets (space separated)
# usage: $(call op_secret,my_secrets,1)
op_secret = $(shell echo $(1) |cut -d, -f$(2))
# return KEY=VALUE envs list.
op_env = $(eval secrets=$(2)) \
$(eval i=1) \
$(foreach k,$(1), \
$(k)=$(shell echo $(secrets)|cut -d',' -f$(i)) \
$(eval i=$(call incr,($i))))
# Utilies
# ---------
aws_keys = AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION AWS_BUCKET
aws_fields = username password region bucket
aws_secrets = $(call op_secrets,$(OP_VAULT),AWS S3,$(aws_fields))
aws_env = $(call op_env,$(aws_keys),$(aws_secrets))
# Infos
# -----
.PHONY: help check-op build run
## Display this help screen
help:
@printf "\e[36m%-35s %s\e[0m\n" "Command" "Usage"
@sed -n -e '/^## /{'\
-e 's/## //g;'\
-e 'h;'\
-e 'n;'\
-e 's/:.*//g;'\
-e 'G;'\
-e 's/\n/ /g;'\
-e 'p;}' Makefile | awk '{printf "\033[33m%-35s\033[0m%s\n", $$1, substr($$0,length($$1)+1)}'
check-op:
@op vault get $(OP_VAULT) > /dev/null
## build program
build:
@go build
## build and run program locally with env vars from 1password
run: build check-op
@export $(aws_env) && \
./perf-fmt --dev $(filter-out $@,$(MAKECMDGOALS))
## echo env vars. usage: $ export $(env)
env: check-op
@echo $(aws_env)