|
1 |
| -# pancloud-nodejs |
2 |
| -Palo Alto Networks Application Framework NodeJS SDK |
| 1 | +# Palo Alto Networks Cloud NodeJS SDK |
| 2 | +NodeJS idiomatic SDK for the Palo Alto Networks Application Framework. |
3 | 3 |
|
4 |
| -## EXPERIMENTAL |
| 4 | +The Palo Alto Networks Cloud NodeJS SDK (or pancloud for short) was created to assist developers with programmatically interacting with the Palo Alto Networks Cortex Framework. |
| 5 | + |
| 6 | +The primary goal is to provide full, low-level API coverage for the following Application Framework services: |
| 7 | + |
| 8 | +* Logging Service |
| 9 | +* Directory Sync Service |
| 10 | +* Event Service |
| 11 | + |
| 12 | +The secondary goal is to provide coverage, in the form of helpers, for common tasks/operations. (Log/event pagination, OAuth 2.0 and token refreshing ...) |
| 13 | + |
| 14 | +# Quick Starting |
| 15 | +1. Install `pancloud` in your project as a dependency |
| 16 | +```$ npm install pancloud``` |
| 17 | +2. Use the `autoCredentials()` function to instantiate a `Credentials` object based on your environmental variables |
| 18 | + * _Option 1_: Set the variable `PAN_ACCESS_TOKEN` to retrieve a `Credentials` instance (valid to interface with a datalake as long as the access token is not expired / no auto-refresh available) |
| 19 | + * _Option 2_: Set the variables `PAN_CLIENT_ID`, `PAN_CLIENT_SECRET` and `PAN_REFRESH_TOKEN` to instantiate a memory-based credentials provider and retrieve a `Credentials` object bound to the datalake for which the provided refresh token was issued (auto-refresh available) |
| 20 | + * _Option 3_: Set the variable `PAN_DEVELOPER_TOKEN` to retieve a `Credentials` object that will leverage your API Explorer tenant to issue access tokens on your behalf |
| 21 | +3. Instantiate a `LoggingService` object using the `Credentials` object you obtained in the step 2 |
| 22 | +4. Perform a query using the `query()` method of your `LoggingService` object. |
| 23 | + |
| 24 | +## Quick Starting Examples |
| 25 | +create a file named `index.js` in your project forder with the following content |
| 26 | +``` |
| 27 | +const pancloud = require('pancloud'); |
| 28 | +pancloud.autoCredentials() |
| 29 | + .then(credentials => pancloud.LoggingService.factory(credentials)) |
| 30 | + .then(loggingService => loggingService.query({ |
| 31 | + query: "SELECT * FROM panw.dpi WHERE subtype='dhcp' LIMIT 1", |
| 32 | + startTime: 0, // 1970 |
| 33 | + endTime: 2000000000, // 2033 |
| 34 | + maxWaitTime: 30000 // wait up to 30 seconds for the query to complete |
| 35 | + })) |
| 36 | + .then(jobResult => console.log(JSON.stringify(jobResult, undefined, ' '))) |
| 37 | +``` |
| 38 | +* **Running the example with an OAUTH2 access token (use case: interactive lab testing)** |
| 39 | +``` |
| 40 | +$ export PAN_ACCESS_TOKEN=eyJhbGciOi......BwSldUIn0.eyJzd......iJ9.GFjG......iaW0N_PCA |
| 41 | +$ node index |
| 42 | +PANCLOUD: {"source":"AutoCredentials","message":"Environmental variable PAN_ENTRYPOINT not set. Assuming https://api.us.paloaltonetworks.com"} |
| 43 | +PANCLOUD: {"source":"AutoCredentials","message":"Using startic credentials. No refresh available."} |
| 44 | +PANCLOUD: {"source":"LoggingService","message":"Creating new LoggingService object for entryPoint https://api.us.paloaltonetworks.com"} |
| 45 | +PANCLOUD: {"source":"LoggingService","message":"*queries* post request. Query: {\"query\":\"SELECT * FROM panw.dpi WHERE subtype='dhcp' LIMIT 1\",\"startTime\":0,\"endTime\":2000000000,\"maxWaitTime\":30000}"} |
| 46 | +PANCLOUD: {"source":"LoggingService","message":"updated authorization header"} |
| 47 | +{ |
| 48 | + "queryId": "c1ce3558-0d33-42c5-bdfc-b71dbbc673eb", |
| 49 | + "sequenceNo": 0, |
| 50 | + "queryStatus": "JOB_FINISHED", |
| 51 | + "clientParameters": {}, |
| 52 | + "result": { |
| 53 | + "esResult": { |
| 54 | + "took": 290, |
| 55 | + "hits": { |
| 56 | + "total": 838, |
| 57 | + "maxScore": 14.113734, |
| 58 | + "hits": [ |
| 59 | + { |
| 60 | + "_index": "117270020_panw.dpi_2019040700-2019042700_000000", |
| 61 | + "_type": "dpi", |
| 62 | + "_id": "117270020_lcaas:1:1253209:657", |
| 63 | + "_score": 14.113734, |
| 64 | + "_source": { |
| 65 | + "dhcp-rsp-dns-suffix": "domain.name", |
| 66 | + "direction_reversed": "true", |
| 67 | + "sessionid": 59070, |
| 68 | + "dhcp-rsp-ciaddr": "00000000000000000000ffff0a640b0b", |
| 69 | + "type": "DPI", |
| 70 | + "content_ver": "8138-5378", |
| 71 | + "txn_id": 1, |
| 72 | + "receptor_txn_start": 1554755925, |
| 73 | + "subtype": "dhcp", |
| 74 | + "client_sw": "8.1.4", |
| 75 | + "recsize": 959, |
| 76 | + "dhcp-rsp-chaddr": "00:00:00:00:00:00", |
| 77 | + "dhcp-rsp-router-option": [ |
| 78 | + { |
| 79 | + "dhcp-rsp-router-addr": "00000000000000000000ffffc0a80101" |
| 80 | + } |
| 81 | + ], |
| 82 | + "dhcp-rsp-yiaddr": "00000000000000000000ffff00000000", |
| 83 | + "dhcp-rsp-giaddr": "00000000000000000000ffff00000000", |
| 84 | + "dhcp-rsp-siaddr": "00000000000000000000ffff00000000", |
| 85 | + "receive_time": 1554755946, |
| 86 | + "dhcp-rsp-msg-type": 5, |
| 87 | + "dhcp-rsp-subnet-mask": "00000000000000000000ffffffffff00", |
| 88 | + "time_generated": 1554755922, |
| 89 | + "dhcp-rsp-domain-name-server-option": [ |
| 90 | + { |
| 91 | + "dhcp-rsp-dns-addr": "00000000000000000000ffff503a3dfa" |
| 92 | + }, |
| 93 | + { |
| 94 | + "dhcp-rsp-dns-addr": "00000000000000000000ffff503a3dfe" |
| 95 | + } |
| 96 | + ], |
| 97 | + "customer-id": "117270020", |
| 98 | + "serial": "", |
| 99 | + "dhcp-rsp-transaction-id": 3782930258, |
| 100 | + "dhcp-rsp-opcode": 2 |
| 101 | + } |
| 102 | + } |
| 103 | + ] |
| 104 | + }, |
| 105 | + "id": "c1ce3558-0d33-42c5-bdfc-b71dbbc673eb", |
| 106 | + "from": 0, |
| 107 | + "size": 1, |
| 108 | + "completed": true, |
| 109 | + "state": "COMPLETED", |
| 110 | + "timed_out": false |
| 111 | + }, |
| 112 | + "esQuery": { |
| 113 | + "table": [ |
| 114 | + "panw.dpi" |
| 115 | + ], |
| 116 | + "query": { |
| 117 | + "aggregations": {}, |
| 118 | + "query": { |
| 119 | + "term": { |
| 120 | + "{{field_0}}": "{{value_0}}" |
| 121 | + } |
| 122 | + }, |
| 123 | + "size": 1 |
| 124 | + }, |
| 125 | + "selections": [], |
| 126 | + "params": { |
| 127 | + "field_0": "subtype", |
| 128 | + "value_0": "dhcp" |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +* **Running the example with an OAUTH2 client-id, client-secret and refresh-token (use case: script lab testing)** |
| 136 | +``` |
| 137 | +$ export PAN_CLIENT_ID=<my oauth2 client-id> |
| 138 | +$ export PAN_CLIENT_SECRET=<my oauth2 client-secret> |
| 139 | +$ export PAN_REFRESH_TOKEN=<my datalake's refresh-token> |
| 140 | +$ node index |
| 141 | +PANCLOUD: {"source":"AutoCredentials","message":"Environmental variable PAN_ENTRYPOINT not set. Assuming https://api.us.paloaltonetworks.com"} |
| 142 | +PANCLOUD: {"source":"AutoCredentials","message":"Using memory based credentials provider"} |
| 143 | +PANCLOUD: {"source":"defaultCredentialsFactory","message":"Got 'client_id'"} |
| 144 | +PANCLOUD: {"source":"defaultCredentialsFactory","message":"Got 'client_secret'"} |
| 145 | +PANCLOUD: {"source":"DefaultCredentialsProvider","message":"Stateless credential provider. Returning an empty item list to load() request"} |
| 146 | +PANCLOUD: {"source":"CortexCredentialProvider","message":"Successfully restored 0 items"} |
| 147 | +PANCLOUD: {"source":"CortexCredentialProvider","message":"Authorization token successfully retrieved","name":"IDENTITY"} |
| 148 | +PANCLOUD: {"source":"CortexCredentialProvider","message":"Retrieved Access Token for datalake ID DEFAULT from Identity Provider"} |
| 149 | +PANCLOUD: {"source":"CortexCredentialProvider","message":"Instantiated new credential object from the factory for datalake id DEFAULT"} |
| 150 | +PANCLOUD: {"source":"DefaultCredentialsProvider","message":"Stateless credential provider. Discarding new item issued"} |
| 151 | +PANCLOUD: {"source":"CortexCredentialProvider","message":"Issued new Credentials Object for datalake ID DEFAULT"} |
| 152 | +PANCLOUD: {"source":"LoggingService","message":"Creating new LoggingService object for entryPoint https://api.us.paloaltonetworks.com"} |
| 153 | +PANCLOUD: {"source":"LoggingService","message":"*queries* post request. Query: {\"query\":\"SELECT * FROM panw.dpi WHERE subtype='dhcp' LIMIT 1\",\"startTime\":0,\"endTime\":2000000000,\"maxWaitTime\":30000}"} |
| 154 | +PANCLOUD: {"source":"LoggingService","message":"updated authorization header"} |
| 155 | +{ |
| 156 | + "queryId": "de0dc306-f2a4-4247-8ace-a47cf92ff558", |
| 157 | + "sequenceNo": 0, |
| 158 | + "queryStatus": "JOB_FINISHED", |
| 159 | + "clientParameters": {}, |
| 160 | + "result": { |
| 161 | + "esResult": { |
| 162 | + "took": 807, |
| 163 | + "hits": { |
| 164 | + "total": 846, |
| 165 | + "maxScore": 14.103332, |
| 166 | + "hits": [ |
| 167 | + { |
| 168 | + "_index": "117270020_panw.dpi_2019040700-2019042700_000000", |
| 169 | + "_type": "dpi", |
| 170 | + "_id": "117270020_lcaas:1:1253209:657", |
| 171 | + "_score": 14.103332, |
| 172 | + "_source": { |
| 173 | + "dhcp-rsp-dns-suffix": "domain.name", |
| 174 | + "direction_reversed": "true", |
| 175 | + "sessionid": 59070, |
| 176 | + "dhcp-rsp-ciaddr": "00000000000000000000ffff0a640b0b", |
| 177 | + "type": "DPI", |
| 178 | + "content_ver": "8138-5378", |
| 179 | + "txn_id": 1, |
| 180 | + "receptor_txn_start": 1554755925, |
| 181 | + "subtype": "dhcp", |
| 182 | + "client_sw": "8.1.4", |
| 183 | + "recsize": 959, |
| 184 | + "dhcp-rsp-chaddr": "00:00:00:00:00:00", |
| 185 | + "dhcp-rsp-router-option": [ |
| 186 | + { |
| 187 | + "dhcp-rsp-router-addr": "00000000000000000000ffffc0a80101" |
| 188 | + } |
| 189 | + ], |
| 190 | + "dhcp-rsp-yiaddr": "00000000000000000000ffff00000000", |
| 191 | + "dhcp-rsp-giaddr": "00000000000000000000ffff00000000", |
| 192 | + "dhcp-rsp-siaddr": "00000000000000000000ffff00000000", |
| 193 | + "receive_time": 1554755946, |
| 194 | + "dhcp-rsp-msg-type": 5, |
| 195 | + "dhcp-rsp-subnet-mask": "00000000000000000000ffffffffff00", |
| 196 | + "time_generated": 1554755922, |
| 197 | + "dhcp-rsp-domain-name-server-option": [ |
| 198 | + { |
| 199 | + "dhcp-rsp-dns-addr": "00000000000000000000ffff503a3dfa" |
| 200 | + }, |
| 201 | + { |
| 202 | + "dhcp-rsp-dns-addr": "00000000000000000000ffff503a3dfe" |
| 203 | + } |
| 204 | + ], |
| 205 | + "customer-id": "117270020", |
| 206 | + "serial": "", |
| 207 | + "dhcp-rsp-transaction-id": 3782930258, |
| 208 | + "dhcp-rsp-opcode": 2 |
| 209 | + } |
| 210 | + } |
| 211 | + ] |
| 212 | + }, |
| 213 | + "id": "de0dc306-f2a4-4247-8ace-a47cf92ff558", |
| 214 | + "from": 0, |
| 215 | + "size": 1, |
| 216 | + "completed": true, |
| 217 | + "state": "COMPLETED", |
| 218 | + "timed_out": false |
| 219 | + }, |
| 220 | + "esQuery": { |
| 221 | + "table": [ |
| 222 | + "panw.dpi" |
| 223 | + ], |
| 224 | + "query": { |
| 225 | + "aggregations": {}, |
| 226 | + "query": { |
| 227 | + "term": { |
| 228 | + "{{field_0}}": "{{value_0}}" |
| 229 | + } |
| 230 | + }, |
| 231 | + "size": 1 |
| 232 | + }, |
| 233 | + "selections": [], |
| 234 | + "params": { |
| 235 | + "field_0": "subtype", |
| 236 | + "value_0": "dhcp" |
| 237 | + } |
| 238 | + } |
| 239 | + } |
| 240 | +} |
| 241 | +``` |
| 242 | + |
| 243 | +* **Running the example with an API Explorer developer-token (use case: script lab testing)** |
| 244 | +``` |
| 245 | +$ export PAN_DEVELOPER_TOKEN=<my developer-token> |
| 246 | +$ node index |
| 247 | +PANCLOUD: {"source":"AutoCredentials","message":"Environmental variable PAN_ENTRYPOINT not set. Assuming https://api.us.paloaltonetworks.com"} |
| 248 | +PANCLOUD: {"source":"AutoCredentials","message":"Neither \"PAN_ACCESS_TOKEN\" (for static credentials) nor \"PAN_CLIENT_ID\", \"PAN_CLIENT_SECRET\" and \"PAN_REFRESH_TOKEN\" for a memory-based credentials provider where provider. Will try with developer token credetials"} |
| 249 | +PANCLOUD: {"source":"LoggingService","message":"Creating new LoggingService object for entryPoint https://api.us.paloaltonetworks.com"} |
| 250 | +PANCLOUD: {"source":"LoggingService","message":"*queries* post request. Query: {\"query\":\"SELECT * FROM panw.dpi WHERE subtype='dhcp' LIMIT 1\",\"startTime\":0,\"endTime\":2000000000,\"maxWaitTime\":30000}"} |
| 251 | +PANCLOUD: {"source":"LoggingService","message":"updated authorization header"} |
| 252 | +{ |
| 253 | + "queryId": "1e7ded92-d49a-4afa-97a3-5314f708f950", |
| 254 | + "sequenceNo": 0, |
| 255 | + "queryStatus": "JOB_FINISHED", |
| 256 | + "clientParameters": {}, |
| 257 | + "result": { |
| 258 | + "esResult": { |
| 259 | + "took": 102, |
| 260 | + "hits": { |
| 261 | + "total": 1568, |
| 262 | + "maxScore": 12.697968, |
| 263 | + "hits": [ |
| 264 | + { |
| 265 | + "_index": "117270018_panw.dpi_2019040800-2019042800_000000", |
| 266 | + "_type": "dpi", |
| 267 | + "_id": "117270018_lcaas:0:5351784:864", |
| 268 | + "_score": 12.697968, |
| 269 | + "_source": { |
| 270 | + "dhcp-req-msg-type": 1, |
| 271 | + "dhcp-req-opcode": 1, |
| 272 | + "receive_time": 1554699492, |
| 273 | + "sessionid": 239993, |
| 274 | + "time_generated": 1554699473, |
| 275 | + "dhcp-req-yiaddr": "00000000000000000000ffff00000000", |
| 276 | + "type": "DPI", |
| 277 | + "dhcp-req-host-name": "HIuBtmcklSawAHLVKHBkJbXQBDfKCvo", |
| 278 | + "content_ver": "8138-5378", |
| 279 | + "dhcp-req-giaddr": "00000000000000000000ffff00000000", |
| 280 | + "dhcp-req-chaddr": "db:7b:65:4b:09:c4", |
| 281 | + "txn_id": 1, |
| 282 | + "dhcp-req-transaction-id": 407499899, |
| 283 | + "customer-id": "117270018", |
| 284 | + "serial": "", |
| 285 | + "receptor_txn_start": 1554699472, |
| 286 | + "subtype": "dhcp", |
| 287 | + "dhcp-req-lease-time": 4294967295, |
| 288 | + "dhcp-req-siaddr": "00000000000000000000ffff00000000", |
| 289 | + "client_sw": "8.1.4", |
| 290 | + "recsize": 727, |
| 291 | + "dhcp-req-vendor-class": "Linux 2.4.22 i686", |
| 292 | + "dhcp-req-ciaddr": "00000000000000000000ffff00000000" |
| 293 | + } |
| 294 | + } |
| 295 | + ] |
| 296 | + }, |
| 297 | + "id": "1e7ded92-d49a-4afa-97a3-5314f708f950", |
| 298 | + "from": 0, |
| 299 | + "size": 1, |
| 300 | + "completed": true, |
| 301 | + "state": "COMPLETED", |
| 302 | + "timed_out": false |
| 303 | + }, |
| 304 | + "esQuery": { |
| 305 | + "table": [ |
| 306 | + "panw.dpi" |
| 307 | + ], |
| 308 | + "query": { |
| 309 | + "aggregations": {}, |
| 310 | + "query": { |
| 311 | + "term": { |
| 312 | + "{{field_0}}": "{{value_0}}" |
| 313 | + } |
| 314 | + }, |
| 315 | + "size": 1 |
| 316 | + }, |
| 317 | + "selections": [], |
| 318 | + "params": { |
| 319 | + "field_0": "subtype", |
| 320 | + "value_0": "dhcp" |
| 321 | + } |
| 322 | + } |
| 323 | + } |
| 324 | +} |
| 325 | +``` |
0 commit comments