-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevenv.nix
More file actions
134 lines (117 loc) · 4.42 KB
/
Copy pathdevenv.nix
File metadata and controls
134 lines (117 loc) · 4.42 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
pkgs,
lib,
config,
inputs,
...
}: {
languages = {
c.enable = true;
rust.enable = true;
};
dotenv = {
enable = true;
filename = [".env" ".env.local"];
};
packages = with pkgs; [alejandra bat cargo-audit cargo-deny just jq];
enterTest = ''
cargo test
cargo clippy
cargo deny check
cargo audit -f ${./Cargo.nix.lock} --json | ${lib.getExe pkgs.jq} -e '. as $expression | $expression, ($expression | .vulnerabilities.found | not)'
'';
git-hooks.hooks = {
rustfmt.enable = true;
clippy.enable = true;
};
scripts = {
setup-business-api.exec = ''
if [ -d .setup-business-api ]; then
echo "Remove the .setup-business-api directory before continuing if you want to start from scratch."
echo
pushd .setup-business-api &> /dev/null
else
mkdir .setup-business-api
pushd .setup-business-api &> /dev/null
${lib.getExe pkgs.openssl} genrsa -out privatecert.pem 2048
${lib.getExe pkgs.openssl} req -new -x509 -key privatecert.pem -out publiccert.cer -days 1825 -subj "/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=example.com"
echo "Certificate contents:"
bat --style=header-filename,grid publiccert.cer
echo "- Upload certificate to the API certificates section:"
echo " - Follow: https://developer.revolut.com/docs/guides/manage-accounts/get-started/make-your-first-api-request#upload-your-certificate"
echo " - Enter:"
echo " - OAuth redirect URI: https://example.com"
echo -n "Enter provided client ID: "
read client_id
echo "Generating client assertion..."
cat <<EOF > header.json
{
"alg": "RS256",
"typ": "JWT"
}
EOF
cat <<EOF > payload.json
{
"iss": "example.com",
"sub": "$client_id",
"aud": "https://revolut.com",
"exp": 1761663836
}
EOF
cat header.json | tr -d '\n' | tr -d '\r' | ${lib.getExe pkgs.openssl} enc -base64 -A | tr +/ -_ | tr -d '=' > client_assertion.txt
echo -n "." >> client_assertion.txt
cat payload.json | tr -d '\n' | tr -d '\r' | ${lib.getExe pkgs.openssl} enc -base64 -A | tr +/ -_ | tr -d '=' >> client_assertion.txt
cat client_assertion.txt | tr -d '\n' | tr -d '\r' | ${lib.getExe pkgs.openssl} dgst -sha256 -sign privatecert.pem | ${lib.getExe pkgs.openssl} enc -base64 -A | tr +/ -_ | tr -d '=' > sign.txt
echo -n "." >> client_assertion.txt
cat sign.txt >> client_assertion.txt
echo "Client assertion:"
bat --style=header-filename,grid client_assertion.txt
echo
echo "- Click on the 'API certificate' you have created"
echo "- Click on 'Enable access' and retrieve the 'code' from the URI GET argument after authorizing the account access"
echo -n "Enter provided code in the URI GET argument 'code': "
read code
REVOLUT_CLIENT_ASSERTION="$(cat client_assertion.txt)" REVOLUT_AUTHORIZATION_CODE="$code" just retrieve-access-token 2> /dev/null > access_token.txt
fi
REFRESH_TOKEN=$(jq -r .refresh_token access_token.txt)
cat <<'EOF' | sed s/__CLIENT_ASSERTION__/$(cat client_assertion.txt)/g | sed s/__REFRESH_TOKEN__/$REFRESH_TOKEN/g | bat --language=markdown --decorations=never
# Setup
Environment variables that can be used with the example binaries in this crate:
```
export REVOLUT_CLIENT_ASSERTION="__CLIENT_ASSERTION__"
export REVOLUT_REFRESH_TOKEN="__REFRESH_TOKEN__"
```
For example, you can run:
```
REVOLUT_CLIENT_ASSERTION="__CLIENT_ASSERTION__" REVOLUT_REFRESH_TOKEN="__REFRESH_TOKEN__" just list-accounts | jq
```
EOF
popd &> /dev/null
'';
};
outputs = {
revolut = pkgs.rustPlatform.buildRustPackage {
name = "revolut";
cargoLock.lockFile = ./Cargo.nix.lock;
postPatch = ''
ln -sf ${./Cargo.nix.lock} Cargo.lock
'';
buildPhase = ''
runHook preBuild
cargo build --release --examples
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
ls -1 $src/examples | sed 's/\.rs$//' | \
xargs -I{} sh -c 'cp target/release/examples/{} $out/bin/$(echo {} | sed 's/_/-/g')'
runHook postInstall
'';
src = ./.;
env = {
GIT_REVISION = "devenv";
};
};
};
}