| 1 | #!/usr/bin/env bash |
| 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | # You may not use this file except in compliance with the License. |
| 6 | # A copy of the License is located at |
| 7 | # |
| 8 | # http://aws.amazon.com/apache2.0 |
| 9 | # |
| 10 | # or in the "license" file accompanying this file. This file is distributed |
| 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | # express or implied. See the License for the specific language governing |
| 13 | # permissions and limitations under the License. |
| 14 | # |
| 15 | set -e |
| 16 | |
| 17 | # Utility functions |
| 18 | get_latest_release(){ |
| 19 | local LATEST_RELEASE_URL=$(gh api /repos/aws/s2n-tls/releases/latest|jq -r '.tarball_url') |
| 20 | local LATEST_RELEASE_VER=$(echo "${LATEST_RELEASE_URL}" | sed 's|.*/||') |
| 21 | echo "${LATEST_RELEASE_VER}" |
| 22 | } |
| 23 | |
| 24 | gh_login(){ |
| 25 | # Takes secrets manager key as an argument |
| 26 | # This GH personal access token must have 'repo' permissions to work. |
| 27 | gh auth status || aws secretsmanager get-secret-value --secret-id "$1" --query 'SecretString' --output text |jq -r '.secret_key'| gh auth login --with-token |
| 28 | |
| 29 | #gh auth status |
| 30 | } |
| 31 | |
| 32 | criterion_install_deps(){ |
| 33 | make install |
| 34 | source "$HOME"/.cargo/env |
| 35 | make -C bindings/rust |
| 36 | } |
| 37 | |
| 38 | |
| 39 | usage(){ |
| 40 | echo -e "Usage:\n\tget_latest_release: returns just the latest v.N.N.N version" |
| 41 | echo -e "\tgh_login <Secret Name> : retrieves a GitHub PAT from secrets manager and logs into GitHub.\n" |
| 42 | } |
| 43 | |
| 44 | if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then |
| 45 | case "${1:-}" in |
| 46 | "gh_login") |
| 47 | gh_login "${2:-}";; |
| 48 | "get_latest_release") |
| 49 | get_latest_release |
| 50 | echo "$LATEST_RELEASE_VER";; |
| 51 | *) usage; |
| 52 | esac |
| 53 | fi |