logical/aws: policy doesn't need to be base64

This commit is contained in:
Mitchell Hashimoto
2015-03-31 17:26:41 -07:00
parent a74d398eb9
commit 630da54522
2 changed files with 6 additions and 15 deletions

View File

@@ -1,7 +1,6 @@
package aws
import (
"encoding/base64"
"log"
"os"
"testing"
@@ -91,7 +90,7 @@ func testAccStepWritePolicy(t *testing.T, name string, policy string) logicaltes
Operation: logical.WriteOperation,
Path: "policy/" + name,
Data: map[string]interface{}{
"policy": base64.StdEncoding.EncodeToString([]byte(policy)),
"policy": testPolicy,
},
}
}

View File

@@ -2,7 +2,6 @@ package aws
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
@@ -21,7 +20,7 @@ func pathPolicy() *framework.Path {
"policy": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Policy document, base64 encoded.",
Description: "Policy document",
},
},
@@ -33,23 +32,16 @@ func pathPolicy() *framework.Path {
func pathPolicyWrite(
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
// Decode and compact the policy. AWS requires a JSON-compacted policy
// because it mustn't contain newlines.
var policyBuf bytes.Buffer
policyRaw, err := base64.StdEncoding.DecodeString(d.Get("policy").(string))
if err != nil {
return logical.ErrorResponse(fmt.Sprintf(
"Error decoding policy base64: %s", err)), nil
}
if err := json.Compact(&policyBuf, []byte(policyRaw)); err != nil {
var buf bytes.Buffer
if err := json.Compact(&buf, []byte(d.Get("policy").(string))); err != nil {
return logical.ErrorResponse(fmt.Sprintf(
"Error compacting policy: %s", err)), nil
}
// Write the policy into storage
err = req.Storage.Put(&logical.StorageEntry{
err := req.Storage.Put(&logical.StorageEntry{
Key: "policy/" + d.Get("name").(string),
Value: policyBuf.Bytes(),
Value: buf.Bytes(),
})
if err != nil {
return nil, err