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

Update IAM Policy Statements to support multiple resources #143

Merged
merged 1 commit into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ object Token extends DefaultJsonProtocol {

override def read(json: JsValue): TokenSeq[R] = ???
})

implicit def tokenStringToTokenSeqString(ts: Token[String]): TokenSeq[String] = Seq(ts)
implicit def tokenizableToTokenSeqString[T](ts: T)(implicit ev1: T ⇒ Token[String]): TokenSeq[String] = tokenStringToTokenSeqString(ts)
}
case class AnyToken[R : JsonFormat](value: R) extends Token[R]
case class StringToken(value: String) extends Token[String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,11 @@ object PolicyConditionValue extends DefaultJsonProtocol {
implicit def tokenList2Value(s : Seq[Token[String]]): PolicyConditionValue = TokenListPolicyConditionValue(s)
}


case class PolicyStatement(
Effect: String,
Principal: Option[PolicyPrincipal] = None,
Action: Seq[String],
Resource: Option[Token[String]] = None,
Resource: Option[TokenSeq[String]] = None,
Condition: Option[Map[String, Map[String, PolicyConditionValue]]] = None,
Sid: Option[String] = None
)
Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/cloudformation-template-vpc-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
"ec2:StartInstances",
"ec2:StopInstances"
],
"Resource":"*"
"Resource":["*"]
}
]
}
Expand All @@ -297,7 +297,7 @@
"Action":[
"s3:GetObject"
],
"Resource":{
"Resource":[{
"Fn::Join":[
"",
[
Expand All @@ -306,7 +306,7 @@
"/*"
]
]
}
}]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.monsanto.arch.cloudformation.model

import com.monsanto.arch.cloudformation.model.resource.ValidPolicyCombo._
import com.monsanto.arch.cloudformation.model.resource._
import ValidPolicyCombo._
import org.scalatest.{Matchers, FunSpec}
import org.scalatest.{FunSpec, Matchers}


/**
* Created by djdool on 7/9/15.
*/
class IAMPolicy_UT extends FunSpec with Matchers with JsonWritingMatcher {

describe("AWS::IAM::Policy") {
Expand Down Expand Up @@ -115,5 +111,20 @@ class IAMPolicy_UT extends FunSpec with Matchers with JsonWritingMatcher {
|}
""".stripMargin
}

it("should generate policy statement with resources") {
PolicyDocument(
Statement = Seq(PolicyStatement(Effect = "Allow",Action = Seq("*"), Resource = Some(Seq("arn:1", "arn:2"))))
) shouldMatch
"""
|{
| "Statement": [{
| "Effect": "Allow",
| "Action": ["*"],
| "Resource": ["arn:1", "arn:2"]
| }]
|}
""".stripMargin
}
}
}