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

feat: implement Roles public api #1980

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

roaminggypsy
Copy link
Contributor

No description provided.

@wfa-reviewable
Copy link

This change is Reviewable

Copy link
Member

@SanjayVas SanjayVas left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 6 files at r1, 1 of 2 files at r2, all commit messages.
Reviewable status: 5 of 6 files reviewed, 6 unresolved discussions (waiting on @roaminggypsy)


src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 64 at r2 (raw file):

          .asStatusRuntimeException(Status.Code.INVALID_ARGUMENT)

    val internalResponse =

nit: specify types when not obvious/redundant (i.e. when the type isn't mentioned on the right side of the assignment)

Suggestion:

val internalResponse: InternalRole

src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 68 at r2 (raw file):

        internalRolesStub.getRole(internalGetRoleRequest { roleResourceId = key.roleId })
      } catch (e: StatusException) {
        val exception: StatusRuntimeException =

nit: unnecessary variable. You can just throw the result of the when expression.


src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 99 at r2 (raw file):

  override suspend fun listRoles(request: ListRolesRequest): ListRolesResponse {
    if (request.pageSize < 0) {
      throw InvalidFieldValueException("page_size")

nit: Pass more information when you can

Suggestion:

InvalidFieldValueException("page_size") { fieldName -> "$fieldName cannot be negative" }

src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 104 at r2 (raw file):

    if (request.pageToken.isNotEmpty()) {
      if (!ResourceIds.RFC_1034_REGEX.matches(request.pageToken)) {

The regex is for the resource ID (role_id field in CreateRoleRequest), not the page token. The page token string should be a base64url-encoded serialized ListRolesPageToken message (though this fact is opaque to the public API caller).


src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 108 at r2 (raw file):

          .asStatusRuntimeException(Status.Code.INVALID_ARGUMENT)
      }
      getRole(getRoleRequest { name = "roles/${request.pageToken}" })

Why is this calling getRole? The page token isn't a role ID.


src/test/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesServiceTest.kt line 56 at r2 (raw file):

import org.wfanet.measurement.common.grpc.testing.mockService
import org.wfanet.measurement.common.testing.verifyProtoArgument
import org.wfanet.measurement.internal.access.ListRolesPageTokenKt.after as internalListRolesPageTokenAfter

Don't add aliases for functions inside of types. Instead, add an alias for the containing type.

You would then use this as InternalListRolesPageTokenKt.after

Suggestion:

import org.wfanet.measurement.internal.access.ListRolesPageTokenKt as InternalListRolesPageTokenKt

Copy link
Contributor Author

@roaminggypsy roaminggypsy left a comment

Choose a reason for hiding this comment

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

Reviewable status: 4 of 6 files reviewed, 3 unresolved discussions (waiting on @SanjayVas)


src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 104 at r2 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

The regex is for the resource ID (role_id field in CreateRoleRequest), not the page token. The page token string should be a base64url-encoded serialized ListRolesPageToken message (though this fact is opaque to the public API caller).

Done.


src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 108 at r2 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

Why is this calling getRole? The page token isn't a role ID.

Done.

Copy link
Contributor Author

@roaminggypsy roaminggypsy left a comment

Choose a reason for hiding this comment

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

Reviewable status: 4 of 6 files reviewed, 3 unresolved discussions (waiting on @SanjayVas)


src/test/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesServiceTest.kt line 56 at r2 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

Don't add aliases for functions inside of types. Instead, add an alias for the containing type.

You would then use this as InternalListRolesPageTokenKt.after

Done.

Copy link
Member

@SanjayVas SanjayVas left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r3, all commit messages.
Reviewable status: 5 of 6 files reviewed, 2 unresolved discussions (waiting on @roaminggypsy)


src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 106 at r4 (raw file):

          pageSize = request.pageSize
          if (request.pageToken.isNotEmpty()) {
            pageToken = internalListRolesPageToken { request.pageToken }

What you have is equivalent to InternalListRolesPageToken.getDefaultInstance()

You need to decode from base64 URL and then deserialize into a page token message. You probably want to throw an InvalidFieldValueException if you get an IOException or InvalidProtocolBufferException.

Suggestion:

InternalListRolesPageToken.parseFrom(request.pageToken.base64UrlDecode())

src/main/kotlin/org/wfanet/measurement/access/service/v1alpha/RolesService.kt line 114 at r4 (raw file):

      roles += internalResponse.rolesList.map { it.toRole() }
      if (internalResponse.hasNextPageToken()) {
        nextPageToken = internalResponse.nextPageToken.after.roleResourceId

Suggestion:

nextPageToken = internalResponse.nextPageToken.toByteString().base64UrlEncode()

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

Successfully merging this pull request may close these issues.

3 participants