config2-scenario.md 2.8 KB

Config 2: Flat YAML with Wildcard

Scenario

Testing flat YAML structure (tanpa root key) yang diakses menggunakan wildcard key '*'. Config ini berisi direct key-value pairs di root level dengan arrays.

Use Case

Simple configuration file yang tidak memerlukan grouping, langsung berisi settings yang dibutuhkan.


Input: CONFIG2.yaml

ApiSecret: flat_secret_789
TrxAuthMethod: oauth2
TrxSignKey: X-Auth-Token
endpoint: https://api.example.com
retryAttempts: 3
connectionTimeout: 5000
headers:
  - name: X-Api-Key
    type: LITERAL
    value: api_key_xyz
  - name: User-Agent
    value: ACE-Middleware/1.0
allowedMethods:
  - GET
  - POST
  - PUT
  - DELETE
responseFields:
  - id
  - status
  - timestamp
  - data

Output: hasilParseConfig2.json

{
  "ApiSecret": "flat_secret_789",
  "TrxAuthMethod": "oauth2",
  "TrxSignKey": "X-Auth-Token",
  "endpoint": "https://api.example.com",
  "retryAttempts": "3",
  "connectionTimeout": "5000",
  "headers": [
    {
      "name": "X-Api-Key",
      "type": "LITERAL",
      "value": "api_key_xyz"
    },
    {
      "name": "User-Agent",
      "value": "ACE-Middleware/1.0"
    }
  ],
  "allowedMethods": ["GET", "POST", "PUT", "DELETE"],
  "responseFields": ["id", "status", "timestamp", "data"]
}

ESQL Usage

-- PENTING: Gunakan wildcard '*' untuk flat YAML
DECLARE config REFERENCE TO Environment.Variables;
DECLARE success BOOLEAN;

CALL ACE_LIB.getConfig(
    'FLAT_CONFIG',
    '*',                      -- Wildcard key untuk ambil semua
    '/path/to/CONFIG2.yaml',
    '600',
    config
) INTO success;

IF success THEN
    -- Akses scalar values
    DECLARE apiSecret CHARACTER config.ApiSecret;
    DECLARE endpoint CHARACTER config.endpoint;
    DECLARE retries CHARACTER config.retryAttempts;
    
    -- Loop simple string arrays
    DECLARE methodRef REFERENCE TO config.allowedMethods[1];
    WHILE LASTMOVE(methodRef) DO
        DECLARE method CHARACTER methodRef;
        -- Process method: "GET", "POST", etc.
        MOVE methodRef NEXTSIBLING;
    END WHILE;
    
    -- Loop array of objects
    DECLARE headerRef REFERENCE TO config.headers[1];
    WHILE LASTMOVE(headerRef) DO
        DECLARE headerName CHARACTER headerRef.name;
        DECLARE headerValue CHARACTER COALESCE(headerRef.value, '');
        MOVE headerRef NEXTSIBLING;
    END WHILE;
END IF;

Key Features Tested

✅ Flat YAML structure (no root key)
✅ Wildcard '*' key untuk akses full config
✅ Arrays of simple strings (allowedMethods, responseFields)
✅ Mixed content: objects and arrays at root level
✅ Direct key-value pairs di root level


Important Notes

  • Key '*' adalah special key untuk flat YAML
  • Semua content di root level langsung accessible
  • Ideal untuk config sederhana yang tidak perlu grouping

⬅️ Back to README