-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
81 lines (69 loc) · 2.13 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
80
81
# Build the library with the specified tool chain. Defaults to x86_64-unknown-linux-gnu
.PHONY: build
TOOL_CHAIN ?= x86_64-unknown-linux-gnu
build: format
cargo clippy
cargo build --target=$(TOOL_CHAIN) --release
# Build documentation for the library
.PHONY: doc
doc:
cargo fmt --check
cargo doc --no-deps
# Run all tests (no coverage)
.PHONY: test
test: format check-env
cargo test
# Clean up
.PHONY: clean
clean:
cargo clean
# ==== Directives for developers ====
# Run unit and integration tests and measure coverage.
# Additional flags can be passed with LLVM_COV_ARGS
.PHONY: test-coverage
test-coverage: check-env
cargo llvm-cov $(LLVM_COV_ARGS)
# Run only documentation tests (shorthand for developers)
.PHONY: doc-test
doc-test: format check-env
cargo test --doc
# Run only unit tests (shorthand for developers)
.PHONY: unit-test
unit-test: format
cargo test --lib
# Run only integration tests (shorthand for developers)
.PHONY: integration-test
integration-test: format check-env
cargo test --tests
# ==== Helper directives ====
# Format codebase
.PHONY: format
format:
cargo fmt
# Download and decode the public key from KMS
.PHONY: fetch-public-key
PUBLIC_KEY_FILE_PATH = ./tests/data/pub-key
PUBLIC_KEY_FILE_PEM = $(PUBLIC_KEY_FILE_PATH).pem
PUBLIC_KEY_FILE_DER = $(PUBLIC_KEY_FILE_PATH).der
fetch-public-key: check-env
@aws kms get-public-key \
--region $(AWS_REGION) \
--key-id $(KMS_KEY_ID) \
--output text \
--query PublicKey > $(PUBLIC_KEY_FILE_PEM) || \
(echo "Failed to fetch public key" && exit 1)
@cat $(PUBLIC_KEY_FILE_PEM) | base64 -d > $(PUBLIC_KEY_FILE_DER)
@echo "Public key saved to $(PUBLIC_KEY_FILE_PEM) and decoded to $(PUBLIC_KEY_FILE_DER)"
# Check if the environment variables are set and STS token is valid
.PHONY: check-env
check-env:
ifndef KMS_KEY_ID
$(error KMS_KEY_ID is not set)
endif
ifndef AWS_REGION
$(error AWS_REGION is not set)
endif
@aws --version &> /dev/null || (echo "AWS CLI not installed" && exit 1)
@aws sts get-caller-identity &> /dev/null || \
(echo "AWS CLI could not assume role. Did the STS token expire?" && exit 1)
@echo "Environment variables are set and the STS token is valid"