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

Added role assignments endpoint #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -1,7 +1,7 @@
package pt.tecnico.dsi.openstack.keystone.models

import io.circe.derivation.{deriveDecoder, deriveEncoder, renaming}
import io.circe.{Decoder, Encoder}
import io.circe.{Decoder, Encoder, HCursor}
import pt.tecnico.dsi.openstack.common.models.{Identifiable, Link}

object Role {
Expand Down Expand Up @@ -36,7 +36,19 @@ object Role {
name: Option[String] = None,
description: Option[String] = None,
)

object Assignment {
implicit val decoder: Decoder[Assignment] = { cursor: HCursor =>
for {
// TODO: How to test if downField worked?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

projectId <- cursor.downField("scope").downField("project").downField("id").as[String]
} yield Assignment(projectId)
}
}

case class Assignment(projectId: String)
}

case class Role(
id: String,
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ package pt.tecnico.dsi.openstack.keystone.services
import cats.effect.Sync
import cats.syntax.flatMap._
import fs2.Stream
import org.http4s.Status.Conflict
import org.http4s.client.{Client, UnexpectedStatus}
import org.http4s.{Header, Query, Uri}
import org.http4s.Status.Conflict
import pt.tecnico.dsi.openstack.common.services.CrudService
import pt.tecnico.dsi.openstack.keystone.models.Role

final class Roles[F[_]: Sync: Client](baseUri: Uri, authToken: Header)
extends CrudService[F, Role, Role.Create, Role.Update](baseUri, "role", authToken)
with UniqueWithinDomain[F, Role] {

/**
* @param groupId filters the response by groupId
* @return a stream of ids from projects to which a certain group has been assigned a certain role
*/
def assignments(groupId: String): Stream[F, Role.Assignment] =
list[Role.Assignment]("role_assignments", baseUri / "role_assignments", Query.fromPairs("group.id" -> groupId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/**
* @param name filters the response by a role name.
* @param domainId filters the response by a domain ID.
Expand Down