Skip to content

Commit fade841

Browse files
Merge pull request #207 from censys/adh/deprecate-v1
Remove Deprecated v1 API Endpoints
2 parents 71d62db + 5a3ad3d commit fade841

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+335
-397
lines changed

censys/asm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""An easy-to-use and lightweight API wrapper for Censys ASM (censys.io)."""
1+
"""An easy-to-use and lightweight API wrapper for Censys ASM (app.censys.io)."""
22
from .assets import Assets, CertificatesAssets, DomainsAssets, HostsAssets
33
from .client import AsmClient
44
from .clouds import Clouds

censys/cli/commands/search.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,14 @@
55
from typing import List
66
from urllib.parse import urlencode
77

8-
from censys.cli.utils import INDEXES, V1_INDEXES, V2_INDEXES, console, write_file
8+
from censys.cli.utils import INDEXES, V1_INDEXES, V2_INDEXES, err_console, write_file
99
from censys.common.exceptions import CensysCLIException
1010
from censys.search import SearchClient
1111

1212
Fields = List[str]
1313
Results = List[dict]
1414

1515
DEFAULT_FIELDS = {
16-
"ipv4": [
17-
"updated_at",
18-
"protocols",
19-
"metadata.description",
20-
"autonomous_system.name",
21-
"23.telnet.banner.banner",
22-
"80.http.get.title",
23-
"80.http.get.metadata.description",
24-
"8080.http.get.metadata.description",
25-
"8888.http.get.metadata.description",
26-
"443.https.get.metadata.description",
27-
"443.https.get.title",
28-
"443.https.tls.certificate.parsed.subject_dn",
29-
"443.https.tls.certificate.parsed.names",
30-
"443.https.tls.certificate.parsed.subject.common_name",
31-
"443.https.tls.certificate.parsed.extensions.subject_alt_name.dns_names",
32-
],
3316
"certs": [
3417
"metadata.updated_at",
3518
"parsed.issuer.common_name",
@@ -44,15 +27,6 @@
4427
"metadata.seen_in_scan",
4528
"tags",
4629
],
47-
"websites": [
48-
"443.https.tls.version",
49-
"alexa_rank",
50-
"domain",
51-
"ports",
52-
"protocols",
53-
"tags",
54-
"updated_at",
55-
],
5630
}
5731

5832

@@ -69,17 +43,12 @@ def cli_search(args: argparse.Namespace):
6943

7044
if args.open:
7145
url_query = {"q": args.query}
72-
if index_type in V1_INDEXES:
73-
if index_type == "certs":
74-
index_type = "certificates"
75-
# TODO: Remove when v1 is fully deprecated
76-
webbrowser.open(
77-
f"https://search.censys.io/{index_type}?{urlencode(url_query)}"
78-
)
79-
sys.exit(0)
80-
webbrowser.open(f"https://censys.io/{index_type}?{urlencode(url_query)}")
46+
if index_type in {"certs", "certificates"}:
47+
webbrowser.open(
48+
f"https://search.censys.io/certificates?{urlencode(url_query)}"
49+
)
8150
sys.exit(0)
82-
elif index_type in V2_INDEXES:
51+
if index_type in V2_INDEXES:
8352
url_query.update({"resource": index_type})
8453
webbrowser.open(f"https://search.censys.io/search?{urlencode(url_query)}")
8554
sys.exit(0)
@@ -120,7 +89,7 @@ def cli_search(args: argparse.Namespace):
12089

12190
search_args["fields"] = fields
12291

123-
with console.status("Searching"):
92+
with err_console.status("Searching"):
12493
results = list(index.search(args.query, **search_args))
12594
elif index_type in V2_INDEXES:
12695
if args.format == "csv":
@@ -132,7 +101,7 @@ def cli_search(args: argparse.Namespace):
132101
if args.pages:
133102
search_args["pages"] = args.pages
134103

135-
with console.status("Searching"):
104+
with err_console.status("Searching"):
136105
query = index.search(args.query, **search_args)
137106

138107
results = []
@@ -142,7 +111,7 @@ def cli_search(args: argparse.Namespace):
142111
try:
143112
write_file(results, **write_args)
144113
except ValueError as error: # pragma: no cover
145-
console.print(f"Error writing log file. Error: {error}")
114+
err_console.print(f"Error writing log file. Error: {error}")
146115

147116

148117
def include(parent_parser: argparse._SubParsersAction, parents: dict):

censys/cli/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime
55
import json
66
import os.path
7+
import sys
78
from typing import Any, Dict, List, Optional, Union
89

910
from rich.console import Console
@@ -14,13 +15,15 @@
1415
Fields = List[str]
1516
Results = Union[List[dict], Dict[str, Any]]
1617

17-
V1_INDEXES = ["ipv4", "certs", "websites"]
18+
V1_INDEXES = ["certs"]
1819
V2_INDEXES = ["hosts"]
1920
INDEXES = V1_INDEXES + V2_INDEXES
2021

2122
config = get_config()
2223
color = config.get(DEFAULT, "color")
23-
console = Console(color_system=("auto" if color else None))
24+
color_system = "auto" if color else None
25+
console = Console(color_system=color_system) # type: ignore
26+
err_console = Console(color_system=color_system, file=sys.stderr) # type: ignore
2427

2528

2629
def print_wrote_file(file_path: str):

censys/search/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
"""An easy-to-use and lightweight API wrapper for Censys Search API (censys.io)."""
1+
"""An easy-to-use and lightweight API wrapper for Censys Search API (search.censys.io)."""
22
from .client import SearchClient
3-
from .v1 import CensysCertificates, CensysData, CensysIPv4, CensysWebsites
3+
from .v1 import CensysCertificates, CensysData
44
from .v2 import CensysCerts, CensysHosts
55

66
__copyright__ = "Copyright 2021 Censys, Inc."
77
__all__ = [
88
"SearchClient",
99
"CensysCertificates",
1010
"CensysData",
11-
"CensysIPv4",
12-
"CensysWebsites",
1311
"CensysCerts",
1412
"CensysHosts",
1513
]

censys/search/client.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Interact with all Search APIs."""
22
from ..common.deprecation import DeprecationDecorator
3-
from .v1 import CensysCertificates, CensysData, CensysIPv4, CensysWebsites
3+
from .v1 import CensysCertificates, CensysData
44
from .v2 import CensysCerts, CensysHosts
55

