Skip to content

Instantly share code, notes, and snippets.

@rafaeltuelho
Last active November 16, 2022 17:15
Show Gist options
  • Save rafaeltuelho/2dbf9dac90191c9c8f41bf5f3b2365be to your computer and use it in GitHub Desktop.
Save rafaeltuelho/2dbf9dac90191c9c8f41bf5f3b2365be to your computer and use it in GitHub Desktop.
3Scale toolbox CLI and API commands

Create a Service Registry instance

Install rhoas on MacOS with zsh shell

curl -o- https://raw.githubusercontent.com/redhat-developer/app-services-cli/main/scripts/install.sh | bash
#make sure your $HOME/bin is included in your $PATH

#open a new terminal
rhoas --version

#add cli completion for zsh
rhoas completion zsh > "${fpath[1]}/_rhoas"

rhoas login
rhoas whoami
rhoas status
rhoas service-registry create --name globex
curl -O https://raw.githubusercontent.com/cloud-services-summit-connect-2022/product-catalog-api/main/openapi/openapi-spec.yml
rhoas service-registry artifact create --file ./openapi-spec.yml --type OPENAPI

## store your 3scale access token and your tenant admin url

export THREESCALE_ACCESS_TOKEN=<ACCESS_TOKEN> export THREESCALE_TENANT_ADMIN_PORTAL_URL=3scale-admin.apps.your-domain


## create a container for 3scale-toolbox adding your tenant admin url

docker run --name=3scale-toolbox-original
quay.io/redhat/3scale-toolbox 3scale remote
add 3scale-tenant -k https://$THREESCALE_ACCESS_TOKEN@$THREESCALE_TENANT_ADMIN_PORTAL_URL


## create a new image with your 3scale tenant info

docker commit 3scale-toolbox-original 3scale-toolbox


## create an alias for the containerized toolbox

alias 3scale='docker run 3scale-toolbox 3scale -k'


## create your API management resources on 3scale

#API product 3scale service create 3scale-tenant globex-product-catalog --description='Product Catalog API for the Globex online app'



## API Backend
```curl -v -X POST "$THREESCALE_TENANT_ADMIN_PORTAL_URL/admin/api/backend_apis.json" \
-d 'access_token=$THREESCALE_ACCESS_TOKEN&name=globex-catalog-backend&description=Backend+for+the+Product+Catalog+service&private_endpoint=https%3A%2F%2Fcatalog-globex-user1.apps.cluster-gnfvj.sandbox565.opentlc.com'
{
 "backend_api": {
  "id": 451,
  "name": "globex-catalog-backend2",
  "system_name": "globex_catalog_backend",
  "description": "Backend for the Product Catalog service",
  "private_endpoint": "https://catalog-globex-user1.apps.cluster-gnfvj.sandbox565.opentlc.com:443",
  "account_id": 575,
  "created_at": "2022-11-11T17:25:59Z",
  "updated_at": "2022-11-11T17:25:59Z",
  "links": [
   {
    "rel": "metrics",
    "href": "/admin/api/backend_apis/451/metrics"
   },
   {
    "rel": "mapping_rules",
    "href": "/admin/api/backend_apis/451/mapping_rules"
   }
  ]
 }
}

Add backend to the product

curl -v  -X POST "$THREESCALE_TENANT_ADMIN_PORTAL_URL/admin/api/services/481/backend_usages.json" -d 'access_token=$THREESCALE_ACCESS_TOKEN&backend_api_id=451&path=%2F'
{
 "backend_usage": {
  "id": 462,
  "path": "/",
  "service_id": 481,
  "backend_id": 451,
  "links": [
   {
    "rel": "service",
    "href": "$THREESCALE_TENANT_ADMIN_PORTAL_URL/admin/api/services/481"
   },
   {
    "rel": "backend_api",
    "href": "$THREESCALE_TENANT_ADMIN_PORTAL_URL/admin/api/backend_apis/451"
   }
  ]
 }
}

API Application Plan

3scale application-plan create --publish 3scale-tenant globex_product_catalog globex-product-catalog-app-plan

Find the sample developer account id

3scale account find 3scale-tenant john
id => 576
org_name => Developer

Application associated with the Plan

3scale application create 3scale-tenant 576 globex_product_catalog globex_product_catalog_app_plan globex-product-catalog-app

Get Service (Product ID)

3scale service show 3scale-tenant globex_product_catalog2 -o json | jq .id

Promote APICast Config to staging

curl -v  -X POST "$THREESCALE_TENANT_ADMIN_PORTAL_URL/admin/api/services/481/proxy/deploy.json" -d 'access_token=$THREESCALE_ACCESS_TOKEN'

get Application user_key

curl -s  -X GET "$THREESCALE_TENANT_ADMIN_PORTAL_URL/admin/api/applications/find.json?access_token=$THREESCALE_ACCESS_TOKEN&application_id=2083" | jq .application.user_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment