Skip to content

Commit

Permalink
fix: Ensure at least one permission when calling with on secure resou…
Browse files Browse the repository at this point in the history
…rces. (#6)
  • Loading branch information
tjholm authored Nov 14, 2023
1 parent 437f9ec commit 7facbe4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
6 changes: 4 additions & 2 deletions lib/src/main/kotlin/io/nitric/resources/BucketResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ class BucketResource internal constructor(name: String): SecureResource<BucketPe
}
}

fun with(vararg permissions: BucketPermission): Bucket {
this.registerPolicy(permissions.asList())
fun with(permission: BucketPermission, vararg permissions: BucketPermission): Bucket {
val allPerms = listOf(permission) + permissions.asList()

this.registerPolicy(allPerms)
return Storage.bucket(this.name)
}

Expand Down
6 changes: 4 additions & 2 deletions lib/src/main/kotlin/io/nitric/resources/CollectionResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ class CollectionResource<T> constructor(name: String, private val collectionType
)
}

fun with(vararg permissions: CollectionPermission): io.nitric.api.documents.v0.Collection<T> {
this.registerPolicy(permissions.asList())
fun with(permission: CollectionPermission, vararg permissions: CollectionPermission): io.nitric.api.documents.v0.Collection<T> {
val allPerms = listOf(permission) + permissions.asList()

this.registerPolicy(allPerms)
return Documents.collection(this.name, this.collectionType)
}
}
6 changes: 4 additions & 2 deletions lib/src/main/kotlin/io/nitric/resources/QueueResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class QueueResource internal constructor(name: String): SecureResource<QueuePerm
}
}

fun with(vararg permissions: QueuePermission): Queue {
this.registerPolicy(permissions.asList())
fun with(permission: QueuePermission, vararg permissions: QueuePermission): Queue {
val allPerms = listOf(permission) + permissions.asList()

this.registerPolicy(allPerms)
return Queueing.queue(this.name)
}
}
8 changes: 4 additions & 4 deletions lib/src/main/kotlin/io/nitric/resources/SecretResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import io.nitric.proto.resource.v1.Action
import io.nitric.proto.resource.v1.ResourceDeclareRequest
import io.nitric.proto.resource.v1.ResourceType
import io.nitric.util.fluently
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking

enum class SecretPermission {
Put,
Expand Down Expand Up @@ -38,8 +36,10 @@ class SecretResource internal constructor(name: String): SecureResource<SecretPe
)
}

fun with(vararg permissions: SecretPermission): io.nitric.api.secrets.v0.Secret {
this.registerPolicy(permissions.asList())
fun with(permission: SecretPermission, vararg permissions: SecretPermission): io.nitric.api.secrets.v0.Secret {
val allPerms = listOf(permission) + permissions.asList()

this.registerPolicy(allPerms)
return Secrets.secret(this.name)
}
}
6 changes: 4 additions & 2 deletions lib/src/main/kotlin/io/nitric/resources/TopicResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ class TopicResource internal constructor(name: String) : SecureResource<TopicPer
Nitric.registerWorker(faas)
}

fun with(vararg permissions: TopicPermission): Topic {
this.registerPolicy(permissions.asList())
fun with(permission: TopicPermission, vararg permissions: TopicPermission): Topic {
val allPerms = listOf(permission) + permissions.asList()

this.registerPolicy(allPerms)
return Eventing.topic(this.name)
}
}
Expand Down

0 comments on commit 7facbe4

Please sign in to comment.