66

@@ -19,8 +19,6 @@ class SearchClient:
1919
2020
>>> certs = c.v1.certificates # CensysCertificates()
2121
>>> data = c.v1.data # CensysData()
22-
>>> ipv4 = c.v1.ipv4 # CensysIPv4()
23-
>>> websites = c.v1.websites # CensysWebsites()
2422
>>> hosts = c.v2.hosts # CensysHosts()
2523
>>> certs = c.v2.certs # CensysCerts()
2624
"""
@@ -42,8 +40,6 @@ def __init__(self, *args, **kwargs):
4240
# Alias certs to certificates
4341
self.certs = self.certificates
4442
self.data = CensysData(*args, **kwargs)
45-
self.ipv4 = CensysIPv4(*args, **kwargs)
46-
self.websites = CensysWebsites(*args, **kwargs)
4743

4844
class _V2:
4945
"""Class for v2 Search APIs."""

censys/search/v1/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Interact with the Censys Search v1 APIs."""
22
from .certificates import CensysCertificates
33
from .data import CensysData
4-
from .ipv4 import CensysIPv4
5-
from .websites import CensysWebsites
64

7-
__all__ = ["CensysCertificates", "CensysData", "CensysIPv4", "CensysWebsites"]
5+
__all__ = ["CensysCertificates", "CensysData"]

censys/search/v1/api.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class CensysSearchAPIv1(CensysAPIBase):
1919
"""This class is the base class for all v1 API indexes."""
2020

21-
DEFAULT_URL: str = "https://censys.io/api/v1"
21+
DEFAULT_URL: str = "https://search.censys.io/api/v1"
2222
"""Default Search API base URL."""
2323
INDEX_NAME: Optional[str] = None
2424
"""Name of Censys Index."""
@@ -112,7 +112,7 @@ def search(
112112
) -> Iterator[dict]:
113113
"""Searches the given index for all records that match the given query.
114114
115-
For more details, see our documentation: https://censys.io/api/v1/docs/search
115+
For more details, see our documentation: https://search.censys.io/api
116116
117117
Args:
118118
query (str): The query to be executed.
@@ -152,7 +152,7 @@ def search(
152152
def view(self, document_id: str) -> dict:
153153
"""View the current structured data we have on a specific document.
154154
155-
For more details, see our documentation: https://censys.io/api/v1/docs/view
155+
For more details, see our documentation: https://search.censys.io/api
156156
157157
Args:
158158
document_id (str): The ID of the document you are requesting.
@@ -165,7 +165,7 @@ def view(self, document_id: str) -> dict:
165165
def report(self, query: str, field: str, buckets: int = 50) -> dict:
166166
"""Creates a report on the breakdown of the values of a field in a result set.
167167
168-
For more details, see our documentation: https://censys.io/api/v1/docs/report
168+
For more details, see our documentation: https://search.censys.io/api
169169
170170
Args:
171171
query (str): The query to be executed.
@@ -177,6 +177,3 @@ def report(self, query: str, field: str, buckets: int = 50) -> dict:
177177
"""
178178
data = {"query": query, "field": field, "buckets": int(buckets)}
179179
return self._post(self.report_path, data=data)
180-
181-
182-
CensysSearchAPI = CensysSearchAPIv1

censys/search/v1/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class CensysData(CensysSearchAPIv1):
66
"""Interacts with the Data index.
77
8-
For more details, see our documentation: https://censys.io/api/v1/docs/data
8+
For more details, see our documentation: https://search.censys.io/api
99
"""
1010

1111
_PREFIX = "/data"

censys/search/v1/ipv4.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

censys/search/v1/websites.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)