Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "short" report generation option #135

Open
mshudrak opened this issue Apr 7, 2023 · 17 comments
Open

Implement "short" report generation option #135

mshudrak opened this issue Apr 7, 2023 · 17 comments
Labels
enhancement New feature or request

Comments

@mshudrak
Copy link
Collaborator

mshudrak commented Apr 7, 2023

Is your feature request related to a problem? Please describe.
Right now, our scan result contains mostly all the data returned by GCP. It is hard to navigate and requires greping data.

Describe the solution you'd like
We can implement a flag that would tell the scanner to return only the most important data from GCP.

We need to define what would be the most important fields to return. We also need to think about a flexible approach on defining what to omit/return from the report.

@mshudrak mshudrak added the enhancement New feature or request label Apr 7, 2023
mshudrak added a commit that referenced this issue Apr 7, 2023
We use a predefined schema to select the most interesting fields
for printing. User can enable it with -ls flag.

Additionally
* Requests are now timed out by 120 seconds
* Impersonation is now disabled by default
* Unwrapped several unnecessary lists in responses
* Fixes extra null output in GCS scanning results

Related to #135
mshudrak added a commit that referenced this issue Apr 7, 2023
* feat: Enable lightweight scanning option

We use a predefined schema to select the most interesting fields
for printing. User can enable it with -ls flag.

Additionally
* Requests are now timed out by 120 seconds
* Impersonation is now disabled by default
* Unwrapped several unnecessary lists in responses
* Fixes extra null output in GCS scanning results
* [tests] Relaxing and updating unit tests
* [tests] Printing error file on failure (

Related to #135
@mshudrak
Copy link
Collaborator Author

mshudrak commented Apr 7, 2023

Implemented. We need to add tests for this feature and think about how to filter with our schema non-standard outputs.

@SaxenaAnushka102
Copy link

Hi @mshudrak! Could you please mention some more details about what type of tests we need here?

@mshudrak
Copy link
Collaborator Author

Hi @SaxenaAnushka102, basically I implemented a new option for GCP Scanner to produce short version of the scanner report. We need to implement acceptance test similar to what we have for the whole scanner here: https://github.com/google/gcp_scanner/blob/main/src/gcp_scanner/test_acceptance.py

@Bhardwaj-Himanshu
Copy link
Contributor

Bhardwaj-Himanshu commented Apr 18, 2023

Hi @mshudrak , could you also mention the file we need to make these changes into?-->I know these sound naive but these do come from my lack of experience, my nearest clue is to implement these changes in scanner.py

Also, @SaxenaAnushka102 , do let me know if you are working on something and if I could be of any help.
Thanks.

@mshudrak
Copy link
Collaborator Author

@Bhardwaj-Himanshu we need new test similar to what we have in test_acceptance.py. Likely new test file needed.

@Bhardwaj-Himanshu
Copy link
Contributor

Bhardwaj-Himanshu commented Apr 18, 2023

Like this

def test_acceptance():
os.mkdir("res")
testargs = ["__main__.py", "-m", "-p", "test-gcp-scanner", "-o", "res"]
with unittest.mock.patch("sys.argv", testargs):
assert scanner.main() == 0
assert len(os.listdir("res/")) == RESULTS_JSON_COUNT
validate_result()
? @mshudrak

a new file or a new addition to the same?
or a new file containing test like this-

def new_test_function():
  os.mkdir("res")
  testargs = ["some_more_repositories", "-o", "res"]
  with unittest.mock.patch("sys.argv", testargs):
    assert scanner.main() == 0
    assert len(os.listdir("res/")) == RESULTS_JSON_COUNT
    validate_result()

Do correct me and help on hints, if I am wrong anywhere, all feedbacks are welcomed.
Also, could you mention few resources I could check out online to create a test_function in a new file for the same, or what would the file contain?

@SaxenaAnushka102
Copy link

Thanks for the details @mshudrak! I'm reading docs related to tests & will update when I'll come up with a solution.

@SaxenaAnushka102
Copy link

@Bhardwaj-Himanshu That's a nice idea, let's work on it!

@Bhardwaj-Himanshu
Copy link
Contributor

Sure thing, @SaxenaAnushka102!
Could you share the link of docs to me aswell!
Thanks

@SaxenaAnushka102
Copy link

@Bhardwaj-Himanshu I'm referring to the GCP Scanner's Wiki page and this Python documentation

@mshudrak
Copy link
Collaborator Author

@Bhardwaj-Himanshu yes, that's the right approach. Whether you choose to expand test_acceptance or create an independent test is up to you. I'd probably just expand test_acceptance with another function.

@Bhardwaj-Himanshu
Copy link
Contributor

Thanks @SaxenaAnushka102 ;)

@Bhardwaj-Himanshu
Copy link
Contributor

Gotcha @mshudrak, now could help me defining what are the values which are required in the output and once which need to be omitted.

But before that , I need to look into what a normal out report looks like in gcp_scanner_test_acceptance.py!

@mshudrak
Copy link
Collaborator Author

You can take a look at Github Actions, there are full logs response there. As for actual output, one option is to prepare the test and print output. On the second iteration you can add that in the check file.

@Bhardwaj-Himanshu
Copy link
Contributor

Hi @mshudrak, first of all pardon me for a late response, got stuck under a very pleasant weather here(sarcasm, cause a storm came through chopping down all the electric lines for 5 days).

Anyways, coming to the code, as being unable to write the new_test.py files myself, if you could help me look at some resources/codebase internally from gcp_scanner or outside for a general overview of how to write the same and most probably going to attach the function inside the test_acceptance.py, rather than creating a new file and breaking the whole code base!

Thanks

@mshudrak
Copy link
Collaborator Author

You can use test_acceptance.py as an example and Github Actions to see produced logs. There is function that does it. You just need to provide extra argument and implemented expected output. Just take a look at code.

@Bhardwaj-Himanshu
Copy link
Contributor

Bhardwaj-Himanshu commented Apr 28, 2023

The function in the test_acceptance.py is most probably-

def test_acceptance():
os.mkdir("res")
testargs = ["__main__.py", "-l", "INFO",
"-m", "-p", "test-gcp-scanner-2", "-o", "res"]
with unittest.mock.patch("sys.argv", testargs):
assert scanner.main() == 0
assert len(os.listdir("res/")) == RESULTS_JSON_COUNT
validate_result()

Which I am thinking to add another function as

def new_test_function():
  os.mkdir("res")
  testargs = ["some_more_repositories", "-o", "res"] #but which repositories to target?
  with unittest.mock.patch("sys.argv", testargs): #and what arguments to run?
    assert scanner.main() == 0
    assert len(os.listdir("res/")) == RESULTS_JSON_COUNT
    validate_result()

Also, if you could tell me a way to contact you other than github, weather email or any social media handle. I had a few things/ideas to discuss, not regarding this pull request, but in regards to documentation and forming a community for the repository!!--> I am totally fine with discussing here too, let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants