-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
New API: list vulnerabilities by namespace #82
Changes from all commits
a541e96
48ffb26
27e5e42
1a863a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,7 +215,8 @@ func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotifica | |
|
||
var nextPageStr string | ||
if nextPage != database.NoVulnerabilityNotificationPage { | ||
nextPageStr = pageNumberToToken(nextPage, key) | ||
nextPageBytes, _ := tokenMarshal(nextPage, key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't get it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but nothing changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! I'm sorry for the confusion. Usually |
||
nextPageStr = string(nextPageBytes) | ||
} | ||
|
||
var created, notified, deleted string | ||
|
@@ -274,8 +275,10 @@ type NamespaceEnvelope struct { | |
} | ||
|
||
type VulnerabilityEnvelope struct { | ||
Vulnerability *Vulnerability `json:"Vulnerability,omitempty"` | ||
Error *Error `json:"Error,omitempty"` | ||
Vulnerability *Vulnerability `json:"Vulnerability,omitempty"` | ||
Vulnerabilities *[]Vulnerability `json:"Vulnerabilities,omitempty"` | ||
NextPage string `json:"NextPage,omitempty"` | ||
Error *Error `json:"Error,omitempty"` | ||
} | ||
|
||
type NotificationEnvelope struct { | ||
|
@@ -289,30 +292,23 @@ type FeatureEnvelope struct { | |
Error *Error `json:"Error,omitempty"` | ||
} | ||
|
||
func tokenToPageNumber(token, key string) (database.VulnerabilityNotificationPageNumber, error) { | ||
func tokenUnmarshal(token string, key string, v interface{}) error { | ||
k, _ := fernet.DecodeKey(key) | ||
msg := fernet.VerifyAndDecrypt([]byte(token), time.Hour, []*fernet.Key{k}) | ||
if msg == nil { | ||
return database.VulnerabilityNotificationPageNumber{}, errors.New("invalid or expired pagination token") | ||
return errors.New("invalid or expired pagination token") | ||
} | ||
|
||
page := database.VulnerabilityNotificationPageNumber{} | ||
err := json.NewDecoder(bytes.NewBuffer(msg)).Decode(&page) | ||
return page, err | ||
return json.NewDecoder(bytes.NewBuffer(msg)).Decode(&v) | ||
} | ||
|
||
func pageNumberToToken(page database.VulnerabilityNotificationPageNumber, key string) string { | ||
func tokenMarshal(v interface{}, key string) ([]byte, error) { | ||
var buf bytes.Buffer | ||
err := json.NewEncoder(&buf).Encode(page) | ||
err := json.NewEncoder(&buf).Encode(v) | ||
if err != nil { | ||
log.Fatal("failed to encode VulnerabilityNotificationPageNumber") | ||
return nil, err | ||
} | ||
|
||
k, _ := fernet.DecodeKey(key) | ||
tokenBytes, err := fernet.EncryptAndSign(buf.Bytes(), k) | ||
if err != nil { | ||
log.Fatal("failed to encrypt VulnerabilityNotificationpageNumber") | ||
} | ||
|
||
return string(tokenBytes) | ||
return fernet.EncryptAndSign(buf.Bytes(), k) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish there was a better way to put this, because I was using HTTP verbs for all of these and technically this is a
GET
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but how though?