Jelajahi Sumber

Added requests example for salt api

nee2c 4 tahun lalu
induk
melakukan
90e7e61c5a
1 mengubah file dengan 27 tambahan dan 0 penghapusan
  1. 27 0
      api/requestsexample.py

+ 27 - 0
api/requestsexample.py

@@ -0,0 +1,27 @@
+import requests
+
+surl = 'https://localhost:32768'
+auth = {'username': 'salt', 'password':'foobar', 'eauth':'sharedsecret'}
+ver = False
+
+with requests.Session() as s:
+    res = s.post(url=f'{surl}/login', json=auth, verify=ver)
+    print(res.text)
+
+
+    resp = s.post('https://localhost:32768', json=[{
+    'client': 'local',
+    'tgt': '*',
+    'fun': 'network.ipaddrs'
+    }],
+    verify=False)
+    print(resp.text)
+
+    resp = s.post('https://localhost:32768', json=[{
+    'client': 'local',
+    'tgt': '*',
+    'fun': 'file.readdir',
+    'arg': ['/etc/']
+    }],
+    verify=False)
+    print(resp.text)