-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Server&UI] Add token manager feature (#471)
- Loading branch information
Showing
34 changed files
with
960 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
datavines-server/src/main/java/io/datavines/server/api/annotation/CheckTokenExist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.datavines.server.api.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CheckTokenExist { | ||
} |
69 changes: 69 additions & 0 deletions
69
datavines-server/src/main/java/io/datavines/server/api/controller/AccessTokenController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.datavines.server.api.controller; | ||
|
||
import io.datavines.core.aop.RefreshToken; | ||
import io.datavines.core.constant.DataVinesConstants; | ||
import io.datavines.core.exception.DataVinesServerException; | ||
import io.datavines.server.api.dto.bo.token.TokenCreate; | ||
import io.datavines.server.api.dto.bo.token.TokenUpdate; | ||
import io.datavines.server.repository.service.AccessTokenService; | ||
import io.datavines.server.utils.ContextHolder; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.annotation.Resource; | ||
import javax.validation.Valid; | ||
|
||
@Api(value = "token", tags = "token", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@RestController | ||
@RequestMapping(value = DataVinesConstants.BASE_API_PATH + "/token", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@RefreshToken | ||
public class AccessTokenController { | ||
|
||
@Resource | ||
private AccessTokenService accessTokenService; | ||
|
||
@ApiOperation(value = "create token") | ||
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) | ||
public Object createToken(@Valid @RequestBody TokenCreate tokenCreate) throws DataVinesServerException { | ||
return accessTokenService.create(tokenCreate); | ||
} | ||
|
||
@ApiOperation(value = "update token") | ||
@PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE) | ||
public Object updateToken(@Valid @RequestBody TokenUpdate tokenUpdate) throws DataVinesServerException { | ||
return accessTokenService.update(tokenUpdate); | ||
} | ||
|
||
@ApiOperation(value = "delete token") | ||
@DeleteMapping(value = "/{id}") | ||
public Object deleteToken(@PathVariable Long id) { | ||
// 加入黑名单,并且需要拦截器进行处理 | ||
return accessTokenService.deleteToken(id); | ||
} | ||
|
||
@ApiOperation(value = "page token") | ||
@GetMapping(value = "/page") | ||
public Object listByUserId(@RequestParam("workspaceId") Long workspaceId, | ||
@RequestParam("pageNumber") Integer pageNumber, | ||
@RequestParam("pageSize") Integer pageSize) { | ||
return accessTokenService.page(workspaceId, ContextHolder.getUserId(), pageNumber, pageSize); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
datavines-server/src/main/java/io/datavines/server/api/controller/OpenApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.datavines.server.api.controller; | ||
|
||
import io.datavines.core.aop.RefreshToken; | ||
import io.datavines.core.constant.DataVinesConstants; | ||
import io.datavines.core.exception.DataVinesServerException; | ||
import io.datavines.server.api.annotation.CheckTokenExist; | ||
import io.datavines.server.api.dto.vo.JobExecutionResultVO; | ||
import io.datavines.server.repository.service.JobExecutionResultService; | ||
import io.datavines.server.repository.service.JobExecutionService; | ||
import io.datavines.server.repository.service.JobService; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Api(value = "openapi", tags = "openapi", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@RestController | ||
@RequestMapping(value = DataVinesConstants.BASE_API_PATH + "/openapi", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@RefreshToken | ||
@Validated | ||
public class OpenApiController { | ||
|
||
@Autowired | ||
private JobService jobService; | ||
|
||
@Autowired | ||
private JobExecutionService jobExecutionService; | ||
|
||
@Autowired | ||
private JobExecutionResultService jobExecutionResultService; | ||
|
||
@CheckTokenExist | ||
@ApiOperation(value = "execute job") | ||
@PostMapping(value = "/job/execute/{id}") | ||
public Object executeJob(@PathVariable("id") Long jobId) throws DataVinesServerException { | ||
return jobService.execute(jobId, null); | ||
} | ||
|
||
@CheckTokenExist | ||
@ApiOperation(value = "kill job", response = Long.class) | ||
@DeleteMapping(value = "/job/execution/kill/{executionId}") | ||
public Object kill(@PathVariable("executionId") Long executionId) { | ||
return jobExecutionService.killJob(executionId); | ||
} | ||
|
||
@CheckTokenExist | ||
@ApiOperation(value = "get job execution status", response = String.class) | ||
@GetMapping(value = "/job/execution/status/{executionId}") | ||
public Object getTaskStatus(@PathVariable("executionId") Long executionId) { | ||
return jobExecutionService.getById(executionId).getStatus().getCode(); | ||
} | ||
|
||
@CheckTokenExist | ||
@Deprecated | ||
@ApiOperation(value = "get job execution result", response = JobExecutionResultVO.class) | ||
@GetMapping(value = "/job/execution/result/{executionId}") | ||
public Object getJobExecutionResultInfo(@PathVariable("executionId") Long executionId) { | ||
return jobExecutionResultService.getCheckResultByJobExecutionId(executionId); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
datavines-server/src/main/java/io/datavines/server/api/dto/bo/token/TokenCreate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.datavines.server.api.dto.bo.token; | ||
|
||
import lombok.Data; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
|
||
@Data | ||
@NotNull(message = "Token Create cannot be null") | ||
public class TokenCreate { | ||
|
||
@NotNull(message = "WorkspaceId cannot be empty") | ||
private long workspaceId; | ||
|
||
@NotBlank(message = "expireTime cannot be empty") | ||
private String expireTime; | ||
} |
31 changes: 31 additions & 0 deletions
31
datavines-server/src/main/java/io/datavines/server/api/dto/bo/token/TokenUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.datavines.server.api.dto.bo.token; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@NotNull(message = "Token Update cannot be null") | ||
public class TokenUpdate extends TokenCreate { | ||
|
||
@NotNull(message = "Config id cannot be null") | ||
private Long id; | ||
} |
Oops, something went wrong.