Skip to content

Commit 6f6d906

Browse files
authored
Merge branch 'ns1:master' into jeremypng-rest.ipam.reservations.list-fix
2 parents 90e3108 + c365c02 commit 6f6d906

10 files changed

Lines changed: 220 additions & 33 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ master ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ master ]
20+
schedule:
21+
- cron: '41 11 * * 6'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'python' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37+
# Learn more:
38+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v2
43+
44+
# Initializes the CodeQL tools for scanning.
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v1
47+
with:
48+
languages: ${{ matrix.language }}
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53+
queries: ns1/NS1QLPacks/codeql/${{ matrix.language }}/NS1-security.qls@main
54+
config-file: ns1/NS1QLPacks/codeql/NS1-codeql-config.yml@main
55+
56+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57+
# If this step fails, then you should remove it and run the build manually (see below)
58+
- name: Autobuild
59+
uses: github/codeql-action/autobuild@v1
60+
61+
# ℹ️ Command-line programs to run using the OS shell.
62+
# 📚 https://git.io/JvXDl
63+
64+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
65+
# and modify them (or add more) to build your code if your project
66+
# uses a compiled language
67+
68+
#- run: |
69+
# make bootstrap
70+
# make release
71+
72+
- name: Perform CodeQL Analysis
73+
uses: github/codeql-action/analyze@v1

.github/workflows/issue_notify.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This workflow is triggered by github issue and creates a jira ticket in the respective configured account
2+
#
3+
name: issue_notify
4+
on:
5+
issues:
6+
types: [opened]
7+
workflow_dispatch:
8+
jobs:
9+
jira_job:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Jira Login
13+
uses: atlassian/gajira-login@v2.0.0
14+
env:
15+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL}}
16+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL}}
17+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN}}
18+
- name: Jira Create issue
19+
id: jira_ticket
20+
uses: atlassian/gajira-create@v2.0.1
21+
with:
22+
project: ${{secrets.JIRA_PROJECT_KEY}}
23+
issuetype: Bug
24+
summary: '[ns1-python] ${{github.event.issue.title}}'
25+
description: ${{github.event.issue.body}} see more at ${{github.event.issue.html_url}}

.github/workflows/pr_notify.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow is triggered by pull request and creates an jira ticket if the ticket does not exist in jira
2+
#
3+
name: pr_notify
4+
on:
5+
pull_request:
6+
branches: [master]
7+
jobs:
8+
jira_job:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Jira Login
12+
uses: atlassian/gajira-login@v2.0.0
13+
env:
14+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
15+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
16+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
17+
# try to find jira key in the PR title
18+
- name: Find jirakey in title
19+
id: jira_founded_ticket
20+
uses: atlassian/gajira-find-issue-key@master
21+
continue-on-error: true
22+
with:
23+
string: ${{ github.event.pull_request.title }}
24+
# if there is no ticket associated then create a new one
25+
- name: Jira Create issue
26+
id: jira_ticket
27+
if: ${{!steps.jira_founded_ticket.outputs.issue}}
28+
uses: atlassian/gajira-create@v2.0.1
29+
with:
30+
project: ${{secrets.JIRA_PROJECT_KEY}}
31+
issuetype: Task
32+
summary: '[ns1-python] ${{github.event.pull_request.title}}'
33+
description: ${{github.event.pull_request.body}} see more at ${{github.event.pull_request.html_url}}

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Build distribution
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: "ubuntu-latest"
8+
9+
steps:
10+
- name: Checkout source
11+
uses: actions/checkout@v2
12+
13+
- name: Set up Python 3.8
14+
uses: actions/setup-python@v1
15+
with:
16+
python-version: 3.8
17+
18+
- name: Install build dependencies
19+
run: python -m pip install build wheel
20+
21+
- name: Build distributions
22+
shell: bash -l {0}
23+
run: python setup.py sdist bdist_wheel
24+
25+
- name: Publish package to PyPI
26+
if: github.repository == 'ns1/ns1-python' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
27+
uses: pypa/gh-action-pypi-publish@master
28+
with:
29+
user: __token__
30+
password: ${{ secrets.ns1_python_publish }}

.github/workflows/verify.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
python-version: ${{ matrix.python-version }}
4343
- name: Install dependencies
4444
run: |
45+
pip install --upgrade setuptools
4546
python setup.py install
4647
python setup.py bdist_wheel
4748
python -m pip install --upgrade pip

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
## 0.17.0 (Unreleased)
1+
## 0.17.1 (October 27, 2021)
2+
BUG FIXES:
3+
* Fixes a casing issue on a search parameter
4+
5+
## 0.17.0 (October 27, 2021)
6+
ENHANCEMENTS
7+
* Move from deprecated search endpoint to supported search endpoint
8+
9+
## 0.16.1 (September 1, 2021)
10+
11+
ENHANCEMENTS
12+
* Re-use connections with Session objects in RequestsTransport
213

314
## 0.16.0 (May 18, 2020)
415

ns1/__init__.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
from .config import Config
77

8-
version = "0.16.0"
8+
version = "0.17.1"
99

1010

