mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-01-03 11:45:41 +00:00
Merge pull request #83 from cloudflare/zi/fix-response-parsing
Zi/fix response parsing
This commit is contained in:
@@ -70,6 +70,11 @@ func (c *RemoteServer) doAction(action string, req []byte) ([]byte, error) {
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
// Return response body as error if status code != 200
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, errors.New(string(body))
|
||||
}
|
||||
|
||||
return body, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -108,6 +108,7 @@ func runDelegate() {
|
||||
fmt.Println(resp.Status)
|
||||
}
|
||||
|
||||
// TODO: summary response needs better formatting
|
||||
func runSummary() {
|
||||
req := core.SummaryRequest{
|
||||
Name: user,
|
||||
@@ -133,6 +134,10 @@ func runEncrypt() {
|
||||
|
||||
resp, err := roServer.Encrypt(req)
|
||||
processError(err)
|
||||
if resp.Status != "ok" {
|
||||
log.Fatal("response status error:", resp.Status)
|
||||
return
|
||||
}
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
outBytes := []byte(base64.StdEncoding.EncodeToString(resp.Response))
|
||||
ioutil.WriteFile(outPath, outBytes, 0644)
|
||||
@@ -161,6 +166,10 @@ func runReEncrypt() {
|
||||
|
||||
resp, err := roServer.ReEncrypt(req)
|
||||
processError(err)
|
||||
if resp.Status != "ok" {
|
||||
log.Fatal("response status error:", resp.Status)
|
||||
return
|
||||
}
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
outBytes := []byte(base64.StdEncoding.EncodeToString(resp.Response))
|
||||
ioutil.WriteFile(outPath, outBytes, 0644)
|
||||
@@ -185,10 +194,14 @@ func runDecrypt() {
|
||||
|
||||
resp, err := roServer.Decrypt(req)
|
||||
processError(err)
|
||||
if resp.Status != "ok" {
|
||||
log.Fatal("response status error:", resp.Status)
|
||||
return
|
||||
}
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
var msg core.DecryptWithDelegates
|
||||
err = json.Unmarshal(resp.Response, &msg)
|
||||
processError(err)
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
fmt.Println("Secure:", msg.Secure)
|
||||
fmt.Println("Delegates:", msg.Delegates)
|
||||
ioutil.WriteFile(outPath, msg.Data, 0644)
|
||||
|
||||
Reference in New Issue
Block a user