description: FlowSync - Example 5
metadata:
  name: example 5
  version: 1.0.0
resources:
  # ------------------------------------------------
  # Our Endpoints for dns.google (north side)
  # ------------------------------------------------

  googleDnsConnection:
    type: Cybus::Connection
    properties:
      protocol: Http
      connection:
        scheme: https
        host: dns.google

  dnsEndpoint:
    type: Cybus::Endpoint
    properties:
      topic: dns
      protocol: Http
      connection: !ref googleDnsConnection
      publishError: true
      read:
        path: /resolve

  # ---------------------------------------
  # Our HTTP Server and Nodes  (south side)
  # ---------------------------------------

  server:
    type: Cybus::Server::Http
    properties:
      basePath: /flowsync

  dnsNode:
    type: Cybus::Node::Http
    properties:
      parent: !ref server
      method: GET
      route: /example5
      operation: transaction

  # ------------------------------------------------
  # The mappings forwarding requests and responses
  # ------------------------------------------------

  Mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref dnsNode
          publish:
            endpoint: !ref dnsEndpoint
          rules:
            - transform:
                expression: >-
                  (
                    {
                      "id": $.id,
                      "query": {
                         "name": $.value.query.entry
                      }
                    }
                  )
        - subscribe:
            endpoint: !ref dnsEndpoint
          publish:
            endpoint: !ref dnsNode
          rules:
            - transform:
                expression: >-
                  (
                    {
                      "id": $.id,
                      "timestamp": $.timestamp,
                      "value" : $.value
                    }
                  )
