-
Notifications
You must be signed in to change notification settings - Fork 117
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
Add HTTP API for updating a token level #942
Conversation
61d8995
to
8af41e5
Compare
server/src/main/java/com/linecorp/centraldogma/server/internal/api/TokenService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/linecorp/centraldogma/server/internal/api/TokenService.java
Outdated
Show resolved
Hide resolved
token -> { | ||
if (token.isAdmin()) { | ||
return mds.updateTokenToUser(author, appId).thenApply( | ||
unused -> mds.findTokenByAppId(appId).join().withoutSecret() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
join()
should not be called for asynchronous code. thenCompose()
could be used instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the join()
.
8801c98
to
539202f
Compare
539202f
to
e7ee043
Compare
Could you add an e2e test to verify that the request is converted correctly? |
server/src/main/java/com/linecorp/centraldogma/server/internal/api/TokenService.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great so far. 😉
server/src/test/java/com/linecorp/centraldogma/server/internal/api/TokenServiceTest.java
Outdated
Show resolved
Hide resolved
server/src/test/java/com/linecorp/centraldogma/server/internal/api/TokenServiceTest.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/linecorp/centraldogma/server/internal/api/TokenLevelRequest.java
Outdated
Show resolved
Hide resolved
@@ -192,6 +193,41 @@ public CompletableFuture<Token> updateToken(ServiceRequestContext ctx, | |||
); | |||
} | |||
|
|||
/** | |||
* PATCH /tokens/{appId}/permission |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use permission or level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change "permission" to "level" in the comment.
return mds.updateTokenToAdmin(author, appId).thenCompose( | ||
unused -> mds.findTokenByAppId(appId).thenApply(Token::withoutSecret)); | ||
default: | ||
throw new IllegalArgumentException("Unexpected token level: " + tokenLevelRequest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do this before calling getTokenOrRespondForbidden
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before calling getTokenOrRespondForbidden
, i will check the argument.
checkArgument(Arrays.asList("user", "admin").contains(tokenLevelRequest.level().toLowerCase()),
"Unsupported token level: " + tokenLevelRequest.level());
server/src/main/java/com/linecorp/centraldogma/server/internal/api/TokenService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/linecorp/centraldogma/server/metadata/MetadataService.java
Outdated
Show resolved
Hide resolved
1985215
to
1e9ef81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of nits. Great job, @byungjunn! 👍
server/src/main/java/com/linecorp/centraldogma/server/internal/api/TokenLevelRequest.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/linecorp/centraldogma/server/internal/api/TokenService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/linecorp/centraldogma/server/metadata/MetadataService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! 💯💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for merging 👍 👍 👍
*/ | ||
@Patch("/tokens/{appId}/level") | ||
@RequiresAdministrator | ||
public CompletableFuture<Token> updateTokenLevel(ServiceRequestContext ctx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit; I'm fine with adding an API, but in retrospect I wonder if we could've just reused updateToken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ ❤️ ❤️
Motivation:
Modification:
Result: