Skip to content

Commit

Permalink
Merge pull request #204 from marksull/release/20241021.0
Browse files Browse the repository at this point in the history
Release/20241021.0
  • Loading branch information
marksull authored Oct 21, 2024
2 parents 763eb9b + 24ee477 commit 200c60e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
26 changes: 16 additions & 10 deletions fmcapi/api_objects/apiclasstemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,15 @@ def valid_for_post(self):
:return: (boolean)
"""
logging.debug("In valid_for_post() for APIClassTemplate class.")
if "bulk_post_data" in self.__dict__:
if "bulk_post_data" in self.__dict__:
missing_required_item = False
# Check within each payload to ensure required for post is handled
for i in self.bulk_post_data:
for item in self.REQUIRED_FOR_POST:
if item not in i:
logging.error(f'BULK POST FAILED: Missing value "{item}" in {i}')
logging.error(
f'BULK POST FAILED: Missing value "{item}" in {i}'
)
missing_required_item = True
if missing_required_item:
return False
Expand Down Expand Up @@ -343,7 +345,9 @@ def post(self, **kwargs):
f'POST success. Object with name: "{self.name}" and id: "{self.id}" created in FMC.'
)
elif "bulk_post_data" in self.__dict__:
logging.info(f'BULK POST success. Items bulk posted: {len(response["items"])}')
logging.info(
f'BULK POST success. Items bulk posted: {len(response["items"])}'
)
logging.debug(f'BULK POST: {response["items"]}')
else:
logging.debug(
Expand Down Expand Up @@ -455,7 +459,7 @@ def delete(self, **kwargs):
url += f"?backupVersion={self.backupVersion}"
elif "bulk_delete_data" in self.__dict__:
# Convert bulk delete data to csv string to insert into url
self.bulk_delete_str = ','.join(map(str,self.bulk_delete_data))
self.bulk_delete_str = ",".join(map(str, self.bulk_delete_data))
url = f"{self.URL}?filter=ids:{self.bulk_delete_str}&bulk=true"
else:
url = f"{self.URL}/{self.id}"
Expand Down Expand Up @@ -487,8 +491,10 @@ def delete(self, **kwargs):
f'DELETE success. Object with targetId: "{self.targetId}" deleted from FMC.'
)
elif "bulk_delete_data" in self.__dict__:
logging.info(f'Bulk DELETE success. Objects deleted in FMC: {len(self.bulk_delete_data)}')
logging.debug(f'Bulk DELETE: {self.bulk_delete_data}')
logging.info(
f"Bulk DELETE success. Objects deleted in FMC: {len(self.bulk_delete_data)}"
)
logging.debug(f"Bulk DELETE: {self.bulk_delete_data}")
else:
logging.info(f'DELETE success. Object id: "{self.id}" deleted in FMC.')
return response
Expand Down Expand Up @@ -572,11 +578,11 @@ def bulk_post(self, **kwargs):
self.bulk_post_data = chunk
response = APIClassTemplate.post(self)
if response is not None:
for i in response['items']:
self.bulk_ids.append(i['id'])
for i in response["items"]:
self.bulk_ids.append(i["id"])
else:
self.bulk_post_data = self.bulk
response = APIClassTemplate.post(self)
if response is not None:
for i in response['items']:
self.bulk_ids.append(i['id'])
for i in response["items"]:
self.bulk_ids.append(i["id"])
4 changes: 2 additions & 2 deletions fmcapi/api_objects/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ def bulk_list_splitter(ids, chunk_size=49):
"""
chunks = []
for id in range(0, len(ids), chunk_size):
chunks.append(ids[id:id + chunk_size])
chunks.append(ids[id : id + chunk_size])
return chunks


def check_uuid(uuid_input):
try:
uuid.UUID(str(uuid_input))
return True
except ValueError:
return False

15 changes: 9 additions & 6 deletions fmcapi/fmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,17 @@ def __enter__(self):
logging.debug("cdFMC is True.")
# cdFMC doesn't use the normal user/pass auth that responds with the token and global uuid
# initial lookup of the global domain uuid done here using the JWT token from cdo api user
logging.debug(f'Fetching cdFMC global domain uuid.')
domain_info = self.send_to_api(method="get",url=f"https://{self.host}/api/fmc_platform/v1/info/domain")
logging.debug(f"Fetching cdFMC global domain uuid.")
domain_info = self.send_to_api(
method="get",
url=f"https://{self.host}/api/fmc_platform/v1/info/domain",
)
logging.debug(domain_info)
if domain_info is not None:
for i in domain_info['items']:
if i['name'] == 'Global':
self.uuid = i['uuid']
logging.debug(f'cdFMC global uuid found! {self.uuid}')
for i in domain_info["items"]:
if i["name"] == "Global":
self.uuid = i["uuid"]
logging.debug(f"cdFMC global uuid found! {self.uuid}")
else:
logging.error(f"Unable to retrieve global domain UUID from cdFMC")
logging.error(domain_info)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="fmcapi",
version="20240503.0",
version="20241021.0",
description="Easier interface to Cisco's FMC API than writing your own way.",
long_description="""With the removal to configure a Cisco NGFW via the command line your only option is to
do so via a manager. Some things are better when automated so using the manager's API gives us that power.
Expand Down

0 comments on commit 200c60e

Please sign in to comment.