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

Server-Side Occurrence Names #160

Merged
merged 8 commits into from Jun 28, 2018

Conversation

daniel-sanche
Copy link
Contributor

Addressing the following issue: #157

Now, the server will automatically assign an name to new occurrences, and reject any that try to set an explicit one

I made use of a UUID library to generate the names, so they will look something like "projects/best-vuln-scanner/occurrences/fadad2f2-6899-446d-9428-8876c75c7962"

@daniel-sanche daniel-sanche requested a review from vtsao June 14, 2018 00:44
@daniel-sanche daniel-sanche force-pushed the server_side_occurrence branch 2 times, most recently from 0f86732 to ebc4f4e Compare June 14, 2018 00:55
@daniel-sanche
Copy link
Contributor Author

It looks like some tests are failing because it assumes it can set and retrieve specific occurrence names, so I'll have to fix the tests.

Also, right now I'm rejecting any occurrences that specify a name, so the user can get some feedback. This also breaks some tests. Let me know if you'd prefer it if the server just changed the name silently

@mikecico
Copy link

It might be useful to have the name have some user-friendly part, e.g., the project name as a prefix, and/or allow some customizable prefix or suffix.

@vtsao
Copy link
Contributor

vtsao commented Jun 15, 2018

@dansanche server should silently ignore any output only fields users set:
https://cloud.google.com/apis/design/design_patterns#output_fields

@mikecico that's an interesting proposal - can you outline your use case for this?

Copy link
Contributor

@vtsao vtsao 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 quick fix Dan!

log.Printf("Invalid occurrence name: %v", o.Name)
return nil, status.Error(codes.InvalidArgument, "Invalid occurrence name")
}

if o.NoteName == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This check might not be necessary, the parse note below should error on empty note name.

return nil, status.Error(codes.InvalidArgument, "Invalid note name")
}
if _, err = g.S.GetProject(pID); err != nil {
log.Printf("Unable to get project %v, err: %v", pID, err)
return nil, status.Error(codes.NotFound, fmt.Sprintf("Project %v not found", pID))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a status.Errorf you can use instead.

Also, for Go style, errors should start with lowercase, you don't have to update all of these, just this one.

}
}
if o.Name != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't validate output only fields as per:
https://cloud.google.com/apis/design/design_patterns#output_fields

log.Printf("Invalid Argument. Name field is read-only")
return nil, status.Error(codes.InvalidArgument, "Name field is read-only")
}
// assign a random name
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this comment, the code should make this obvious.

randID, err := uuid.NewRandom()
if err != nil {
log.Printf("Error Assiging Occurrence Name: %v", err)
return nil, status.Error(codes.Internal, "Internal Error: Could not generate Occurrence Name")
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably don't need to say "Internal Error" since the status code is already internal.

@daniel-sanche daniel-sanche force-pushed the server_side_occurrence branch 17 times, most recently from 57764be to 00aef77 Compare June 16, 2018 04:58
@daniel-sanche daniel-sanche force-pushed the server_side_occurrence branch 4 times, most recently from ed82c21 to f7c259c Compare June 16, 2018 05:16
@daniel-sanche
Copy link
Contributor Author

@vtsao I've addressed your comments, and the tests are now passing

@mikecico
Copy link

@vtsao we have a use case where we might be storing occurrences from multiple scanners within the same project (the other option of course is to have separate projects for each one, but we're trying to consolidate scanning steps within a pipeline job/step). Since prior to this the naming field was set by the client, we were thinking of creating a shallow hierarchy through naming conventions, which would also make the occurrences more readable, and allow us to be able to categorize occurrences within the project that we can create searches on, etc.

I think perhaps allowing clients influence on the naming field might not be necessary, and its probably better to leave it under the control of Grafeas if it is intended to be a generated ID. But perhaps if there were something akin to an optional "display-name" field, or something under client control, that might be useful. Unless there's something we can already leverage for this purpose?

@raj-inamdar
Copy link

To second @mikecico 's comment above, it will be useful to be able to add labels/tags to occurrences so they can be filtered/queried effectively.

@R2wenD2
Copy link
Contributor

R2wenD2 commented Jun 18, 2018

@mikecico and @raj-inamdar If you're storing occurrences from two scanners, the correct thing to do here would be to use separate not projects for each scanner, and then you could differentiate the occurrences by note name. Is there a reason that wouldn't work?

@raj-inamdar
Copy link

raj-inamdar commented Jun 18, 2018

@R2wenD2 In general, we expect to create separate notes projects for each scanner and use the note-name in the occurrences to differentiate, just as you suggest.

However, we think that there may be situations where multiple scanners may have some overlap and may identify the same underlying condition. Instead of duplicating notes in respective projects for such scanners, we may want to create a "shared" notes project. In that case, the note-name in occurrences may not be sufficient to differentiate across different scanners.

Besides, we think that a user-customizable labels/tags field may be useful in general to add flexibility for filtering, querying, etc.

@vtsao
Copy link
Contributor

vtsao commented Jun 19, 2018

@mikecico @raj-inamdar thanks for the use case description. Can either of you open an issue so we can track/discuss it there? Thanks.

}
}
randID, err := uuid.NewRandom()
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do this in a follow-up PR, but we should move the UUID generation to the storage layer, since it's a storage concept. Depending on the DB being used, some people may choose to let the DB create this ID for instance.

@raj-inamdar
Copy link

@vtsao Entered #163 to track our request. Thanks.

@sandeeps2
Copy link

I have a comment, hope it is not too late. In general it might be useful to have a human readable name. We can keep the original name field which is provided by the user in the CreateOccurrenceRequest and introduce a new ID field which is generated by the Server and returned to user after a successful create. It will keep the API same but existing queries will break, we can address it with a new method to ListOccurrencesByName.

@vtsao
Copy link
Contributor

vtsao commented Jun 20, 2018

@raj-inamdar thanks. @sandeeps2 can you add your comment on #163.

@sandeeps2
Copy link

@vtsao While a general purpose labeling facility will be useful, it is good to have Name as a first class field which can be indexed and easily searched for an Occurrence. My comment was more for the in-flight change for this Issue to retain the Name field of the Occurrence as a user-supplied value and define a new field for the generated ID. I will add my related thoughts on #163 as well.
Thanks.

@vtsao
Copy link
Contributor

vtsao commented Jun 28, 2018

Is this ready to be merged now Dan?

@daniel-sanche
Copy link
Contributor Author

Yes, I believe it should be. It looks like I don't have merge permissions for the repository

@vtsao vtsao merged commit 4931586 into grafeas:master Jun 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants