Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Make Condition a Case Class for consistency #83

Closed
EdgeCaseBerg opened this issue Jun 15, 2015 · 2 comments
Closed

Make Condition a Case Class for consistency #83

EdgeCaseBerg opened this issue Jun 15, 2015 · 2 comments

Comments

@EdgeCaseBerg
Copy link

Hello! Your library is really useful and saving me a lot of time, but something tripped me up today.
I was defining a Policy that had conditions, Something like this:

val policy = Policy(
        Seq(
            Statement(Effect.Allow, 
                Seq(
                    Action("s3:ListAllMyBuckets"), 
                    Action("s3:GetBucketLocation")
                ),
                Seq(
                    Resource("arn:aws:s3:::*"),
                    Resource(s"arn:aws:s3:::${bucketName}")
                )
            ),
            Statement(Effect.Allow,
                Seq(
                    Action("s3:ListBucket")
                ),
                Seq(
                    Resource(s"arn:aws:s3:::${bucketName}")
                ),
                conditions = Seq(
                    new awscala.Condition(
                        "StringLike",
                        "s3:prefix",
                        Seq("", s"${keyToAllow}")
                    )
                )
            )
        )
    )

Something that really threw me off was that Resource, Statement and Action are all case classes, so they have the companion object's apply method to Simply state Action(...) instead of new Action(...). While it's not a huge deal, you'll notice that Condition is not a case class and therefore needs to be instantiated with new.

This puzzled me for a while because I was doing the import awscala.Condition fine, but was getting the error not found: value Condition when trying to make my policy. I figure'd it out as you can tell from the above. But is there a reason why Condition is not a case class?

@seratch
Copy link
Owner

seratch commented Jun 15, 2015

Thanks. I just changed Condition class to a case class.

@EdgeCaseBerg
Copy link
Author

awesome! thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants