Search code examples
sap-cloud-sdk

Use SSH tunnel to test apps with on-premise destination locally


I would like to run my app locally and use the on-premise system connected via Cloud Connector (connectivity) and destination service. I was already pointed to the documentation but it is not working as expected. Is there a more detailed step-by-step tutorial available for the setup?

I followed the documentation and expected to be able to run my app using

cds watch

but it looks like the app is still trying to call the destination from my local client instead of using the ssh tunnel.


Solution

  • sorry we don't have a more detailed step by step guide, but I think it makes sense to extend the documentation.

    Form the cds watch I guess you are using a CAP application. This should in principle be possible, but in order to minimize the sources of errors I would do the following:

    • open the ssh tunnel
    • just execute a node my-test.js
    • add a copy of your VCAP_SERVICE variables to the process (dotenv lib)
    • Remember to adjust port/host proxy in your VCAP_SERVICE to point to the local side of your tunnel
    • in the "my-test.js" call getDestination() from the SDK and have a look (if you do not provide a user JWT here you have to use a basic auth destination)
    • The destination should have a proxy config containing the local side and all necessary auth headers
    • Execute a call using this destination. The request should use the proxy located in CF via the ssh tunnel

    I made a E2E test in the context of an other project and this snippet worked for me:

    //cf enable-ssh My-App
    //cf ssh MyApp -L 4711:connectivityproxy.cf.sap.hana.ondemand.com:20003
    const destination = await getDestination('MyDestination',{})
    
    
        destination.proxyConfiguration = {
            host:'localhost',
            port:4711,
            headers:destination.proxyConfiguration.headers,
            protocol:destination.proxyConfiguration.protocol
        }
    
        const bps = await BusinessPartner.requestBuilder().getAll().top(3).execute(destination)
    

    Best Frank