-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (60 loc) · 2.16 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# dcape-config-cli Makefile
SHELL = /bin/bash
CFG = .env
# CIS access token
CIS_TOKEN ?= set_from_cis_site_data
# Config store url
ENFIST_URL ?= http://cis.dev.lan/conf/api
-include $(CFG)
export
.PHONY: all help ls cat get set del
all: help
# ------------------------------------------------------------------------------
## get env tag list store, `make ls`
ls:
@echo -e "** Configs at server $${ENFIST_URL}:\n" ; \
curl -gs -H "X-narra-token:$$CIS_TOKEN" "$${ENFIST_URL}/tag/" | jq -r '.[].code'
## cat data of env tag from store, `make cat TAG=app--config--tag[.env]`
cat:
@[[ "$(TAG)" ]] || { echo "Error: Tag value required" ; exit 1 ;}
@echo "Getting env into $(TAG)" \
&& tag=$${TAG%.env} \
&& curl -gs -H "X-narra-token:$$CIS_TOKEN" "$${ENFIST_URL}/tag_vars/?code=$$tag" | jq -r '.'
## get env tag from store, `make get TAG=app--config--tag[.env]`
get:
@[[ "$(TAG)" ]] || { echo "Error: Tag value required" ; exit 1 ;}
@echo "Getting env into $(TAG)" \
&& tag=$${TAG%.env} \
&& curl -gs -H "X-narra-token:$$CIS_TOKEN" "$${ENFIST_URL}/tag_vars/?code=$$tag" \
| jq -r '.' > $${tag}.env
## set env tag in store, `make set TAG=app--config--tag[.env]`
set:
@[[ "$(TAG)" ]] || { echo "Error: Tag value required" ; exit 1 ;}
@echo "Setting $(TAG) from file" \
&& tag=$${TAG%.env} \
&& jq -R -sc ". | {\"code\":\"$$tag\",\"data\":.}" < $${tag}.env \
| curl -gsd @- -H "X-narra-token:$$CIS_TOKEN" "$${ENFIST_URL}/tag_set/" | jq '.'
## del env tag from store, `make del TAG=app--config--tag[.env]`
del:
@[[ "$(TAG)" ]] || { echo "Error: Tag value required" ; exit 1 ;}
@echo "Deleting $(TAG)" \
&& tag=$${TAG%.env} \
&& curl -gs -H "X-narra-token:$$CIS_TOKEN" "$${ENFIST_URL}/tag_del/?code=$$tag" | jq '.'
define CONFIG_DEF
# dcape-app-config config file, generated by make init
# CIS access token
# from gitea's /user/settings/applications
CIS_TOKEN=$(CIS_TOKEN)
# Config store url
ENFIST_URL=$(ENFIST_URL)
endef
export CONFIG_DEF
## create .env file
$(CFG):
@echo "*** $@ ***"
@[ -f $@ ] || { echo "$$CONFIG_DEF" > $@ ; echo >&2 "Created default $@" ; }
help:
@grep -A 1 "^##" Makefile | less
##
## Press 'q' for exit
##