Skip to content

Commit

Permalink
old card change logic added
Browse files Browse the repository at this point in the history
  • Loading branch information
gary1998 committed Feb 27, 2020
1 parent 4a00d04 commit e28c31e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apt-get update && \
RUN apt-get install curl -y
RUN apt-get update
RUN apt-get install python3-pip -y
RUN pip3 install requests ibm_cloud_sdk_core==1.6.2 ibm-cloud-security-advisor-findingsapi-sdk==2.0.0
RUN pip3 install requests ibm-cloud-security-advisor-findingsapi-sdk==2.0.5

RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
Expand Down
22 changes: 22 additions & 0 deletions src/ibmcloud/kubeHunterL1Adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,34 @@ def create_note(account_id, token, endpoint):
)
if response.get_status_code() == 200:
logger.info("created note: %s" % note['id'])
elif response.get_status_code() == 409 and note['kind'] == "CARD":
logger.info("card already present... attempting to update")
change_card(account_id, token, endpoint, note)
else:
logger.error("unable to create note: %s" % note['id'])
except:
logger.exception("an unexpected error was encountered while creating note")


def change_card(account_id, token, endpoint, note):
try:
findingsAPI = FindingsApiV1(
authenticator=BearerTokenAuthenticator(token)
)
findingsAPI.set_service_url(endpoint)
response = findingsAPI.update_note(
account_id=account_id,
note_id=note['id']
**note
)
if response.get_status_code() == 200:
logger.info("card updated: %s" % note['id'])
else:
logger.error("card not updated: %s" % note['id'])
except:
logger.exception("an unexpected error was encountered while updating note")


def get_all_kubehunternotes(account_id, token, endpoint):
providers = [
"kubeHunterIBMCloud",
Expand Down
22 changes: 22 additions & 0 deletions src/redhat-openshift/kubeHunterL1Adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,34 @@ def create_note(account_id, token, endpoint):
)
if response.get_status_code() == 200:
logger.info("created note: %s" % note['id'])
elif response.get_status_code() == 409 and note['kind'] == "CARD":
logger.info("card already present... attempting to update")
change_card(account_id, token, endpoint, note)
else:
logger.error("unable to create note: %s" % note['id'])
except:
logger.exception("an unexpected error was encountered while creating note")


def change_card(account_id, token, endpoint, note):
try:
findingsAPI = FindingsApiV1(
authenticator=BearerTokenAuthenticator(token)
)
findingsAPI.set_service_url(endpoint)
response = findingsAPI.update_note(
account_id=account_id,
note_id=note['id']
**note
)
if response.get_status_code() == 200:
logger.info("card updated: %s" % note['id'])
else:
logger.error("card not updated: %s" % note['id'])
except:
logger.exception("an unexpected error was encountered while updating note")


def get_all_kubehunternotes(account_id, token, endpoint):
providers = [
"kubeHunterRedhatOpenshift",
Expand Down

0 comments on commit e28c31e

Please sign in to comment.