Skip to content

Commit

Permalink
Merge branch 'ns1:master' into jeremypng-rest.ipam.reservations.list-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypng authored Feb 14, 2022
2 parents 90e3108 + c365c02 commit 6f6d906
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 33 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '41 11 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# 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

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
queries: ns1/NS1QLPacks/codeql/${{ matrix.language }}/NS1-security.qls@main
config-file: ns1/NS1QLPacks/codeql/NS1-codeql-config.yml@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
25 changes: 25 additions & 0 deletions .github/workflows/issue_notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This workflow is triggered by github issue and creates a jira ticket in the respective configured account
#
name: issue_notify
on:
issues:
types: [opened]
workflow_dispatch:
jobs:
jira_job:
runs-on: ubuntu-latest
steps:
- name: Jira Login
uses: atlassian/[email protected]
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL}}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL}}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN}}
- name: Jira Create issue
id: jira_ticket
uses: atlassian/[email protected]
with:
project: ${{secrets.JIRA_PROJECT_KEY}}
issuetype: Bug
summary: '[ns1-python] ${{github.event.issue.title}}'
description: ${{github.event.issue.body}} see more at ${{github.event.issue.html_url}}
33 changes: 33 additions & 0 deletions .github/workflows/pr_notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow is triggered by pull request and creates an jira ticket if the ticket does not exist in jira
#
name: pr_notify
on:
pull_request:
branches: [master]
jobs:
jira_job:
runs-on: ubuntu-latest
steps:
- name: Jira Login
uses: atlassian/[email protected]
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
# try to find jira key in the PR title
- name: Find jirakey in title
id: jira_founded_ticket
uses: atlassian/gajira-find-issue-key@master
continue-on-error: true
with:
string: ${{ github.event.pull_request.title }}
# if there is no ticket associated then create a new one
- name: Jira Create issue
id: jira_ticket
if: ${{!steps.jira_founded_ticket.outputs.issue}}
uses: atlassian/[email protected]
with:
project: ${{secrets.JIRA_PROJECT_KEY}}
issuetype: Task
summary: '[ns1-python] ${{github.event.pull_request.title}}'
description: ${{github.event.pull_request.body}} see more at ${{github.event.pull_request.html_url}}
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build distribution

on: [push, pull_request]

jobs:
test:
runs-on: "ubuntu-latest"

steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install build dependencies
run: python -m pip install build wheel

- name: Build distributions
shell: bash -l {0}
run: python setup.py sdist bdist_wheel

- name: Publish package to PyPI
if: github.repository == 'ns1/ns1-python' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.ns1_python_publish }}
1 change: 1 addition & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade setuptools
python setup.py install
python setup.py bdist_wheel
python -m pip install --upgrade pip
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## 0.17.0 (Unreleased)
## 0.17.1 (October 27, 2021)
BUG FIXES:
* Fixes a casing issue on a search parameter

## 0.17.0 (October 27, 2021)
ENHANCEMENTS
* Move from deprecated search endpoint to supported search endpoint

## 0.16.1 (September 1, 2021)

ENHANCEMENTS
* Re-use connections with Session objects in RequestsTransport

## 0.16.0 (May 18, 2020)

Expand Down
33 changes: 25 additions & 8 deletions ns1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
from .config import Config

version = "0.16.0"
version = "0.17.1"


class NS1:
Expand Down Expand Up @@ -248,16 +248,28 @@ def loadZone(self, zone, callback=None, errback=None):
return zone.load(callback=callback, errback=errback)

def searchZone(
self, zone, q=None, has_geo=False, callback=None, errback=None
self,
query,
type="all",
expand=True,
max=None,
callback=None,
errback=None,
):
"""
Search a zone for a given search query (e.g., for geological data, etc)
This method was updated since NS1 deprecated v1/search/zones
Search a zone record or answers for a given search query (e.g., for geological data, etc)
:param zone: NOT a string like loadZone - an already loaded ns1.zones.Zone, like one returned from loadZone
:return:
:param query: query to search zone name or other type name
:param type: String Filters search results by type. Enum: "zone", "record", "all", "answers"
:param expand: Boolean Expands contents of search results.
:param max: Integer Maximum number of search results to display
:return: list of zones searched
"""
from ns1.rest.zones import Zones

return zone.search(q, has_geo, callback=callback, errback=errback)
rest_zone = Zones(self.config)
return rest_zone.search(query, type, expand, max, callback, errback)

def createZone(
self, zone, zoneFile=None, callback=None, errback=None, **kwargs
Expand Down Expand Up @@ -513,12 +525,17 @@ def createReservation(
return reservation.create(callback=callback, errback=errback, **kwargs)

def loadReservation(
self, scopegroup_id, address_id, callback=None, errback=None
self,
scopegroup_id,
address_id,
reservation_id=None,
callback=None,
errback=None,
):
import ns1.ipam

reservation = ns1.ipam.Reservation(
self.config, scopegroup_id, address_id
self.config, scopegroup_id, address_id, reservation_id
)

return reservation.load(callback=callback, errback=errback)
Expand Down
9 changes: 5 additions & 4 deletions ns1/rest/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ def __init__(self, config):
if not have_requests:
raise ImportError("requests module required for RequestsTransport")
TransportBase.__init__(self, config, self.__module__)
self.session = requests.Session()
self.REQ_MAP = {
"GET": requests.get,
"POST": requests.post,
"DELETE": requests.delete,
"PUT": requests.put,
"GET": self.session.get,
"POST": self.session.post,
"DELETE": self.session.delete,
"PUT": self.session.put,
}
self._timeout = self._config.get("timeout", None)
if isinstance(self._timeout, list) and len(self._timeout) == 2:
Expand Down
25 changes: 16 additions & 9 deletions ns1/rest/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class Zones(resource.BaseResource):

ROOT = "zones"
SEARCH_ROOT = "search"

Expand Down Expand Up @@ -87,16 +86,24 @@ def retrieve(self, zone, callback=None, errback=None):
pagination_handler=zone_retrieve_pagination,
)

def search(self, zone, q=None, has_geo=False, callback=None, errback=None):
params = {}
if q is not None:
params["q"] = q
if has_geo:
params["geo"] = has_geo
def search(
self,
query,
type="all",
expand=True,
max=None,
callback=None,
errback=None,
):
request = "{}?q={}&type={}&expand={}".format(
self.SEARCH_ROOT, query, type, str.lower(str(expand))
)
if max is not None:
request += "&max=" + str(max)
return self._make_request(
"GET",
"%s/zone/%s" % (self.SEARCH_ROOT, zone),
params=params,
request,
params={},
callback=callback,
errback=errback,
)
Expand Down
11 changes: 0 additions & 11 deletions ns1/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
# License under The MIT License (MIT). See LICENSE in project root.
#

from ns1.rest.zones import Zones
from ns1.records import Record
from ns1.rest.stats import Stats
Expand All @@ -15,7 +14,6 @@ class ZoneException(Exception):


class Zone(object):

"""
High level object representing a Zone. In addition to the documented
methods, there are magic methods allowing easy creation of records in this
Expand Down Expand Up @@ -65,15 +63,6 @@ def success(result, *args):
self.zone, callback=success, errback=errback
)

def search(self, q=None, has_geo=False, callback=None, errback=None):
"""
Search within a zone for specific metadata. Zone must already be loaded.
"""
if not self.data:
raise ZoneException("zone not loaded")

return self._rest.search(self.zone, q, has_geo, callback, errback)

def delete(self, callback=None, errback=None):
"""
Delete the zone and ALL records it contains.
Expand Down

0 comments on commit 6f6d906

Please sign in to comment.