Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Expand Up @@ -24,7 +24,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Objects;
import java.util.Collection;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
Expand Down Expand Up @@ -72,8 +72,17 @@ public Object around(ProceedingJoinPoint pjp, ApolloAuditLog auditLog) throws Th
}
}
if (entityName != null && fieldName != null) {
String matchedValue = String.valueOf(arg);
api.appendDataInfluence("AnyMatched", entityName, fieldName, matchedValue);
// if arg is a collection
if (arg instanceof Collection) {
for (Object o : ((Collection<?>) arg).toArray()) {
String matchedValue = String.valueOf(o);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some test for those code?

api.appendDataInfluence(entityName, "AnyMatched", fieldName, matchedValue);
}
}
else {
String matchedValue = String.valueOf(arg);
api.appendDataInfluence(entityName, "AnyMatched", fieldName, matchedValue);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public void appendDataInfluence(String entityName, String entityId, String field
OpType type = traceContext.tracer().getActiveSpan().getOpType();
ApolloAuditLogDataInfluence.Builder builder = ApolloAuditLogDataInfluence.builder().spanId(spanId)
.entityName(entityName).entityId(entityId).fieldName(fieldName);
if (type == null) {
return;
}
switch (type) {
case CREATE:
case UPDATE:
Expand Down Expand Up @@ -106,7 +109,7 @@ public void appendDataInfluences(List<Object> entities, Class<?> beanDefinition)
f.setAccessible(true);
String val = String.valueOf(f.get(e));
String fieldName = f.getAnnotation(ApolloAuditLogDataInfluenceTableField.class).fieldName();
appendDataInfluence(tableId, tableName, fieldName, val);
appendDataInfluence(tableName, tableId, fieldName, val);
}
} catch (IllegalAccessException ex) {
throw new IllegalArgumentException("failed append data influence, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testAppendDataInfluences() {
api.appendDataInfluences(entities, MockDataInfluenceEntity.class);

Mockito.verify(api, Mockito.times(entityNum))
.appendDataInfluence(Mockito.anyString(), Mockito.eq("MockTableName"), Mockito.eq("MarkedAttribute"),
.appendDataInfluence(Mockito.eq("MockTableName"), Mockito.any(), Mockito.eq("MarkedAttribute"),
Mockito.any());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.ctrip.framework.apollo.biz.service;

import com.ctrip.framework.apollo.audit.annotation.ApolloAuditLog;
import com.ctrip.framework.apollo.audit.annotation.OpType;
import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Namespace;
Expand Down Expand Up @@ -102,6 +104,7 @@ public List<AppNamespace> findByAppIdAndNamespaces(String appId, Set<String> nam
}

@Transactional
@ApolloAuditLog(type = OpType.CREATE, name = "AppNamespace.createDefault")
public void createDefaultAppNamespace(String appId, String createBy) {
if (!isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {
throw new ServiceException("appnamespace not unique");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,20 @@ public NamespaceDTO findPublicNamespaceForAssociatedNamespace(Env env, String ap
NamespaceDTO.class, appId, clusterName, namespaceName);
}

@ApolloAuditLog(type = OpType.RPC, name = "Namespace.createInRemote")
public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) {
return restTemplate
.post(env, "apps/{appId}/clusters/{clusterName}/namespaces", namespace, NamespaceDTO.class,
namespace.getAppId(), namespace.getClusterName());
}

@ApolloAuditLog(type = OpType.RPC, name = "AppNamespace.createInRemote")
public AppNamespaceDTO createAppNamespace(Env env, AppNamespaceDTO appNamespace) {
return restTemplate
.post(env, "apps/{appId}/appnamespaces", appNamespace, AppNamespaceDTO.class, appNamespace.getAppId());
}

@ApolloAuditLog(type = OpType.RPC, name = "AppNamespace.createMissingAppNamespaceInRemote")
public AppNamespaceDTO createMissingAppNamespace(Env env, AppNamespaceDTO appNamespace) {
return restTemplate
.post(env, "apps/{appId}/appnamespaces?silentCreation=true", appNamespace, AppNamespaceDTO.class,
Expand All @@ -140,6 +143,7 @@ public List<AppNamespaceDTO> getAppNamespaces(String appId, Env env) {
return Arrays.asList(appNamespaceDTOs);
}

@ApolloAuditLog(type = OpType.RPC, name = "Namespace.deleteInRemote")
public void deleteNamespace(Env env, String appId, String clusterName, String namespaceName, String operator) {
restTemplate
.delete(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}?operator={operator}", appId,
Expand Down Expand Up @@ -167,6 +171,7 @@ public int countPublicAppNamespaceAssociatedNamespaces(Env env, String publicNam
return count == null ? 0 : count;
}

@ApolloAuditLog(type = OpType.RPC, name = "AppNamespace.deleteInRemote")
public void deleteAppNamespace(Env env, String appId, String namespaceName, String operator) {
restTemplate.delete(env, "/apps/{appId}/appnamespaces/{namespaceName}?operator={operator}", appId, namespaceName,
operator);
Expand Down Expand Up @@ -266,12 +271,13 @@ public boolean isClusterUnique(String appId, Env env, String clusterName) {

}

@ApolloAuditLog(type = OpType.RPC, name = "Cluster.createInRemote")
public ClusterDTO create(Env env, ClusterDTO cluster) {
return restTemplate.post(env, "apps/{appId}/clusters", cluster, ClusterDTO.class,
cluster.getAppId());
}


@ApolloAuditLog(type = OpType.RPC, name = "Cluster.deleteInRemote")
public void delete(Env env, String appId, String clusterName, String operator) {
restTemplate.delete(env, "apps/{appId}/clusters/{clusterName}?operator={operator}", appId, clusterName, operator);
}
Expand All @@ -280,6 +286,7 @@ public void delete(Env env, String appId, String clusterName, String operator) {
@Service
public static class AccessKeyAPI extends API {

@ApolloAuditLog(type = OpType.RPC, name = "AccessKey.createInRemote")
public AccessKeyDTO create(Env env, AccessKeyDTO accessKey) {
return restTemplate.post(env, "apps/{appId}/accesskeys",
accessKey, AccessKeyDTO.class, accessKey.getAppId());
Expand All @@ -291,16 +298,19 @@ public List<AccessKeyDTO> findByAppId(Env env, String appId) {
return Arrays.asList(accessKeys);
}

@ApolloAuditLog(type = OpType.RPC, name = "AccessKey.deleteInRemote")
public void delete(Env env, String appId, long id, String operator) {
restTemplate.delete(env, "apps/{appId}/accesskeys/{id}?operator={operator}",
appId, id, operator);
}

@ApolloAuditLog(type = OpType.RPC, name = "AccessKey.enableInRemote")
public void enable(Env env, String appId, long id, String operator) {
restTemplate.put(env, "apps/{appId}/accesskeys/{id}/enable?operator={operator}",
null, appId, id, operator);
}

@ApolloAuditLog(type = OpType.RPC, name = "AccessKey.disableInRemote")
public void disable(Env env, String appId, long id, String operator) {
restTemplate.put(env, "apps/{appId}/accesskeys/{id}/disable?operator={operator}",
null, appId, id, operator);
Expand Down Expand Up @@ -513,6 +523,7 @@ public int getInstanceCountByNamespace(String appId, Env env, String clusterName
@Service
public static class NamespaceBranchAPI extends API {

@ApolloAuditLog(type = OpType.RPC, name = "NamespaceBranch.createInRemote")
public NamespaceDTO createBranch(String appId, Env env, String clusterName,
String namespaceName, String operator) {
return restTemplate
Expand All @@ -534,6 +545,7 @@ public GrayReleaseRuleDTO findBranchGrayRules(String appId, Env env, String clus

}

@ApolloAuditLog(type = OpType.RPC, name = "NamespaceBranch.updateInRemote")
public void updateBranchGrayRules(String appId, Env env, String clusterName,
String namespaceName, String branchName, GrayReleaseRuleDTO rules) {
restTemplate
Expand All @@ -542,6 +554,7 @@ public void updateBranchGrayRules(String appId, Env env, String clusterName,

}

@ApolloAuditLog(type = OpType.RPC, name = "NamespaceBranch.deleteInRemote")
public void deleteBranch(String appId, Env env, String clusterName,
String namespaceName, String branchName, String operator) {
restTemplate.delete(env,
Expand Down Expand Up @@ -587,6 +600,7 @@ public List<ServerConfig> findAllConfigDBConfig(Env env){
}).getBody();
}

@ApolloAuditLog(type = OpType.RPC, name = "ServerConfig.createOrUpdateConfigDBConfigInRemote")
public ServerConfig createOrUpdateConfigDBConfig(Env env, ServerConfig serverConfig){
return restTemplate.post(env, "/server/config", serverConfig, ServerConfig.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.ctrip.framework.apollo.portal.controller;

import com.ctrip.framework.apollo.audit.annotation.ApolloAuditLog;
import com.ctrip.framework.apollo.audit.annotation.OpType;
import com.ctrip.framework.apollo.common.dto.AccessKeyDTO;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.service.AccessKeyService;
Expand Down Expand Up @@ -44,6 +46,7 @@ public AccessKeyController(

@PreAuthorize(value = "@permissionValidator.isAppAdmin(#appId)")
@PostMapping(value = "/apps/{appId}/envs/{env}/accesskeys")
@ApolloAuditLog(type = OpType.CREATE, name = "AccessKey.create")
public AccessKeyDTO save(@PathVariable String appId, @PathVariable String env,
@RequestBody AccessKeyDTO accessKeyDTO) {
String secret = UUID.randomUUID().toString().replaceAll("-", "");
Expand All @@ -61,6 +64,7 @@ public List<AccessKeyDTO> findByAppId(@PathVariable String appId,

@PreAuthorize(value = "@permissionValidator.isAppAdmin(#appId)")
@DeleteMapping(value = "/apps/{appId}/envs/{env}/accesskeys/{id}")
@ApolloAuditLog(type = OpType.DELETE, name = "AccessKey.delete")
public void delete(@PathVariable String appId,
@PathVariable String env,
@PathVariable long id) {
Expand All @@ -70,6 +74,7 @@ public void delete(@PathVariable String appId,

@PreAuthorize(value = "@permissionValidator.isAppAdmin(#appId)")
@PutMapping(value = "/apps/{appId}/envs/{env}/accesskeys/{id}/enable")
@ApolloAuditLog(type = OpType.UPDATE, name = "AccessKey.enable")
public void enable(@PathVariable String appId,
@PathVariable String env,
@PathVariable long id) {
Expand All @@ -79,6 +84,7 @@ public void enable(@PathVariable String appId,

@PreAuthorize(value = "@permissionValidator.isAppAdmin(#appId)")
@PutMapping(value = "/apps/{appId}/envs/{env}/accesskeys/{id}/disable")
@ApolloAuditLog(type = OpType.UPDATE, name = "AccessKey.disable")
public void disable(@PathVariable String appId,
@PathVariable String env,
@PathVariable long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public List<App> findAppsByOwner(@RequestParam("owner") String owner, Pageable p

@PreAuthorize(value = "@permissionValidator.hasCreateApplicationPermission()")
@PostMapping
@ApolloAuditLog(type = OpType.CREATE)
@ApolloAuditLog(type = OpType.CREATE, name = "App.create")
public App create(@Valid @RequestBody AppModel appModel) {

App app = transformToApp(appModel);
Expand All @@ -130,7 +130,7 @@ public App create(@Valid @RequestBody AppModel appModel) {

@PreAuthorize(value = "@permissionValidator.isAppAdmin(#appId)")
@PutMapping("/{appId:.+}")
@ApolloAuditLog(type = OpType.UPDATE)
@ApolloAuditLog(type = OpType.UPDATE, name = "App.update")
public void update(@PathVariable String appId, @Valid @RequestBody AppModel appModel) {
if (!Objects.equals(appId, appModel.getAppId())) {
throw new BadRequestException("The App Id of path variable and request body is different");
Expand Down Expand Up @@ -161,6 +161,7 @@ public MultiResponseEntity<EnvClusterInfo> nav(@PathVariable String appId) {
}

@PostMapping(value = "/envs/{env}", consumes = {"application/json"})
@ApolloAuditLog(type = OpType.CREATE, name = "App.create.forEnv")
public ResponseEntity<Void> create(@PathVariable String env, @Valid @RequestBody App app) {
appService.createAppInRemote(Env.valueOf(env), app);

Expand All @@ -182,7 +183,7 @@ public AppDTO load(@PathVariable String appId) {

@PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@DeleteMapping("/{appId:.+}")
@ApolloAuditLog(type = OpType.RPC, name = "App.delete.request")
@ApolloAuditLog(type = OpType.RPC, name = "App.delete")
public void deleteApp(@PathVariable String appId) {
App app = appService.deleteAppInLocal(appId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.ctrip.framework.apollo.portal.controller;

import com.ctrip.framework.apollo.audit.annotation.ApolloAuditLog;
import com.ctrip.framework.apollo.audit.annotation.OpType;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.service.ClusterService;
Expand Down Expand Up @@ -44,6 +46,7 @@ public ClusterController(final ClusterService clusterService, final UserInfoHold

@PreAuthorize(value = "@permissionValidator.hasCreateClusterPermission(#appId)")
@PostMapping(value = "apps/{appId}/envs/{env}/clusters")
@ApolloAuditLog(type = OpType.CREATE, name = "Cluster.create")
public ClusterDTO createCluster(@PathVariable String appId, @PathVariable String env,
@Valid @RequestBody ClusterDTO cluster) {
String operator = userInfoHolder.getUser().getUserId();
Expand All @@ -55,6 +58,7 @@ public ClusterDTO createCluster(@PathVariable String appId, @PathVariable String

@PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@DeleteMapping(value = "apps/{appId}/envs/{env}/clusters/{clusterName:.+}")
@ApolloAuditLog(type = OpType.DELETE, name = "Cluster.delete")
public ResponseEntity<Void> deleteCluster(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName){
clusterService.deleteCluster(Env.valueOf(env), appId, clusterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.ctrip.framework.apollo.portal.controller;

import com.ctrip.framework.apollo.audit.annotation.ApolloAuditLog;
import com.ctrip.framework.apollo.audit.annotation.OpType;
import com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
Expand Down Expand Up @@ -78,6 +80,7 @@ public NamespaceBO findBranch(@PathVariable String appId,

@PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName, #env)")
@PostMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/branches")
@ApolloAuditLog(type = OpType.CREATE, name = "NamespaceBranch.create")
public NamespaceDTO createBranch(@PathVariable String appId,
@PathVariable String env,
@PathVariable String clusterName,
Expand All @@ -87,6 +90,7 @@ public NamespaceDTO createBranch(@PathVariable String appId,
}

@DeleteMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}")
@ApolloAuditLog(type = OpType.DELETE, name = "NamespaceBranch.delete")
public void deleteBranch(@PathVariable String appId,
@PathVariable String env,
@PathVariable String clusterName,
Expand All @@ -113,6 +117,7 @@ public void deleteBranch(@PathVariable String appId,

@PreAuthorize(value = "@permissionValidator.hasReleaseNamespacePermission(#appId, #namespaceName, #env)")
@PostMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/merge")
@ApolloAuditLog(type = OpType.UPDATE, name = "NamespaceBranch.merge")
public ReleaseDTO merge(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@PathVariable String branchName, @RequestParam(value = "deleteBranch", defaultValue = "true") boolean deleteBranch,
Expand Down Expand Up @@ -152,6 +157,7 @@ public GrayReleaseRuleDTO getBranchGrayRules(@PathVariable String appId, @PathVa

@PreAuthorize(value = "@permissionValidator.hasOperateNamespacePermission(#appId, #namespaceName, #env)")
@PutMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/rules")
@ApolloAuditLog(type = OpType.UPDATE, name = "NamespaceBranch.updateBranchRules")
public void updateBranchRules(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@PathVariable String branchName, @RequestBody GrayReleaseRuleDTO rules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.ctrip.framework.apollo.portal.controller;

import com.ctrip.framework.apollo.audit.annotation.ApolloAuditLog;
import com.ctrip.framework.apollo.audit.annotation.OpType;
import com.ctrip.framework.apollo.common.dto.AppNamespaceDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
Expand Down Expand Up @@ -141,6 +143,7 @@ public NamespaceBO findPublicNamespaceForAssociatedNamespace(@PathVariable Strin

@PreAuthorize(value = "@permissionValidator.hasCreateNamespacePermission(#appId)")
@PostMapping("/apps/{appId}/namespaces")
@ApolloAuditLog(type = OpType.CREATE, name = "Namespace.create")
public ResponseEntity<Void> createNamespace(@PathVariable String appId,
@RequestBody List<NamespaceCreationModel> models) {

Expand Down Expand Up @@ -171,6 +174,7 @@ public ResponseEntity<Void> createNamespace(@PathVariable String appId,

@PreAuthorize(value = "@permissionValidator.hasDeleteNamespacePermission(#appId)")
@DeleteMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/linked-namespaces/{namespaceName:.+}")
@ApolloAuditLog(type = OpType.DELETE, name = "Namespace.deleteLinkedNamespace")
public ResponseEntity<Void> deleteLinkedNamespace(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName) {

Expand All @@ -193,6 +197,7 @@ public List<NamespaceUsage> findNamespaceUsage(@PathVariable String appId, @Path

@PreAuthorize(value = "@permissionValidator.hasDeleteNamespacePermission(#appId)")
@DeleteMapping("/apps/{appId}/appnamespaces/{namespaceName:.+}")
@ApolloAuditLog(type = OpType.DELETE, name = "AppNamespace.delete")
public ResponseEntity<Void> deleteAppNamespace(@PathVariable String appId, @PathVariable String namespaceName) {

AppNamespace appNamespace = appNamespaceService.deleteAppNamespace(appId, namespaceName);
Expand All @@ -215,6 +220,7 @@ public AppNamespaceDTO findAppNamespace(@PathVariable String appId, @PathVariabl

@PreAuthorize(value = "@permissionValidator.hasCreateAppNamespacePermission(#appId, #appNamespace)")
@PostMapping("/apps/{appId}/appnamespaces")
@ApolloAuditLog(type = OpType.CREATE, name = "AppNamespace.create")
public AppNamespace createAppNamespace(@PathVariable String appId,
@RequestParam(defaultValue = "true") boolean appendNamespacePrefix,
@Valid @RequestBody AppNamespace appNamespace) {
Expand Down Expand Up @@ -272,6 +278,7 @@ public MultiResponseEntity<String> findMissingNamespaces(@PathVariable String ap
}

@PostMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/missing-namespaces")
@ApolloAuditLog(type = OpType.CREATE, name = "Namespace.createMissingNamespaces")
public ResponseEntity<Void> createMissingNamespaces(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName) {

Set<String> missingNamespaces = findMissingNamespaceNames(appId, env, clusterName);
Expand Down
Loading