How to retrieve Application Property Sources from a Spring Cloud Services for TAS Config Server
search cancel

How to retrieve Application Property Sources from a Spring Cloud Services for TAS Config Server

book

Article ID: 377013

calendar_today

Updated On:

Products

VMware Tanzu Application Service

Issue/Introduction

This article demonstrates the steps to retrieve application's environment variables used to enumerate property sources and publish them at a JSON endpoint.

The HTTP service has resources in the following form:

/{application}/{profile}[/{label}]

Environment

Spring Cloud Service for TAS 

 

Resolution

The following steps retrieves the property sources from the config-server service instance. 

 

1. Retrieve the client_id and client_secret for the config-server service instance using How to retrieve service credentials for a service instance bind to an application

2. Open a terminal session.

3. SSH to your Ops Manager VM

ssh ubuntu@<opsman-url-or-IP>

 

4. Target your UAA server by running

uaac target uaa.UAA-DOMAIN

where UAA-DOMAIN is the domain of your UAA server

Example:

uaac target https://uaa.system,example.com

 

5. Authenticate and obtain an access token for the service credentials from the UAA server by running

uaac token client get <client_id> -s <client_secret>

where: client_id and client_secret recorded in Step #1.

Example: 

$ uaac token client get config-client-BINDING_GUID -s mysecret

WARNING: Decoding token without verifying it was signed by its authoring UAA

Successfully fetched token via client credentials grant.
Target: https://uaa.system.example.com
Context: config-client-BINDING_GUID, from client config-client-BINDING_GUID



6. Retrieve access token by running

export APP_TOKEN=`uaac context | grep access_token | awk '{print $2}'`

 

7. Verify access token

echo $APP_TOKEN

 

8. Get Property Sources from the config-server endpoint URL 

curl -k -H "Authorization: bearer $APP_TOKEN" -H "Accept: application/json" https://<CONFIG-SERVER-ROUTE-URL>/<SPRING_APPLICATION_NAME>/<PROFILE>/<LABEL> | jq

 

Example:

Using: 
SPRING_APPLICATION_NAME = cook
PROFILE = development
LABEL = main

$ curl -k -H "Authorization: bearer $APP_TOKEN" -H "Accept: application/json" https://config-server-GUID.cfapps.example.com/cook/development/main | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   349    0   349    0     0    321      0 --:--:--  0:00:01 --:--:--   321
{
  "name": "cook",
  "profiles": [
    "development"
  ],
  "label": "main",
  "version": null,
  "state": null,
  "propertySources": [
    {
      "name": "credhub-cook-development-main",
      "source": {
        "secretMenu": "tacos-dev"
      }
    },
    {
    "name": "ssh://mirror@<IP>:22/var/vcap/store/mirror/00957ad15f043b124e46eb212e90c4c8/cook-config/cook.properties",
      "source": {
        "cook.special": "Pickled Cactus"
      }
    }
  ]
}






Additional Information

The application will execute multiple request to the config server and evaluate Property Sources 

For example using:

SPRING_APPLICATION_NAME=cook
SPRING_PROFILES_ACTIVE=DEVELOPMENT

Enumeration sequence:

  1. GET /application/default 
  2. GET /cook/development
  3. GET /cook/default

Sample app logs.

2024-09-10T15:15:20.37-0600 [APP/PROC/WEB/0] OUT 2024-09-10T21:15:20.377Z  INFO 13 --- [cook] [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : https://config-server-8acb8291-547e-41f8-9ade-05438101f53c.cfapps.example.com

   2024-09-10T15:15:20.37-0600 [APP/PROC/WEB/0] OUT 2024-09-10T21:15:20.377Z  INFO 13 --- [cook] [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[default], label=null, version=null, state=null

 

   2024-09-10T15:15:20.37-0600 [APP/PROC/WEB/0] OUT 2024-09-10T21:15:20.378Z  INFO 13 --- [cook] [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : https://config-server-8acb8291-547e-41f8-9ade-05438101f53c.cfapps.example.com

   2024-09-10T15:15:20.37-0600 [APP/PROC/WEB/0] OUT 2024-09-10T21:15:20.378Z  INFO 13 --- [cook] [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=cook, profiles=[development], label=null, version=null, state=null

 

   2024-09-10T15:15:20.37-0600 [APP/PROC/WEB/0] OUT 2024-09-10T21:15:20.378Z  INFO 13 --- [cook] [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : https://config-server-8acb8291-547e-41f8-9ade-05438101f53c.cfapps.example.com

   2024-09-10T15:15:20.37-0600 [APP/PROC/WEB/0] OUT 2024-09-10T21:15:20.378Z  INFO 13 --- [cook] [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=cook, profiles=[default], label=null, version=null, state=null