Programmatic API access
Scripts and other programs call the Cloudera SQL Stream Builder (SSB) REST API with the same session as the Streaming SQL Console: a hadoop-jwt cookie that the Anywhere Cloud gateway issues when you sign in, or with an access token.
The Streaming SQL Console and the SSB REST API share one authenticated session. The gateway
of Anywhere Cloud checks the hadoop-jwt cookie of each
request and passes your username to SSB. SSB gives you the permissions that you have in each
project. Users in the Admin usernames: comma separated list setting of the engine
instance are SSB administrators.
The gateway also accepts an Anywhere Cloud access token as a bearer token in the Authorization header, for requests to the same host. For how to get a token, see Creating tokens for using the API in the Anywhere Cloud documentation. Opaque Anywhere Cloud API keys do
not authenticate requests to the SSB REST API.
Getting the cookie from your browser
You can use this method with every identity provider.
- Sign in to the Streaming SQL Console.
- Open the developer tools of your browser, and copy the value of the
hadoop-jwtcookie. - Store the value in an environment variable:
export HADOOP_JWT="<hadoop-jwt-cookie-value>"
Checking access
The gateway rejects unauthenticated requests, so the heartbeat endpoint shows whether your credentials work for access from outside the cluster.
- Store the host of the Streaming SQL Console in an environment variable:
export SSB_URL="https://<instance-name>-ssb-sse.<domain>" - Send a request with the cookie or with an access token:
curl -s -o /dev/null -w "%{http_code}\n" -b "hadoop-jwt=${HADOOP_JWT}" "${SSB_URL}/api/v2/heartbeat" curl -s -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer ${TOKEN}" "${SSB_URL}/api/v2/heartbeat"The command prints
200when the request is authenticated.TOKENholds an Anywhere Cloud access token.
Expired sessions
The session expires after some time. When it expires, requests return the sign-in page or a redirect instead of JSON. Get a new cookie or token, and send the request again.
For the Anywhere Cloud platform APIs, see Creating tokens for using the API in the Anywhere Cloud documentation.
