diff --git a/deployment/default.nix b/deployment/default.nix index 3ace91bf896..02da12bce6a 100644 --- a/deployment/default.nix +++ b/deployment/default.nix @@ -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 @@ -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)}' ''; @@ -41,14 +43,18 @@ 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 @@ -56,18 +62,19 @@ let 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) @@ -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} @@ -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) @@ -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: { diff --git a/nix/dev.nix b/nix/dev.nix index 1e2d66d7006..a82d8f323d8 100644 --- a/nix/dev.nix +++ b/nix/dev.nix @@ -13,10 +13,24 @@ 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 \ @@ -24,8 +38,7 @@ pkgs.recurseIntoAttrs (rec { --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 @@ -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 \ @@ -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 @@ -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 [ @@ -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 @@ -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}' ''; }; }) diff --git a/plutus-scb/test/Cardano/Metadata/TypesSpec.hs b/plutus-scb/test/Cardano/Metadata/TypesSpec.hs index 6219aa83de5..a8e32959b51 100644 --- a/plutus-scb/test/Cardano/Metadata/TypesSpec.hs +++ b/plutus-scb/test/Cardano/Metadata/TypesSpec.hs @@ -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" ] ] diff --git a/plutus-scb/test/Cardano/Metadata/query_response1.json b/plutus-scb/test/Cardano/Metadata/query_response1.json new file mode 100644 index 00000000000..9860142274e --- /dev/null +++ b/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" + } + ] + } + } +] \ No newline at end of file diff --git a/plutus-scb/test/Cardano/Metadata/query_response2.json b/plutus-scb/test/Cardano/Metadata/query_response2.json new file mode 100644 index 00000000000..d49442f5ea2 --- /dev/null +++ b/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" + } + ] + } + } +] \ No newline at end of file diff --git a/shell.nix b/shell.nix index 10bf8f75215..4c408db6ad6 100644 --- a/shell.nix +++ b/shell.nix @@ -14,6 +14,7 @@ in haskell.packages.shellFor { pkgs.cacert pkgs.niv pkgs.nodejs + pkgs.shellcheck pkgs.yarn pkgs.zlib pkgs.z3