-
Notifications
You must be signed in to change notification settings - Fork 75
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
[cms] Add passthroughs for proposals requests #1171
Conversation
} | ||
|
||
data, _ := ioutil.ReadAll(resp.Body) | ||
util.RespondRaw(w, http.StatusOK, data) |
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.
util.RespondRaw(w, http.StatusOK, data) | |
resp.Body.Close() | |
util.RespondRaw(w, http.StatusOK, data) |
politeiawww/cmswww.go
Outdated
resp, err := http.Get(route) | ||
if err != nil { | ||
RespondWithError(w, r, 0, | ||
"SOME ERROR", err) |
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.
we would want to handle this properly
politeiawww/cmswww.go
Outdated
@@ -865,6 +887,9 @@ func (p *politeiawww) setCMSWWWRoutes() { | |||
p.addRoute(http.MethodGet, cms.APIRoute, | |||
cms.RouteProposalOwner, p.handleProposalOwner, | |||
permissionLogin) | |||
p.addRoute(http.MethodGet, cms.APIRoute, | |||
www.RouteTokenInventory, p.handlePassThroughTokenInventory, | |||
permissionPublic) |
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.
Maybe set this to permissionLogin . This would avoid the public hitting this heavy end point by mistake.
permissionPublic) | |
permissionLogin) |
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.
ACK
@marcopeereboom will want to look at this.
politeiawww/cmswww.go
Outdated
return | ||
} | ||
defer func() { | ||
resp.Body.Close() |
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.
Closing here.
politeiawww/cmswww.go
Outdated
}() | ||
|
||
data, _ := ioutil.ReadAll(resp.Body) | ||
resp.Body.Close() |
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.
And here.
|
||
// VerifyProposal verifies a proposal's merkle root, author signature, and | ||
// censorship record. | ||
func VerifyProposal(p v1.ProposalRecord, serverPubKey string) error { |
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.
We are going to need unit tests for this function where we test all failure modes.
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.
This was an existing unexported func in piwww. Where do you want these tests? I'm not seeing any in piwww.
politeiawww/cmswww.go
Outdated
} | ||
|
||
data, _ := ioutil.ReadAll(resp.Body) | ||
resp.Body.Close() |
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'd make this a defer right after the GET
.
@@ -30,6 +31,19 @@ func RespondWithJSON(w http.ResponseWriter, code int, payload interface{}) { | |||
w.Write(response) | |||
} | |||
|
|||
func RespondRaw(w http.ResponseWriter, code int, payload []byte) { |
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.
This should be shared with the various CLI tools. So that we only have to change it once and not multiple times.
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.
It's exported within the util package, so it should be able to be used anywhere that it's necessary. What other tools should use it?
This allows us to request
https://cms.decred.org/api/v1/proposals/tokeninventory
andhttps://cms.decred.org/api/v1/proposals/batch
to avoid a cross site request that causes security issues. This simple passes that request through via the API to the relevant proposals site (mainnet/testnet).