Skip to content

Commit 7bbf9ac

Browse files
authored
Patch dict (#6)
* Refactor dicts Refactor scan and chunking interface to handle dict with multiple items instead of list of dicts.
1 parent e2f4400 commit 7bbf9ac

File tree

13 files changed

+117
-100
lines changed

13 files changed

+117
-100
lines changed

CHANGELOG

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@ Changelog
33

44
Here you can see the full list of changes between each Nightfall release.
55

6+
Version 0.6.0
7+
-------------
8+
9+
UNRELEASED
10+
11+
- Update scan and chunking interface to handle dict with multiple items
12+
instead of list of dicts.
13+
14+
.. warning::
15+
This is a breaking change compared to version 0.5.0, but all users are
16+
reccomended to upgrade to this version. This version represents an
17+
improvement on the previous iteration where instead of handling a list of
18+
dicts, we now handle a single dict with mulitple entries. This simplifies
19+
the library code and makes the interface much more usable.
20+
21+
The previous version of the SDK required users to pass in a list of dicts.
22+
We now require users to pass in a single dict with multiple entries.
23+
``nightfall.scan([{'id': 'string}])`` should now be
24+
``nightfall.scan({'id': 'string'})``.
25+
626
Version 0.5.0
727
-------------
828

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ nightfall = Nightfall(
2525
os.getenv('NIGHTFALL_CONDITION_SET')
2626
)
2727
28-
response = nightfall.scan([{'id': 'test string'}])
28+
response = nightfall.scan({'id': 'test string'})
2929
3030
print(response)
3131
```

docs/_sources/quickstart.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Import Nightfall and start using methods:
2929
os.getenv('NIGHTFALL_CONDITION_SET')
3030
)
3131

32-
response = nightfall.scan([{'id': 'test string'}])
32+
response = nightfall.scan({'id': 'test string'})
3333

3434
print(response)
3535

docs/api.html

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,38 +209,36 @@ <h3>nightfall.api<a class="headerlink" href="#nightfall-api" title="Permalink to
209209
<dl class="py method">
210210
<dt class="sig sig-object py" id="nightfall.api.Nightfall.make_payloads">
211211
<span class="sig-name descname"><span class="pre">make_payloads</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nightfall.api.Nightfall.make_payloads" title="Permalink to this definition"></a></dt>
212-
<dd><p>Turn a list of dicts <code class="docutils literal notranslate"><span class="pre">[{'id':</span> <span class="pre">'string'},]</span></code> into a list of
213-
acceptable payloads.</p>
212+
<dd><p>Turn a dict into a list of acceptable payloads.</p>
214213
<p>Creates chunks based on the <code class="docutils literal notranslate"><span class="pre">MAX_PAYLOAD_SIZE</span></code> and <code class="docutils literal notranslate"><span class="pre">MAX_NUM_ITEMS</span></code>
215214
constants.</p>
216-
<p>When the number of items in a list is greater than <code class="docutils literal notranslate"><span class="pre">MAX_NUM_ITEMS</span></code>
217-
we will split the list into multiple lists. When the total sum of all
218-
strings in a list is greater than <code class="docutils literal notranslate"><span class="pre">MAX_PAYLOAD_SIZE</span></code>, we will split
219-
that list into multiple lists.</p>
215+
<p>When the number of items in a dict is greater than <code class="docutils literal notranslate"><span class="pre">MAX_NUM_ITEMS</span></code>
216+
or total sum of all strings in a dict is greater than
217+
<code class="docutils literal notranslate"><span class="pre">MAX_PAYLOAD_SIZE</span></code>, we will split that dict into multiple dicts.</p>
220218
<dl class="field-list simple">
221219
<dt class="field-odd">Parameters</dt>
222-
<dd class="field-odd"><p><strong>data</strong> (<em>list</em>) – list of dicts</p>
220+
<dd class="field-odd"><p><strong>data</strong> (<em>list</em>) – dict in form of <code class="docutils literal notranslate"><span class="pre">{'id':</span> <span class="pre">'string',}</span></code></p>
223221
</dd>
224222
<dt class="field-even">Raises</dt>
225223
<dd class="field-even"><p><a class="reference internal" href="#nightfall.exceptions.InputError" title="nightfall.exceptions.InputError"><strong>InputError</strong></a> – when individual dictionary item is larger than
226224
<code class="docutils literal notranslate"><span class="pre">MAX_PAYLOAD_SIZE</span></code></p>
227225
</dd>
228226
<dt class="field-odd">Returns</dt>
229-
<dd class="field-odd"><p>list of list of dicts to scan</p>
227+
<dd class="field-odd"><p>list of dicts to scan</p>
230228
</dd>
231229
</dl>
232230
</dd></dl>
233231

234232
<dl class="py method">
235233
<dt class="sig sig-object py" id="nightfall.api.Nightfall.scan">
236234
<span class="sig-name descname"><span class="pre">scan</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nightfall.api.Nightfall.scan" title="Permalink to this definition"></a></dt>
237-
<dd><p>Scan lists of data with Nightfall.</p>
238-
<p>This method will convert the list of dicts into chunks if necessary
235+
<dd><p>Scan data with Nightfall.</p>
236+
<p>This method will convert a dict into chunks if necessary
239237
and then makes one or more requests to the Nightfall API to scan the
240238
data.</p>
241239
<p>data dicts should be in the following format:</p>
242240
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
243-
<span class="s2">&quot;id123&quot;</span><span class="p">:</span> <span class="s2">&quot;string_to_scan&quot;</span>
241+
<span class="s2">&quot;id123&quot;</span><span class="p">:</span> <span class="s2">&quot;string_to_scan&quot;</span><span class="p">,</span>
244242
<span class="p">}</span>
245243
</pre></div>
246244
</div>
@@ -249,16 +247,16 @@ <h3>nightfall.api<a class="headerlink" href="#nightfall-api" title="Permalink to
249247
and is not considered sensitive.</p>
250248
<p>response dicts are in the form of:</p>
251249
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
252-
<span class="s2">&quot;id123&quot;</span><span class="p">:</span> <span class="p">[{</span><span class="n">nightfall_findings</span><span class="p">},]</span> <span class="ow">or</span> <span class="kc">None</span>
250+
<span class="s2">&quot;id123&quot;</span><span class="p">:</span> <span class="p">[{</span><span class="n">nightfall_findings</span><span class="p">},]</span> <span class="ow">or</span> <span class="kc">None</span><span class="p">,</span>
253251
<span class="p">}</span>
254252
</pre></div>
255253
</div>
256254
<dl class="field-list simple">
257255
<dt class="field-odd">Parameters</dt>
258-
<dd class="field-odd"><p><strong>data</strong> (<em>list</em>) – list of dicts to scan.</p>
256+
<dd class="field-odd"><p><strong>data</strong> (<em>dict</em>) – dict to scan.</p>
259257
</dd>
260258
<dt class="field-even">Returns</dt>
261-
<dd class="field-even"><p>list of list of dicts for items in payload.</p>
259+
<dd class="field-even"><p>dict with findings.</p>
262260
</dd>
263261
</dl>
264262
</dd></dl>

docs/changelog.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
</ul>
9595
<ul class="current">
9696
<li class="toctree-l1 current"><a class="current reference internal" href="#">Changelog</a><ul>
97+
<li class="toctree-l2"><a class="reference internal" href="#version-0-6-0">Version 0.6.0</a></li>
9798
<li class="toctree-l2"><a class="reference internal" href="#version-0-5-0">Version 0.5.0</a></li>
9899
<li class="toctree-l2"><a class="reference internal" href="#version-0-4-0">Version 0.4.0</a></li>
99100
<li class="toctree-l2"><a class="reference internal" href="#version-0-3-0">Version 0.3.0</a></li>
@@ -170,6 +171,26 @@
170171
<div class="section" id="changelog">
171172
<h1>Changelog<a class="headerlink" href="#changelog" title="Permalink to this headline"></a></h1>
172173
<p>Here you can see the full list of changes between each Nightfall release.</p>
174+
<div class="section" id="version-0-6-0">
175+
<h2>Version 0.6.0<a class="headerlink" href="#version-0-6-0" title="Permalink to this headline"></a></h2>
176+
<p>UNRELEASED</p>
177+
<ul class="simple">
178+
<li><p>Update scan and chunking interface to handle dict with multiple items
179+
instead of list of dicts.</p></li>
180+
</ul>
181+
<div class="admonition warning">
182+
<p class="admonition-title">Warning</p>
183+
<p>This is a breaking change compared to version 0.5.0, but all users are
184+
reccomended to upgrade to this version. This version represents an
185+
improvement on the previous iteration where instead of handling a list of
186+
dicts, we now handle a single dict with mulitple entries. This simplifies
187+
the library code and makes the interface much more usable.</p>
188+
<p>The previous version of the SDK required users to pass in a list of dicts.
189+
We now require users to pass in a single dict with multiple entries.
190+
<code class="docutils literal notranslate"><span class="pre">nightfall.scan([{'id':</span> <span class="pre">'string}])</span></code> should now be
191+
<code class="docutils literal notranslate"><span class="pre">nightfall.scan({'id':</span> <span class="pre">'string'})</span></code>.</p>
192+
</div>
193+
</div>
173194
<div class="section" id="version-0-5-0">
174195
<h2>Version 0.5.0<a class="headerlink" href="#version-0-5-0" title="Permalink to this headline"></a></h2>
175196
<p>Released on July 12, 2021</p>

docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ <h2>Changelog<a class="headerlink" href="#changelog" title="Permalink to this he
196196
<div class="toctree-wrapper compound">
197197
<ul>
198198
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog</a><ul>
199+
<li class="toctree-l2"><a class="reference internal" href="changelog.html#version-0-6-0">Version 0.6.0</a></li>
199200
<li class="toctree-l2"><a class="reference internal" href="changelog.html#version-0-5-0">Version 0.5.0</a></li>
200201
<li class="toctree-l2"><a class="reference internal" href="changelog.html#version-0-4-0">Version 0.4.0</a></li>
201202
<li class="toctree-l2"><a class="reference internal" href="changelog.html#version-0-3-0">Version 0.3.0</a></li>

docs/quickstart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ <h2>Basic Usage<a class="headerlink" href="#basic-usage" title="Permalink to thi
191191
<span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s1">&#39;NIGHTFALL_CONDITION_SET&#39;</span><span class="p">)</span>
192192
<span class="p">)</span>
193193

194-
<span class="n">response</span> <span class="o">=</span> <span class="n">nightfall</span><span class="o">.</span><span class="n">scan</span><span class="p">([{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="s1">&#39;test string&#39;</span><span class="p">}])</span>
194+
<span class="n">response</span> <span class="o">=</span> <span class="n">nightfall</span><span class="o">.</span><span class="n">scan</span><span class="p">({</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="s1">&#39;test string&#39;</span><span class="p">})</span>
195195

196196
<span class="nb">print</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
197197
</pre></div>

docs/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docsrc/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Import Nightfall and start using methods:
2929
os.getenv('NIGHTFALL_CONDITION_SET')
3030
)
3131

32-
response = nightfall.scan([{'id': 'test string'}])
32+
response = nightfall.scan({'id': 'test string'})
3333

3434
print(response)
3535

0 commit comments

Comments
 (0)