1111
class NS1:
@@ -248,16 +248,28 @@ def loadZone(self, zone, callback=None, errback=None):
248248
return zone.load(callback=callback, errback=errback)
249249

250250
def searchZone(
251-
self, zone, q=None, has_geo=False, callback=None, errback=None
251+
self,
252+
query,
253+
type="all",
254+
expand=True,
255+
max=None,
256+
callback=None,
257+
errback=None,
252258
):
253259
"""
254-
Search a zone for a given search query (e.g., for geological data, etc)
260+
This method was updated since NS1 deprecated v1/search/zones
261+
Search a zone record or answers for a given search query (e.g., for geological data, etc)
255262
256-
:param zone: NOT a string like loadZone - an already loaded ns1.zones.Zone, like one returned from loadZone
257-
:return:
263+
:param query: query to search zone name or other type name
264+
:param type: String Filters search results by type. Enum: "zone", "record", "all", "answers"
265+
:param expand: Boolean Expands contents of search results.
266+
:param max: Integer Maximum number of search results to display
267+
:return: list of zones searched
258268
"""
269+
from ns1.rest.zones import Zones
259270

260-
return zone.search(q, has_geo, callback=callback, errback=errback)
271+
rest_zone = Zones(self.config)
272+
return rest_zone.search(query, type, expand, max, callback, errback)
261273

262274
def createZone(
263275
self, zone, zoneFile=None, callback=None, errback=None, **kwargs
@@ -513,12 +525,17 @@ def createReservation(
513525
return reservation.create(callback=callback, errback=errback, **kwargs)
514526

515527
def loadReservation(
516-
self, scopegroup_id, address_id, callback=None, errback=None
528+
self,
529+
scopegroup_id,
530+
address_id,
531+
reservation_id=None,
532+
callback=None,
533+
errback=None,
517534
):
518535
import ns1.ipam
519536

520537
reservation = ns1.ipam.Reservation(
521-
self.config, scopegroup_id, address_id
538+
self.config, scopegroup_id, address_id, reservation_id
522539
)
523540

524541
return reservation.load(callback=callback, errback=errback)

ns1/rest/transport/requests.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ def __init__(self, config):
2626
if not have_requests:
2727
raise ImportError("requests module required for RequestsTransport")
2828
TransportBase.__init__(self, config, self.__module__)
29+
self.session = requests.Session()
2930
self.REQ_MAP = {
30-
"GET": requests.get,
31-
"POST": requests.post,
32-
"DELETE": requests.delete,
33-
"PUT": requests.put,
31+
"GET": self.session.get,
32+
"POST": self.session.post,
33+
"DELETE": self.session.delete,
34+
"PUT": self.session.put,
3435
}
3536
self._timeout = self._config.get("timeout", None)
3637
if isinstance(self._timeout, list) and len(self._timeout) == 2:

ns1/rest/zones.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class Zones(resource.BaseResource):
11-
1211
ROOT = "zones"
1312
SEARCH_ROOT = "search"
1413

@@ -87,16 +86,24 @@ def retrieve(self, zone, callback=None, errback=None):
8786
pagination_handler=zone_retrieve_pagination,
8887
)
8988

90-
def search(self, zone, q=None, has_geo=False, callback=None, errback=None):
91-
params = {}
92-
if q is not None:
93-
params["q"] = q
94-
if has_geo:
95-
params["geo"] = has_geo
89+
def search(
90+
self,
91+
query,
92+
type="all",
93+
expand=True,
94+
max=None,
95+
callback=None,
96+
errback=None,
97+
):
98+
request = "{}?q={}&type={}&expand={}".format(
99+
self.SEARCH_ROOT, query, type, str.lower(str(expand))
100+
)
101+
if max is not None:
102+
request += "&max=" + str(max)
96103
return self._make_request(
97104
"GET",
98-
"%s/zone/%s" % (self.SEARCH_ROOT, zone),
99-
params=params,
105+
request,
106+
params={},
100107
callback=callback,
101108
errback=errback,
102109
)

ns1/zones.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44
# License under The MIT License (MIT). See LICENSE in project root.
55
#
6-
76
from ns1.rest.zones import Zones
87
from ns1.records import Record
98
from ns1.rest.stats import Stats
@@ -15,7 +14,6 @@ class ZoneException(Exception):
1514

1615

1716
class Zone(object):
18-
1917
"""
2018
High level object representing a Zone. In addition to the documented
2119
methods, there are magic methods allowing easy creation of records in this
@@ -65,15 +63,6 @@ def success(result, *args):
6563
self.zone, callback=success, errback=errback
6664
)
6765

68-
def search(self, q=None, has_geo=False, callback=None, errback=None):
69-
"""
70-
Search within a zone for specific metadata. Zone must already be loaded.
71-
"""
72-
if not self.data:
73-
raise ZoneException("zone not loaded")
74-
75-
return self._rest.search(self.zone, q, has_geo, callback, errback)
76-
7766
def delete(self, callback=None, errback=None):
7867
"""
7968
Delete the zone and ALL records it contains.

0 commit comments

Comments
 (0)