From 74efc791995e2e57817cae074a1dce2c10d2b1f3 Mon Sep 17 00:00:00 2001 From: Craig Shanks <44571906+crshanks@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:36:16 +0100 Subject: [PATCH] Merge four props shell scripts into one --- README.md | 19 +++++++++------ props.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 props.sh diff --git a/README.md b/README.md index fb1487e..4c6c7ee 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,9 @@ Update the [newrelic.properties.sample](newrelic.properties.sample) properties f The newrelic.properties file contains the following value: * LICENSE_KEY: your New Relic [Ingest License API key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#license-key) -Create, or update a propertyset named `NewRelicPropSet` for your environment using [props-create.sh](props-create.sh), and [props-update.sh](props-update.sh) respectively. Use [props-get.sh](props-get.sh) to verify the property set has been created successfully. Use [props-delete.sh](props-delete.sh) to delete the property set. +Create, or update a property set named `NewRelicPropSet` for your environment using [props.sh](props.sh) -c or -u for create, and update respectively. Use [props.sh](props.sh) -r to verify the property set has been created successfully. Use [props.sh](props.sh) -d to delete the property set. + +Note that in production environments you may wish to use Apigee [secrets](https://cloud.google.com/apigee/docs/api-platform/publish/import-existing-consumer-keys-and-secrets) rather than [property sets](https://cloud.google.com/apigee/docs/api-platform/cache/property-sets). ### Maven configuration If you are using the New Relic EU region, instead of the US region, change the host endpoint values. @@ -28,7 +30,7 @@ Set the following environment variables: * APIGEE_ENV: your agigee environment. The proxies can be configured per environment, e.g. `dev` If the environment variables are not set, they can alternatively be provided in the following file locations: -* [props-create.sh](props-create.sh), [props-update.sh](props-update.sh), and [props-get.sh](props-get.sh) +* [props.sh](props.sh) * deploy.sh for each of the proxies ### Shared flows @@ -36,17 +38,19 @@ The instrumentation examples in this repository make use of [shared flows](https Example API proxies are contained in the [examples](examples) directory. The example proxies are dependent on the following shared flows: * nr-instrumentation-sharedflow +* nr-instrumentation-obfuscation-sharedflow * nr-log-api-sharedflow * nr-logging-sharedflow * nr-metric-api-sharedflow * nr-trace-api-sharedflow To install the shared flows: -1. Execute the [deploy.sh](sharedflows/src/gateway/nr-instrumentation-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-instrumentation-sharedflow](sharedflows/src/gateway/nr-instrumentation-sharedflow) directory. -2. Execute the [deploy.sh](sharedflows/src/gateway/nr-log-api-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-log-api-sharedflow](sharedflows/src/gateway/nr-log-api-sharedflow) directory. -3. Execute the [deploy.sh](sharedflows/src/gateway/nr-logging-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-logging-sharedflow](sharedflows/src/gateway/nr-logging-sharedflow) directory. -4. Execute the [deploy.sh](sharedflows/src/gateway/nr-metric-api-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-metric-api-sharedflow](sharedflows/src/gateway/nr-metric-api-sharedflow) directory. -5. Execute the [deploy.sh](sharedflows/src/gateway/nr-trace-api-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-trace-api-sharedflow](sharedflows/src/gateway/nr-trace-api-sharedflow) directory. +1. Execute the [deploy.sh](sharedflows/src/gateway/nr-instrumentation-obfuscation-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-instrumentation-obfuscation-sharedflow](sharedflows/src/gateway/nr-instrumentation-obfuscation-sharedflow) directory. +2. Execute the [deploy.sh](sharedflows/src/gateway/nr-instrumentation-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-instrumentation-sharedflow](sharedflows/src/gateway/nr-instrumentation-sharedflow) directory. +3. Execute the [deploy.sh](sharedflows/src/gateway/nr-log-api-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-log-api-sharedflow](sharedflows/src/gateway/nr-log-api-sharedflow) directory. +4. Execute the [deploy.sh](sharedflows/src/gateway/nr-logging-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-logging-sharedflow](sharedflows/src/gateway/nr-logging-sharedflow) directory. +5. Execute the [deploy.sh](sharedflows/src/gateway/nr-metric-api-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-metric-api-sharedflow](sharedflows/src/gateway/nr-metric-api-sharedflow) directory. +6. Execute the [deploy.sh](sharedflows/src/gateway/nr-trace-api-sharedflow/deploy.sh) script from within the [sharedflows/src/gateway/nr-trace-api-sharedflow](sharedflows/src/gateway/nr-trace-api-sharedflow) directory. ### Example flow To install the example flows: @@ -56,6 +60,7 @@ To install the example flows: 4. Execute the [deploy.sh](examples/newrelic-trace/deploy.sh) script from within the [examples/newrelic-trace](examples/newrelic-trace) directory. 5. Execute the [deploy.sh](examples/newrelic-trace-and-logging/deploy.sh) script from within the [examples/newrelic-trace-and-logging](examples/newrelic-trace-and-logging) directory. 6. Execute the [deploy.sh](examples/newrelic-trace-and-metric-and-log/deploy.sh) script from within the [examples/newrelic-trace-and-metric-and-log](examples/newrelic-trace-and-metric-and-log) directory. +7. Execute the [deploy.sh](examples/newrelic-trace-and-metric-and-log-obfuscate/deploy.sh) script from within the [examples/newrelic-trace-and-metric-and-log-obfuscate](examples/newrelic-trace-and-metric-and-log-obfuscate) directory. ## Synthetics tests for the example API proxies Terraform configuration is available to create synthetics monitors to exercise the sample API proxies. Take a look at the [README.md](synthetics-tests/README.md) file in the [synthetics-tests](synthetics-tests) directory for more information. diff --git a/props.sh b/props.sh new file mode 100644 index 0000000..37501b9 --- /dev/null +++ b/props.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Function to create a property set +create() { + TOKEN=$(gcloud auth print-access-token) + ORG=${APIGEE_ORG:-"default here if not set as an env variable"} + ENV=${APIGEE_ENV:-"default here if not set as an env variable"} + NAME=NewRelicPropSet + + curl -X POST "https://apigee.googleapis.com/v1/organizations/$ORG/environments/$ENV/resourcefiles?name=$NAME&type=properties" \ + -H "Authorization: Bearer $TOKEN" \ + -H "Content-type: multipart/form-data" \ + -F file=@newrelic.properties +} + +# Function to read a property set +read() { + TOKEN=$(gcloud auth print-access-token) + ORG=${APIGEE_ORG:-"default here if not set as an env variable"} + ENV=${APIGEE_ENV:-"default here if not set as an env variable"} + NAME=NewRelicPropSet + + curl -X GET "https://apigee.googleapis.com/v1/organizations/$ORG/environments/$ENV/resourcefiles/properties/$NAME" \ + -H "Authorization: Bearer $TOKEN" +} + +# Function to update a property set +update() { + TOKEN=$(gcloud auth print-access-token) + ORG=${APIGEE_ORG:-"default here if not set as an env variable"} + ENV=${APIGEE_ENV:-"default here if not set as an env variable"} + NAME=NewRelicPropSet + + curl -X PUT "https://apigee.googleapis.com/v1/organizations/$ORG/environments/$ENV/resourcefiles/properties/$NAME" \ + -H "Authorization: Bearer $TOKEN" \ + -H "Content-type: multipart/form-data" \ + -F file=@newrelic.properties +} + +# Function to delete a property set +delete() { + TOKEN=$(gcloud auth print-access-token) + ORG=${APIGEE_ORG:-"default here if not set as an env variable"} + ENV=${APIGEE_ENV:-"default here if not set as an env variable"} + NAME=NewRelicPropSet + + curl -X DELETE "https://apigee.googleapis.com/v1/organizations/$ORG/environments/$ENV/resourcefiles/properties/$NAME" \ + -H "Authorization: Bearer $TOKEN" +} + +# Parse command-line arguments +while getopts "c:g:u:d:" opt; do + case ${opt} in + c ) + create + ;; + r ) + read + ;; + u ) + update + ;; + d ) + delete + ;; + \? ) + echo "Usage: cmd [-c] [-r] [-u] [-d]" + ;; + esac +done \ No newline at end of file