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

feature: 执行账号使用权限迁移 #30 #88

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public EsbIamClient(String esbHostUrl, String appCode, String appSecret, String

@Override
public String getApplyUrl(List<ActionDTO> actionList) {
GetApplyUrlRequest getApplyUrlRequest = makeBaseReqByWeb(GetApplyUrlRequest.class, null, "admin", "superadmin");
GetApplyUrlRequest getApplyUrlRequest = makeBaseReqByWeb(
GetApplyUrlRequest.class,
null,
"admin",
"superadmin"
);
getApplyUrlRequest.setSystem(SystemId.JOB);
getApplyUrlRequest.setAction(actionList);
String respStr = null;
Expand Down Expand Up @@ -136,7 +141,11 @@ public boolean registerResource(String id, String name, String type, String crea
}

@Override
public EsbIamAuthedPolicy authByPath(EsbIamAction esbIamAction, EsbIamSubject esbIamSubject, List<EsbIamResource> esbIamResources) {
public EsbIamAuthedPolicy authByPath(
EsbIamAction esbIamAction,
EsbIamSubject esbIamSubject,
List<EsbIamResource> esbIamResources
) {
AuthByPathReq authByPathReq =
makeBaseReqByWeb(AuthByPathReq.class, null, "admin", "superadmin");
authByPathReq.setAction(esbIamAction);
Expand All @@ -150,15 +159,23 @@ public EsbIamAuthedPolicy authByPath(EsbIamAction esbIamAction, EsbIamSubject es
}

@Override
public List<EsbIamBatchAuthedPolicy> batchAuthByPath(List<EsbIamAction> esbIamActions, EsbIamSubject esbIamSubject, List<EsbIamBatchPathResource> esbIamBatchPathResources, Long expiredAt) {
public List<EsbIamBatchAuthedPolicy> batchAuthByPath(
List<EsbIamAction> esbIamActions,
EsbIamSubject esbIamSubject,
List<EsbIamBatchPathResource> esbIamBatchPathResources,
Long expiredAt
) {
BatchAuthByPathReq batchAuthByPathReq =
makeBaseReqByWeb(BatchAuthByPathReq.class, null, "admin", "superadmin");
batchAuthByPathReq.setActions(esbIamActions);
batchAuthByPathReq.setSubject(esbIamSubject);
batchAuthByPathReq.setResources(esbIamBatchPathResources);
batchAuthByPathReq.setExpiredAt(expiredAt);
EsbResp<List<EsbIamBatchAuthedPolicy>> esbResp = getEsbRespByReq(HttpPost.METHOD_NAME,
API_BATCH_AUTH_BY_PATH_URL, batchAuthByPathReq, new TypeReference<EsbResp<List<EsbIamBatchAuthedPolicy>>>() {
EsbResp<List<EsbIamBatchAuthedPolicy>> esbResp = getEsbRespByReq(
HttpPost.METHOD_NAME,
API_BATCH_AUTH_BY_PATH_URL,
batchAuthByPathReq,
new TypeReference<EsbResp<List<EsbIamBatchAuthedPolicy>>>() {
});
return esbResp.getData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Object getFieldValue(Object obj, String propertyName) {
field.setAccessible(true);
return field.get(obj);
} catch (NoSuchFieldException e) {
log.info("Fail to get field {} of {}", propertyName, obj);
log.info("no field {} of {}", propertyName, obj);
} catch (IllegalAccessException e) {
log.info("Cannot access field {} of {}", propertyName, obj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
import org.apache.commons.lang3.tuple.Pair;

import java.net.URLEncoder;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -44,6 +50,7 @@
public class StringUtil {

public static String replacePathVariables(String rawStr, Object obj) {
if (obj == null) return rawStr;
List<String> placeholderList = findOneRegexPatterns(rawStr, "(\\{.*?\\})");
for (String placeholder : placeholderList) {
String fieldName = placeholder.substring(1, placeholder.length() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.tencent.bk.job.common.annotation.InternalAPI;
import com.tencent.bk.job.common.model.ServiceResponse;
import com.tencent.bk.job.manage.model.inner.ServiceAppBaseInfoDTO;
import com.tencent.bk.job.manage.model.inner.ServiceApplicationDTO;
import com.tencent.bk.job.manage.model.inner.ServiceHostStatusDTO;
import com.tencent.bk.job.manage.model.inner.request.ServiceGetHostStatusByDynamicGroupReq;
Expand All @@ -49,6 +50,14 @@
@RestController
@InternalAPI
public interface ServiceApplicationResource {
/**
* 查询CMDB中的常规业务列表
*
* @return
*/
@RequestMapping("/list/normal")
ServiceResponse<List<ServiceAppBaseInfoDTO>> listNormalApps();

/**
* 根据业务id查询业务
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.upgrader.model;
package com.tencent.bk.job.manage.model.inner;

import lombok.AllArgsConstructor;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
/**
* 业务
*/
@Data
public class CompositeExpression {
private String op;
private List<Expression> content;
@ApiModel("业务")
public class ServiceAppBaseInfoDTO {

@ApiModelProperty("业务ID")
private Long id;

/**
* 业务名称
*/
@ApiModelProperty("业务名称")
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.tencent.bk.job.common.model.vo.HostInfoVO;
import com.tencent.bk.job.manage.api.inner.ServiceApplicationResource;
import com.tencent.bk.job.manage.dao.ApplicationInfoDAO;
import com.tencent.bk.job.manage.model.inner.ServiceAppBaseInfoDTO;
import com.tencent.bk.job.manage.model.inner.ServiceApplicationDTO;
import com.tencent.bk.job.manage.model.inner.ServiceHostStatusDTO;
import com.tencent.bk.job.manage.model.inner.request.ServiceGetHostStatusByDynamicGroupReq;
Expand Down Expand Up @@ -60,6 +61,14 @@ public ServiceApplicationResourceImpl(ApplicationService applicationService,
this.applicationInfoDAO = applicationInfoDAO;
}

@Override
public ServiceResponse<List<ServiceAppBaseInfoDTO>> listNormalApps() {
List<ApplicationInfoDTO> applicationInfoDTOList = applicationInfoDAO.listAppInfoByType(AppTypeEnum.NORMAL);
List<ServiceAppBaseInfoDTO> resultList =
applicationInfoDTOList.parallelStream().map(this::convertToServiceAppBaseInfo).collect(Collectors.toList());
return ServiceResponse.buildSuccessResp(resultList);
}

@Override
public ServiceApplicationDTO queryAppById(Long appId) {
ApplicationInfoDTO appInfo = applicationService.getAppInfoById(appId);
Expand All @@ -83,6 +92,12 @@ private ServiceApplicationDTO convertToServiceApp(ApplicationInfoDTO appInfo) {
return app;
}

private ServiceAppBaseInfoDTO convertToServiceAppBaseInfo(ApplicationInfoDTO appInfo) {
ServiceAppBaseInfoDTO appBaseInfoDTO = new ServiceAppBaseInfoDTO();
appBaseInfoDTO.setId(appInfo.getId());
appBaseInfoDTO.setName(appInfo.getName());
return appBaseInfoDTO;
}

@Override
public ServiceResponse<Boolean> checkAppPermission(Long appId, String username) {
Expand Down
Loading