Skip to content

Commit

Permalink
- FIX: search result were applied on the first 250, implemented pagin…
Browse files Browse the repository at this point in the history
…ation scan (solves issue #10)

- Update of Open Source license headers (year, adding missing one)
- Bump version to 0.4.7
  • Loading branch information
bitonio committed Apr 12, 2022
1 parent c50cbcb commit 1cd5e02
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 23 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.6
0.4.7
62 changes: 48 additions & 14 deletions bin/akamai-eaa
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2021 Akamai Technologies, Inc. All Rights Reserved
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@ import fnmatch
import signal
import http.client as http_client
from json import dumps
from math import ceil

# cli-eaa
import _paths
Expand All @@ -45,6 +46,7 @@ verbose = getattr(config, 'verbose', False)

LOG_FMT = '%(asctime)s %(name)s %(levelname).1s %(message)s'


class SearchAPI(BaseAPI):
"""
Search EAA applications
Expand All @@ -57,17 +59,55 @@ class SearchAPI(BaseAPI):
super(SearchAPI, self).__init__(config, api=BaseAPI.API_Version.OpenAPI)

def search_app(self, search_pattern):
url_params = {'limit': SearchAPI.SCAN_LIMIT, 'expand': 'true'}
search_app = self.get('mgmt-pop/apps', params=url_params)
self.process_response(search_app.json(), search_pattern)
"""
Search for a particular application pattern, or all if no pattern is provided.
Corresponding API documentation: https://techdocs.akamai.com/eaa-api/reference/get-apps
"""

def process_response(self, data, search_pattern):
url_params = {'limit': SearchAPI.SCAN_LIMIT, 'expand': 'true'}
first_search = self.get('mgmt-pop/apps', params=url_params)
data = first_search.json()
app_found = 0
app_scanned = 0

# CLI ouput header
cli.print('#app_id,type,name,host,cname,cert_id,status,reachable')
stats = self.process_page(data, search_pattern)
app_scanned += stats[0]
app_found += stats[1]

if data.get("meta"):

app_count = data.get("meta").get("total_count")
# Header
cli.print('#app_id,type,name,host,cname,cert_id,status,reachable')
page_offset = data.get("meta").get("offset")
page_limit = data.get("meta").get("limit")
page_total = ceil(app_count / page_limit)

logging.debug("app_count: {}, scanned: {}, offset: {}, limit: {}, pages: {}".format(
app_count, app_scanned, page_offset, page_limit, page_total))

for page in range(1, page_total):
logging.debug("Loading application page {} of {}".format(page, page_total))
url_params['offset'] = page * page_limit
search = self.get('mgmt-pop/apps', params=url_params)
stats = self.process_page(search.json(), search_pattern)
app_scanned += stats[0]
app_found += stats[1]

# CLI ouput footer
if not config.batch:
if app_found != app_count:
cli.footer("Found %s app(s), total %s app(s)" % (app_found, app_count))
else:
cli.footer("%s app(s)" % app_count)

def process_page(self, data, search_pattern):
app_found = 0
app_scanned = 0

if data.get("meta"):
for a in data.get('objects', []):
app_scanned += 1
if not search_pattern or (
search_pattern and (
fnmatch.fnmatch(a.get('name') or "", "*%s*" % search_pattern) or
Expand All @@ -88,14 +128,8 @@ class SearchAPI(BaseAPI):
status=ApplicationAPI.Status(a.get('app_status')).name,
reach=('Y' if a.get('resource_status', {}).get('host_reachable') else 'F'))
)
# cli.print(json.dumps(a))
app_found += 1
# Footer
if not config.batch:
if app_found != app_count:
cli.footer("Found %s app(s), total %s app(s)" % (app_found, app_count))
else:
cli.footer("%s app(s)" % app_count)
return app_scanned, app_found


class ReportingAPI(BaseAPI):
Expand Down
2 changes: 1 addition & 1 deletion cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"commands": [
{
"name": "eaa",
"version": "0.4.6",
"version": "0.4.7",
"description": "Akamai CLI for Enterprise Application Access (EAA)"
}
]
Expand Down
2 changes: 1 addition & 1 deletion libeaa/application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Akamai Technologies, Inc. All Rights Reserved
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion libeaa/cert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Akamai Technologies, Inc. All Rights Reserved
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions libeaa/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Akamai Technologies, Inc. All Rights Reserved
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@
config = EdgeGridConfig({'verbose': False}, 'default')

#: cli-eaa version
__version__ = '0.4.6'
__version__ = '0.4.7'

#: HTTP Request Timeout in seconds
HTTP_REQ_TIMEOUT = 300
Expand Down Expand Up @@ -91,6 +91,7 @@ def exit_gracefully(signum, frame):
logging.info(f"Stop due to SIGTERM(15) or SIGINT(2) signal received: {signum} ")
cli.stop_event.set()


class EAALegacyAuth(requests.auth.AuthBase):
"""
EAA legacy API authentication for Requests
Expand Down
2 changes: 1 addition & 1 deletion libeaa/connector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Akamai Technologies, Inc. All Rights Reserved
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions libeaa/directory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Python modules
from enum import Enum
import logging
Expand Down
2 changes: 1 addition & 1 deletion libeaa/error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Akamai Technologies, Inc. All Rights Reserved
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion libeaa/eventlog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Akamai Technologies, Inc. All Rights Reserved
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions libeaa/idp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 Akamai Technologies, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# cli-eaa
from common import cli, BaseAPI
from application import ApplicationAPI
Expand Down

0 comments on commit 1cd5e02

Please sign in to comment.