Skip to content

Commit

Permalink
Shellcheck pass.
Browse files Browse the repository at this point in the history
* Adding shellcheck to shell.nix.
* Running shellcheck over some of our nix-written shell scripts.
* Fixing the warnings it throws up.
  • Loading branch information
Kris Jenkins authored and krisajenkins committed Oct 21, 2020
1 parent 0658923 commit daa957a
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 22 deletions.
45 changes: 27 additions & 18 deletions deployment/default.nix
Expand Up @@ -5,6 +5,8 @@ let
terraform = (callPackage ./terraform.nix { }).terraform_0_12;

getCreds = pkgs.writeShellScript "getcreds" ''
set -eou pipefail
if [[ $# -ne 2 ]]; then
echo "Please call the script with your AWS account username followed by the MFA code"
exit 1
Expand All @@ -14,7 +16,7 @@ let
unset AWS_SECRET_ACCESS_KEY
unset AWS_ACCESS_KEY_ID
${awscli}/bin/aws sts get-session-token --serial-number arn:aws:iam::454236594309:mfa/$1 --output text --duration-seconds 86400 --token-code $2 \
${awscli}/bin/aws sts get-session-token --serial-number "arn:aws:iam::454236594309:mfa/$1" --output text --duration-seconds 86400 --token-code "$2" \
| awk '{printf("export AWS_ACCESS_KEY_ID=%s\nexport AWS_SECRET_ACCESS_KEY=\"%s\"\nexport AWS_SESSION_TOKEN=\"%s\"\n",$2,$4,$5)}'
'';

Expand All @@ -41,33 +43,38 @@ let

syncS3 = env:
writeShellScript "syncs3" ''
set -eou pipefail
echo "sync with S3"
${awscli}/bin/aws s3 cp --recursive ${plutus-playground.client} s3://plutus-playground-website-${env}/
${awscli}/bin/aws s3 cp --recursive ${marlowe-playground.client} s3://marlowe-playground-website-${env}/
${awscli}/bin/aws s3 cp --recursive ${marlowe-playground.tutorial} s3://marlowe-playground-website-${env}/tutorial
'';

syncPlutusTutorial = env:
writeShellScript "syncPlutusTutorial" ''
set -eou pipefail
echo "sync plutus tutorial with S3"
${awscli}/bin/aws s3 sync --delete ${plutus-playground.tutorial} s3://plutus-playground-website-${env}/tutorial
${awscli}/bin/aws s3 cp --recursive ${plutus-playground.tutorial} s3://plutus-playground-website-${env}/tutorial
'';

applyTerraform = env: region:
writeShellScript "deploy" ''
set -e
set -eou pipefail
tmp_dir=$(mktemp -d)
echo "using tmp_dir $tmp_dir"
ln -s ${./terraform}/* $tmp_dir
ln -s ${./terraform}/* "$tmp_dir"
# in case we have some tfvars around in ./terraform
rm $tmp_dir/*.tfvars | true
rm "$tmp_dir/*.tfvars" || true
ln -s ${terraform-locals env}/* $tmp_dir
ln -s ${terraform-vars env region}/* $tmp_dir
cd $tmp_dir
ln -s ${terraform-locals env}/* "$tmp_dir"
ln -s ${terraform-vars env region}/* "$tmp_dir"
cd "$tmp_dir"
echo "read secrets"
TF_VAR_marlowe_github_client_id=$(pass ${env}/marlowe/githubClientId)
Expand All @@ -94,13 +101,14 @@ let
region=$(${terraform}/bin/terraform output region)
echo "deploy api"
${awscli}/bin/aws apigateway create-deployment --region $region --rest-api-id $marlowe_api_id --stage-name ${env}
${awscli}/bin/aws apigateway create-deployment --region $region --rest-api-id $plutus_api_id --stage-name ${env}
${awscli}/bin/aws apigateway create-deployment --region "$region" --rest-api-id "$marlowe_api_id" --stage-name ${env}
${awscli}/bin/aws apigateway create-deployment --region "$region" --rest-api-id "$plutus_api_id" --stage-name ${env}
'';

deploy = env: region:
writeShellScript "deploy" ''
set -e
set -eou pipefail
${applyTerraform env region}
${syncS3 env}
${syncPlutusTutorial env}
Expand All @@ -109,18 +117,19 @@ let

destroy = env: region:
writeShellScript "destroy" ''
set -e
set -eou pipefail
tmp_dir=$(mktemp -d)
echo "using tmp_dir $tmp_dir"
ln -s ${./terraform}/* $tmp_dir
ln -s ${./terraform}/* "$tmp_dir"
# in case we have some tfvars around in ./terraform
rm $tmp_dir/*.tfvars | true
rm "$tmp_dir/*.tfvars" || true
ln -s ${terraform-locals env}/* $tmp_dir
ln -s ${terraform-vars env region}/* $tmp_dir
cd $tmp_dir
ln -s ${terraform-locals env}/* "$tmp_dir"
ln -s ${terraform-vars env region}/* "$tmp_dir"
cd "$tmp_dir"
echo "apply terraform"
export TF_VAR_marlowe_github_client_id=$(pass ${env}/marlowe/githubClientId)
Expand All @@ -131,7 +140,7 @@ let
export TF_VAR_plutus_jwt_signature=$(pass ${env}/plutus/jwtSignature)
${terraform}/bin/terraform init
${terraform}/bin/terraform workspace select ${env}
${terraform}/bin/terraform destroy -var-file=${env}.tfvars
${terraform}/bin/terraform destroy -var-file=${env}.tfvars
'';

mkEnv = env: region: {
Expand Down
31 changes: 27 additions & 4 deletions nix/dev.nix
Expand Up @@ -13,19 +13,32 @@ pkgs.recurseIntoAttrs (rec {
spago = easyPS.spago;
};

metadataQueryPayload = {
subjects = [
"44b57ee30cdb55829d0a5d4f046baef078f1e97a7f21b62d75f8e96ea139c35f"
"7f71940915ea5fe85e840f843c929eba467e6f050475bad1f10b9c274d1888c0"
];
properties = [
"name"
"description"
];
};

scripts = pkgs.recurseIntoAttrs {
updateMaterialized = haskell.project.stack-nix.passthru.updateMaterialized;

fixStylishHaskell = pkgs.writeScriptBin "fix-stylish-haskell" ''
#!${pkgs.runtimeShell}
set -eou pipefail
${pkgs.git}/bin/git diff > pre-stylish.diff
${pkgs.fd}/bin/fd \
--extension hs \
--exclude '*/dist/*' \
--exclude '*/docs/*' \
--exec ${packages.stylish-haskell}/bin/stylish-haskell -i {}
${pkgs.git}/bin/git diff > post-stylish.diff
diff pre-stylish.diff post-stylish.diff > /dev/null
if [ $? != 0 ]
if (diff pre-stylish.diff post-stylish.diff > /dev/null)
then
echo "Changes by stylish have been made. Please commit them."
else
Expand All @@ -36,6 +49,9 @@ pkgs.recurseIntoAttrs (rec {
'';

fixPurty = pkgs.writeScriptBin "fix-purty" ''
#!${pkgs.runtimeShell}
set -eou pipefail
${pkgs.git}/bin/git diff > pre-purty.diff
${pkgs.fd}/bin/fd \
--extension purs \
Expand All @@ -45,8 +61,7 @@ pkgs.recurseIntoAttrs (rec {
--exclude '*/generated/*' \
--exec ${packages.purty}/bin/purty --write {}
${pkgs.git}/bin/git diff > post-purty.diff
diff pre-purty.diff post-purty.diff > /dev/null
if [ $? != 0 ]
if (diff pre-purty.diff post-purty.diff > /dev/null)
then
echo "Changes by purty have been made. Please commit them."
else
Expand All @@ -58,6 +73,7 @@ pkgs.recurseIntoAttrs (rec {

# See note on 'easyPS' in 'default.nix'
updateClientDeps = pkgs.lib.meta.addMetaAttrs { platforms = pkgs.lib.platforms.linux; } (pkgs.writeScriptBin "update-client-deps" ''
#!${pkgs.runtimeShell}
set -eou pipefail
export PATH=${pkgs.gccStdenv.lib.makeBinPath [
Expand Down Expand Up @@ -96,6 +112,9 @@ pkgs.recurseIntoAttrs (rec {
'');

updateMetadataSamples = pkgs.writeScriptBin "update-metadata-samples" ''
#!${pkgs.runtimeShell}
set -eou pipefail
SERVER=https://api.cardano.org/staging
SUBJECT=7f71940915ea5fe85e840f843c929eba467e6f050475bad1f10b9c274d1888c0
DATA_DIR=plutus-scb/test/Cardano/Metadata
Expand All @@ -106,6 +125,10 @@ pkgs.recurseIntoAttrs (rec {
do
${pkgs.curl}/bin/curl -o $DATA_DIR/property_$PROPERTY.json $SERVER/metadata/$SUBJECT/properties/$PROPERTY
done
${pkgs.curl}/bin/curl -X POST -o $DATA_DIR/query_response1.json $SERVER/metadata/query \
-H 'Content-Type: application/json' \
-d '${builtins.toJSON metadataQueryPayload}'
'';
};
})
5 changes: 5 additions & 0 deletions plutus-scb/test/Cardano/Metadata/TypesSpec.hs
Expand Up @@ -65,6 +65,11 @@ jsonTests =
assertDecodes
@(SubjectProperties 'ExternalEncoding)
"test/Cardano/Metadata/subject_response1.json"
, testCase "Batch query response" $
void $
assertDecodes
@[SubjectProperties 'ExternalEncoding]
"test/Cardano/Metadata/query_response1.json"
]
]

Expand Down
71 changes: 71 additions & 0 deletions plutus-scb/test/Cardano/Metadata/query_response1.json
@@ -0,0 +1,71 @@
[
{
"subject": "7f71940915ea5fe85e840f843c929eba467e6f050475bad1f10b9c274d1888c0",
"owner": {
"signature": "62e800b8c540b218396174f9c42fc253ab461961e20a4cc8ed4ba8b3fdff760cf8422e80d2504829a1d84458093880f02629524416f895b802cb9211f5145808",
"publicKey": "25912b3081c20782aaa576af51ef3b17d7370d9fdf6641fec28012678ac1d179"
},
"description": {
"value": "A sample description",
"anSignatures": [
{
"signature": "83ef5c04882e43e5f1c8e9bc386bd51cdda163f5cbd1996d1d066238de063d4b79b1648b48aec63dddff05649911ca116579842c8e9a08a3bc7ae1a0ec7ef000",
"publicKey": "1446c9d327b0f07aa691014c08578867674f3a88b36f2017a58c37a8a7799058"
},
{
"signature": "4e29a00feaeb24b25315f0eac28bbfc550dabfb847bf6a06cb8086120201f90c64fab778037d0ef009ab4669121a38fe9b8c0a6aec99c68366c5187c0889520a",
"publicKey": "1910312a9a6998c7e4f585dc138f85a90f50a28397b8ea05eb23355fb8ea4fa0"
},
{
"signature": "ce939acca5677bc6d436bd8f054ed8fb03d143e0a9792c1f58592c43f175e89bb72d4d7114c1474b86e0d8fbf7807f4506325b56fcc6b87b2cb7002872527106",
"publicKey": "4c5bbbbe7caaa18372aa8edc1ef2d2a770d18a5c2d142b9d695619c3365dd297"
},
{
"signature": "5a1d55048234d92057dfd1938f49935a33751ee604b7dbd02a315418ced6f0836a51107512b192eae6133403bb437c6850b1af1c62c3b17a372acce77adf9903",
"publicKey": "57fa73123c3b39489c4d6c2ff3cab9952e56e556daab9f8f333bc5ca6984fa5e"
},
{
"signature": "e13c9ba5b084dc126d34f3f1120fff75495b64a41a98a69071b5c5ed01bb9d273f51d570cf4fdaa42969fa2c775c12ec05c496cd8f61323d343970136781f60e",
"publicKey": "8cc8963b65ddd0a49f7ce1acc2915d8baff505bbc4f8727a22bd1d28f8ad6632"
}
]
},
"name": {
"value": "SteveToken",
"anSignatures": [
{
"signature": "7ef6ed44ba9456737ef8d2e31596fdafb66d5775ac1a254086a553b666516e5895bb0c6b7ba8bef1f6b4d9bd9253b4449d1354de2f9e043ea4eb43fd42f87108",
"publicKey": "0ee262f062528667964782777917cd7139e19e8eb2c591767629e4200070c661"
},
{
"signature": "c95cf87b74d1e4d3b413c927c65de836f0905ba2cd176c7cbff83d8b886b30fe1560c542c1f77bb88280dff55c2d267c9840fe36560fb13ba4a78b6429e51500",
"publicKey": "7c3bfe2a11290a9b6ea054b4d0932678f88130511cfbfe3f634ee77d71edebe7"
},
{
"signature": "f88692b13212bac8121151a99a4de4d5244e5f63566babd2b8ac20950ede74073af0570772b3ce3d11b72e972079199f02306e947cd5fcca688a9d4664eddb04",
"publicKey": "8899d0777f399fffd44f72c85a8aa51605123a7ebf20bba42650780a0c81096a"
},
{
"signature": "c2b30fa5f2c09323d81e5050af681c023089d832d0b85d05f60f4278fba3011ab03e6bd9bd2b8649080a368ecfe51573cd232efe8f1e7ca69ff8334ced7b6801",
"publicKey": "d40688a3eeda1f229c64efc56dd53b363ff981f71a7462f78c8cc444117a03db"
}
]
},
"preImage": {
"hex": "f026b38d5bfdd8d8d838df4c4cc5d6aa4e",
"hashFn": "blake2b-256"
}
},
{
"subject": "44b57ee30cdb55829d0a5d4f046baef078f1e97a7f21b62d75f8e96ea139c35f",
"name": {
"value": "Wallet #6",
"anSignatures": [
{
"signature": "2e27065e365d38bef19b7bec139206f99b00effc8a2ad05bd22259aa939dd5083f25da91c4cb764eb1bfbce243ec32cce112be9762e1da7a38e975ebb0cc0b08",
"publicKey": "44b57ee30cdb55829d0a5d4f046baef078f1e97a7f21b62d75f8e96ea139c35f"
}
]
}
}
]
63 changes: 63 additions & 0 deletions plutus-scb/test/Cardano/Metadata/query_response2.json
@@ -0,0 +1,63 @@
[
{
"subject": "44b57ee30cdb55829d0a5d4f046baef078f1e97a7f21b62d75f8e96ea139c35f",
"name": {
"value": "Wallet #6",
"anSignatures": [
{
"signature": "2e27065e365d38bef19b7bec139206f99b00effc8a2ad05bd22259aa939dd5083f25da91c4cb764eb1bfbce243ec32cce112be9762e1da7a38e975ebb0cc0b08",
"publicKey": "44b57ee30cdb55829d0a5d4f046baef078f1e97a7f21b62d75f8e96ea139c35f"
}
]
}
},
{
"description": {
"value": "A sample description",
"anSignatures": [
{
"signature": "83ef5c04882e43e5f1c8e9bc386bd51cdda163f5cbd1996d1d066238de063d4b79b1648b48aec63dddff05649911ca116579842c8e9a08a3bc7ae1a0ec7ef000",
"publicKey": "1446c9d327b0f07aa691014c08578867674f3a88b36f2017a58c37a8a7799058"
},
{
"signature": "4e29a00feaeb24b25315f0eac28bbfc550dabfb847bf6a06cb8086120201f90c64fab778037d0ef009ab4669121a38fe9b8c0a6aec99c68366c5187c0889520a",
"publicKey": "1910312a9a6998c7e4f585dc138f85a90f50a28397b8ea05eb23355fb8ea4fa0"
},
{
"signature": "ce939acca5677bc6d436bd8f054ed8fb03d143e0a9792c1f58592c43f175e89bb72d4d7114c1474b86e0d8fbf7807f4506325b56fcc6b87b2cb7002872527106",
"publicKey": "4c5bbbbe7caaa18372aa8edc1ef2d2a770d18a5c2d142b9d695619c3365dd297"
},
{
"signature": "5a1d55048234d92057dfd1938f49935a33751ee604b7dbd02a315418ced6f0836a51107512b192eae6133403bb437c6850b1af1c62c3b17a372acce77adf9903",
"publicKey": "57fa73123c3b39489c4d6c2ff3cab9952e56e556daab9f8f333bc5ca6984fa5e"
},
{
"signature": "e13c9ba5b084dc126d34f3f1120fff75495b64a41a98a69071b5c5ed01bb9d273f51d570cf4fdaa42969fa2c775c12ec05c496cd8f61323d343970136781f60e",
"publicKey": "8cc8963b65ddd0a49f7ce1acc2915d8baff505bbc4f8727a22bd1d28f8ad6632"
}
]
},
"subject": "7f71940915ea5fe85e840f843c929eba467e6f050475bad1f10b9c274d1888c0",
"name": {
"value": "SteveToken",
"anSignatures": [
{
"signature": "7ef6ed44ba9456737ef8d2e31596fdafb66d5775ac1a254086a553b666516e5895bb0c6b7ba8bef1f6b4d9bd9253b4449d1354de2f9e043ea4eb43fd42f87108",
"publicKey": "0ee262f062528667964782777917cd7139e19e8eb2c591767629e4200070c661"
},
{
"signature": "c95cf87b74d1e4d3b413c927c65de836f0905ba2cd176c7cbff83d8b886b30fe1560c542c1f77bb88280dff55c2d267c9840fe36560fb13ba4a78b6429e51500",
"publicKey": "7c3bfe2a11290a9b6ea054b4d0932678f88130511cfbfe3f634ee77d71edebe7"
},
{
"signature": "f88692b13212bac8121151a99a4de4d5244e5f63566babd2b8ac20950ede74073af0570772b3ce3d11b72e972079199f02306e947cd5fcca688a9d4664eddb04",
"publicKey": "8899d0777f399fffd44f72c85a8aa51605123a7ebf20bba42650780a0c81096a"
},
{
"signature": "c2b30fa5f2c09323d81e5050af681c023089d832d0b85d05f60f4278fba3011ab03e6bd9bd2b8649080a368ecfe51573cd232efe8f1e7ca69ff8334ced7b6801",
"publicKey": "d40688a3eeda1f229c64efc56dd53b363ff981f71a7462f78c8cc444117a03db"
}
]
}
}
]
1 change: 1 addition & 0 deletions shell.nix
Expand Up @@ -14,6 +14,7 @@ in haskell.packages.shellFor {
pkgs.cacert
pkgs.niv
pkgs.nodejs
pkgs.shellcheck
pkgs.yarn
pkgs.zlib
pkgs.z3
Expand Down

0 comments on commit daa957a

Please sign in to comment.