Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Add Support for CSCC Beta API #2130

Merged
merged 10 commits into from
Nov 14, 2018
Merged

Add Support for CSCC Beta API #2130

merged 10 commits into from
Nov 14, 2018

Conversation

blueandgold
Copy link
Contributor

@blueandgold blueandgold commented Oct 23, 2018

  • Also maintains backward compatibility with the alpha API. If you can see a better way to do this, please let me know.
  • Will update tests after review.


client = securitycenter.SecurityCenterClient(version='v1beta1')

for i in findings:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finding/finding_tuple would be easier to understand than i here e.g.
for finding in findings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, done.

client = securitycenter.SecurityCenterClient(version='v1beta1')

for i in findings:
finding_id = i[0][0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be i[0] instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this was sliced incorrectly, and is now fixed.

configs/server/forseti_conf_server.yaml.in Show resolved Hide resolved
Copy link
Contributor Author

@blueandgold blueandgold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. Please take another look.

configs/server/forseti_conf_server.yaml.in Show resolved Hide resolved

client = securitycenter.SecurityCenterClient(version='v1beta1')

for i in findings:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, done.

client = securitycenter.SecurityCenterClient(version='v1beta1')

for i in findings:
finding_id = i[0][0]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this was sliced incorrectly, and is now fixed.

google/cloud/forseti/notifier/notifier.py Show resolved Hide resolved
@@ -77,8 +87,17 @@ def __init__(self, **kwargs):

LOGGER.debug(
'Creating _SecurityCenterOrganizationsFindingsRepositoryClient')

# pylint: disable=protected-access
if kwargs.get('gcp_service')._resourceDesc.get('version') == 'v1beta1':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for 'gcp_service' to be not found? If so accessing _resourceDesc will throw errors (Can't seem to find any information related to _resourceDesc, too).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcp_sevice is always built by the create_service_api() in _base_repository().

# CSCC can't accept the full hash, so this must be shortened.
finding_id = violation.get('violation_hash')[:32]
finding = {
'name': '{0}/findings/{1}'.format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any character limits on any of these fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the character limits are actually bigger than on alpha api. Let me follow-up with the CSCC team to be sure.

Copy link
Contributor Author

@blueandgold blueandgold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. All comments addressed.

google/cloud/forseti/notifier/notifier.py Show resolved Hide resolved
# CSCC can't accept the full hash, so this must be shortened.
finding_id = violation.get('violation_hash')[:32]
finding = {
'name': '{0}/findings/{1}'.format(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the character limits are actually bigger than on alpha api. Let me follow-up with the CSCC team to be sure.

@@ -77,8 +87,17 @@ def __init__(self, **kwargs):

LOGGER.debug(
'Creating _SecurityCenterOrganizationsFindingsRepositoryClient')

# pylint: disable=protected-access
if kwargs.get('gcp_service')._resourceDesc.get('version') == 'v1beta1':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcp_sevice is always built by the create_service_api() in _base_repository().

@codecov
Copy link

codecov bot commented Nov 14, 2018

Codecov Report

Merging #2130 into dev will decrease coverage by 0.1%.
The diff coverage is 62.31%.

@@            Coverage Diff             @@
##              dev    #2130      +/-   ##
==========================================
- Coverage   88.88%   88.78%   -0.11%     
==========================================
  Files         175      175              
  Lines       13462    13515      +53     
==========================================
+ Hits        11966    11999      +33     
- Misses       1496     1516      +20
Impacted Files Coverage Δ
google/cloud/forseti/notifier/notifier.py 72.83% <0%> (-4.8%) ⬇️
...e/cloud/forseti/common/gcp_api/_base_repository.py 99.4% <100%> (ø) ⬆️
...gle/cloud/forseti/common/gcp_api/securitycenter.py 100% <100%> (ø) ⬆️
.../cloud/forseti/notifier/notifiers/cscc_notifier.py 55.68% <50%> (-3.65%) ⬇️

@blueandgold blueandgold merged commit eb538a6 into dev Nov 14, 2018
joecheuk pushed a commit that referenced this pull request Dec 5, 2018
* Add support for CSCC Beta API

* tweak

* tweak

* address comments and fix tests

* update test for beta api

* add more tests for beta api

* fix tests

* fix lint
@blueandgold blueandgold deleted the csccbeta_final branch December 21, 2018 00:19
@blueandgold blueandgold mentioned this pull request Jan 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants