Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -287,6 +287,17 @@ public final class Messages {
public static final String ENTRY_CREATE_AUDIT_LOG_CONFIG = "Configuration entry create";
public static final String ENTRY_UPDATE_AUDIT_LOG_CONFIG = "Configuration entry update";

public static final String LOGGING_CONFIGURATION_CREATE = "Create cloud-logging-configuration in space with id: {0}";
public static final String LOGGING_CONFIGURATION_UPDATE = "Update cloud-logging-configuration in space with id: {0}";
public static final String LOGGING_CONFIGURATION_DELETE = "Delete cloud-logging-configuration in space with id: {0}";
public static final String LOGGING_CONFIGURATION_GET = "Get cloud-logging-configuration in space with id: {0}";
public static final String LOGGING_CONFIGURATION_LIST = "List cloud-logging-configurations in space with id: {0}";
public static final String LOGGING_CONFIGURATION_CREATE_AUDIT_LOG_CONFIG = "Cloud logging configuration create";
public static final String LOGGING_CONFIGURATION_UPDATE_AUDIT_LOG_CONFIG = "Cloud logging configuration update";
public static final String LOGGING_CONFIGURATION_DELETE_AUDIT_LOG_CONFIG = "Cloud logging configuration delete";
public static final String LOGGING_CONFIGURATION_GET_AUDIT_LOG_CONFIG = "Cloud logging configuration get";
public static final String LOGGING_CONFIGURATION_LIST_AUDIT_LOG_CONFIG = "Cloud logging configuration list";

public static final String API_INFO_AUDIT_LOG_CONFIG = "Api info";
public static final String IGNORING_NAMESPACE_PARAMETERS = "Ignoring parameter \"{0}\" , as the MTA is not deployed with namespace!";
public static final String NAMESPACE_PARSING_ERROR_MESSAGE = "Cannot parse \"{0}\" flag - expected a boolean format.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ public ConfigurationSubscriptionServiceAuditLog buildAConfigurationSubscriptionS
public ConfigurationEntryServiceAuditLog buildAConfigurationEntryServiceAuditLog(AuditLoggingFacade auditLoggingFacade) {
return new ConfigurationEntryServiceAuditLog(auditLoggingFacade);
}

@Bean
public CloudLoggingServiceConfigurationAuditLog buildCloudLoggingServiceConfigurationAuditLog(AuditLoggingFacade auditLoggingFacade) {
return new CloudLoggingServiceConfigurationAuditLog(auditLoggingFacade);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.cloudfoundry.multiapps.controller.core.auditlogging;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.cloudfoundry.multiapps.controller.core.Messages;
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.AuditLogConfiguration;
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.ConfigurationChangeActions;
import org.cloudfoundry.multiapps.controller.persistence.model.LoggingConfiguration;

public class CloudLoggingServiceConfigurationAuditLog {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because SAP Cloud logging service is an internal proprietary service it should not be exposed in the open source. The whole logic related to the service must be move in the internal project.

Move every SAP related thing to the internal project and only leave the what is actually open source in this PR


private static final String ID_PROPERTY_NAME = "id";
private static final String MTA_ID_PROPERTY_NAME = "mtaId";
private static final String MTA_SPACE_PROPERTY_NAME = "mtaSpace";
private static final String MTA_SPACE_ID_PROPERTY_NAME = "mtaSpaceId";
private static final String MTA_ORG_PROPERTY_NAME = "mtaOrg";
private static final String NAMESPACE_PROPERTY_NAME = "namespace";
private static final String TARGET_SPACE_PROPERTY_NAME = "targetSpace";
private static final String TARGET_ORG_PROPERTY_NAME = "targetOrg";
private static final String SERVICE_INSTANCE_NAME_PROPERTY_NAME = "serviceInstanceName";
private static final String SERVICE_KEY_NAME_PROPERTY_NAME = "serviceKeyName";
private static final String LOG_LEVEL_PROPERTY_NAME = "logLevel";
private static final String IS_FAILSAFE_PROPERTY_NAME = "isFailSafe";

private final AuditLoggingFacade auditLoggingFacade;

public CloudLoggingServiceConfigurationAuditLog(AuditLoggingFacade auditLoggingFacade) {
this.auditLoggingFacade = auditLoggingFacade;
}

public void logCreateLoggingConfiguration(String username, String spaceId, LoggingConfiguration loggingConfiguration) {
String performedAction = MessageFormat.format(Messages.LOGGING_CONFIGURATION_CREATE, spaceId);
auditLoggingFacade.logConfigurationChangeAuditLog(new AuditLogConfiguration(username,
spaceId,
performedAction,
Messages.LOGGING_CONFIGURATION_CREATE_AUDIT_LOG_CONFIG,
buildIdentifiers(loggingConfiguration)),
ConfigurationChangeActions.CONFIGURATION_CREATE);
}

public void logUpdateLoggingConfiguration(String username, String spaceId, LoggingConfiguration newConfiguration) {
String performedAction = MessageFormat.format(Messages.LOGGING_CONFIGURATION_UPDATE, spaceId);
auditLoggingFacade.logConfigurationChangeAuditLog(new AuditLogConfiguration(username,
spaceId,
performedAction,
Messages.LOGGING_CONFIGURATION_UPDATE_AUDIT_LOG_CONFIG,
buildIdentifiers(newConfiguration)),
ConfigurationChangeActions.CONFIGURATION_UPDATE);
}

public void logDeleteLoggingConfiguration(String username, String spaceId, LoggingConfiguration loggingConfiguration) {
String performedAction = MessageFormat.format(Messages.LOGGING_CONFIGURATION_DELETE, spaceId);
auditLoggingFacade.logConfigurationChangeAuditLog(new AuditLogConfiguration(username,
spaceId,
performedAction,
Messages.LOGGING_CONFIGURATION_DELETE_AUDIT_LOG_CONFIG,
buildIdentifiers(loggingConfiguration)),
ConfigurationChangeActions.CONFIGURATION_DELETE);
}

public void logGetLoggingConfiguration(String username, String spaceId, LoggingConfiguration loggingConfiguration) {
String performedAction = MessageFormat.format(Messages.LOGGING_CONFIGURATION_GET, spaceId);
Map<String, String> identifiers = new HashMap<>();
identifiers.put(MTA_ID_PROPERTY_NAME, loggingConfiguration.getMtaId());
identifiers.put(NAMESPACE_PROPERTY_NAME, loggingConfiguration.getNamespace());
auditLoggingFacade.logDataAccessAuditLog(new AuditLogConfiguration(username,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why buildIdentifiers is not used in this method?

spaceId,
performedAction,
Messages.LOGGING_CONFIGURATION_GET_AUDIT_LOG_CONFIG,
identifiers));
}

public void logListLoggingConfigurations(String username, String spaceId) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this really used?

String performedAction = MessageFormat.format(Messages.LOGGING_CONFIGURATION_LIST, spaceId);
auditLoggingFacade.logDataAccessAuditLog(new AuditLogConfiguration(username,
spaceId,
performedAction,
Messages.LOGGING_CONFIGURATION_LIST_AUDIT_LOG_CONFIG));
}

private Map<String, String> buildIdentifiers(LoggingConfiguration loggingConfiguration) {
Map<String, String> identifiers = new HashMap<>();
identifiers.put(ID_PROPERTY_NAME, loggingConfiguration.getId());
identifiers.put(MTA_ID_PROPERTY_NAME, loggingConfiguration.getMtaId());
identifiers.put(MTA_SPACE_PROPERTY_NAME, loggingConfiguration.getMtaSpace());
identifiers.put(MTA_SPACE_ID_PROPERTY_NAME, loggingConfiguration.getMtaSpaceId());
identifiers.put(MTA_ORG_PROPERTY_NAME, loggingConfiguration.getMtaOrg());
identifiers.put(NAMESPACE_PROPERTY_NAME, loggingConfiguration.getNamespace());
identifiers.put(TARGET_SPACE_PROPERTY_NAME, loggingConfiguration.getTargetSpace());
identifiers.put(TARGET_ORG_PROPERTY_NAME, loggingConfiguration.getTargetOrg());
identifiers.put(SERVICE_INSTANCE_NAME_PROPERTY_NAME, loggingConfiguration.getServiceInstanceName());
identifiers.put(SERVICE_KEY_NAME_PROPERTY_NAME, loggingConfiguration.getServiceKeyName());
Comment on lines +91 to +95
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we use the IDs of target space and service instance?

identifiers.put(LOG_LEVEL_PROPERTY_NAME, Objects.toString(loggingConfiguration.getLogLevel()));
identifiers.put(IS_FAILSAFE_PROPERTY_NAME, Objects.toString(loggingConfiguration.isFailSafe()));
return identifiers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

public enum ResourceType {
MANAGED_SERVICE("managed-service", SupportedParameters.SERVICE, SupportedParameters.SERVICE_PLAN), USER_PROVIDED_SERVICE(
"user-provided-service"), EXISTING_SERVICE("existing-service"), EXISTING_SERVICE_KEY("existing-service-key");
"user-provided-service"), EXISTING_SERVICE("existing-service"), EXISTING_SERVICE_KEY("existing-service-key"),
CLOUD_LOGGING_SERVICE("cloud-logging-service");

private final String name;
private final Set<String> requiredParameters = new HashSet<>();
Expand All @@ -33,7 +34,7 @@ public static ResourceType get(String value) {
}

public static Set<ResourceType> getServiceTypes() {
return EnumSet.of(MANAGED_SERVICE, USER_PROVIDED_SERVICE, EXISTING_SERVICE);
return EnumSet.of(MANAGED_SERVICE, USER_PROVIDED_SERVICE, EXISTING_SERVICE, CLOUD_LOGGING_SERVICE);
}

public Set<String> getRequiredParameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudApplication;
import org.cloudfoundry.multiapps.controller.client.facade.rest.CloudSpaceClient;
import org.cloudfoundry.multiapps.controller.core.Messages;
import org.cloudfoundry.multiapps.controller.core.auditlogging.CloudLoggingServiceConfigurationAuditLog;
import org.cloudfoundry.multiapps.controller.core.auditlogging.MtaConfigurationPurgerAuditLog;
import org.cloudfoundry.multiapps.controller.core.cf.metadata.MtaMetadata;
import org.cloudfoundry.multiapps.controller.core.cf.metadata.processor.MtaMetadataParser;
Expand All @@ -20,6 +21,8 @@
import org.cloudfoundry.multiapps.controller.persistence.model.CloudTarget;
import org.cloudfoundry.multiapps.controller.persistence.model.ConfigurationEntry;
import org.cloudfoundry.multiapps.controller.persistence.model.ConfigurationSubscription;
import org.cloudfoundry.multiapps.controller.persistence.model.LoggingConfiguration;
import org.cloudfoundry.multiapps.controller.persistence.services.CloudLoggingServiceConfigurationService;
import org.cloudfoundry.multiapps.controller.persistence.services.ConfigurationEntryService;
import org.cloudfoundry.multiapps.controller.persistence.services.ConfigurationSubscriptionService;
import org.slf4j.Logger;
Expand All @@ -37,17 +40,23 @@
private final ConfigurationEntryService configurationEntryService;
private final ConfigurationSubscriptionService configurationSubscriptionService;
private MtaMetadataParser mtaMetadataParser;
private CloudLoggingServiceConfigurationService cloudLoggingServiceConfigurationService;
private CloudLoggingServiceConfigurationAuditLog cloudLoggingServiceConfigurationAuditLog;

public MtaConfigurationPurger(CloudControllerClient client, CloudSpaceClient spaceClient,

Check warning on line 46 in multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/helpers/MtaConfigurationPurger.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Constructor has 8 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=cloudfoundry_multiapps-controller&issues=AZ5tnXqXE1924JjNgYTV&open=AZ5tnXqXE1924JjNgYTV&pullRequest=1847
ConfigurationEntryService configurationEntryService,
ConfigurationSubscriptionService configurationSubscriptionService, MtaMetadataParser mtaMetadataParser,
MtaConfigurationPurgerAuditLog mtaConfigurationPurgerAuditLog) {
MtaConfigurationPurgerAuditLog mtaConfigurationPurgerAuditLog,
CloudLoggingServiceConfigurationService cloudLoggingServiceConfigurationService,
CloudLoggingServiceConfigurationAuditLog cloudLoggingServiceConfigurationAuditLog) {
this.client = client;
this.spaceClient = spaceClient;
this.configurationEntryService = configurationEntryService;
this.configurationSubscriptionService = configurationSubscriptionService;
this.mtaMetadataParser = mtaMetadataParser;
this.mtaConfigurationPurgerAuditLog = mtaConfigurationPurgerAuditLog;
this.cloudLoggingServiceConfigurationService = cloudLoggingServiceConfigurationService;
this.cloudLoggingServiceConfigurationAuditLog = cloudLoggingServiceConfigurationAuditLog;
}

public void purge(String org, String space) {
Expand All @@ -56,6 +65,7 @@
List<CloudApplication> existingApps = getExistingApps();
purgeConfigurationSubscriptions(targetId, existingApps);
purgeConfigurationEntries(targetSpace, existingApps, targetId);
purgeCloudLoggingServiceConfigurations(targetId);
}

private void purgeConfigurationSubscriptions(String spaceId, List<CloudApplication> existingApps) {
Expand Down Expand Up @@ -96,6 +106,15 @@
}
}

private void purgeCloudLoggingServiceConfigurations(String spaceId) {
List<LoggingConfiguration> loggingConfigurations = cloudLoggingServiceConfigurationService.getAllCloudLoggingServiceConfigurationsFromSpace(
spaceId);
for (LoggingConfiguration loggingConfiguration : loggingConfigurations) {
cloudLoggingServiceConfigurationService.deleteCloudLoggingServiceConfiguration(loggingConfiguration.getId());
cloudLoggingServiceConfigurationAuditLog.logDeleteLoggingConfiguration("", spaceId, loggingConfiguration);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can get the user guid here from the securityContext

}
}

private boolean isStillRelevant(List<ConfigurationEntry> stillRelevantEntries, ConfigurationEntry entry) {
return stillRelevantEntries.stream()
.anyMatch(currentEntry -> haveSameProviderIdAndVersion(currentEntry, entry));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.cloudfoundry.multiapps.controller.core.model;

import java.util.List;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.cloudfoundry.multiapps.common.Nullable;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableExternalLoggingServiceConfiguration.class)
@JsonDeserialize(as = ImmutableExternalLoggingServiceConfiguration.class)
public interface ExternalLoggingServiceConfiguration {

@Nullable
String getServiceInstanceName();

@Nullable
String getServiceKeyName();

@Nullable
String getTargetOrg();

@Nullable
String getTargetSpace();

@Nullable
String getOperationId();

@Nullable
String getEndpointUrl();

@Nullable
String getServerCa();

@Nullable
String getClientCert();

@Nullable
String getClientKey();

@Nullable
List<String> getLogLevels();

@Nullable
Boolean isFailSafe();
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public class SupportedParameters {
public static final String FAIL_ON_SERVICE_UPDATE = "fail-on-service-update";
public static final String SYSLOG_DRAIN_URL = "syslog-drain-url";
public static final String SERVICE_GUID = "service-guid";
public static final String LOG_LEVEL = "log-level";
public static final String DESTINATION = "destination";

// Configuration reference (new syntax):
public static final String PROVIDER_NID = "provider-nid";
Expand Down Expand Up @@ -210,7 +212,8 @@ public class SupportedParameters {
SERVICE_KEY_NAME, SERVICE_NAME, SERVICE_PLAN, SERVICE_TAGS, SERVICE_BROKER,
SKIP_SERVICE_UPDATES, TYPE, PROVIDER_ID, PROVIDER_NID, TARGET,
SERVICE_CONFIG_PATH, FILTER, MANAGED, VERSION, PATH, MEMORY,
FAIL_ON_SERVICE_UPDATE, SERVICE_PROVIDER, SERVICE_VERSION);
FAIL_ON_SERVICE_UPDATE, SERVICE_PROVIDER, SERVICE_VERSION, LOG_LEVEL,
DESTINATION);
public static final Set<String> GLOBAL_PARAMETERS = Set.of(KEEP_EXISTING_ROUTES, APPS_UPLOAD_TIMEOUT, APPS_TASK_EXECUTION_TIMEOUT,
APPS_START_TIMEOUT, APPS_STAGE_TIMEOUT, APPLY_NAMESPACE,
ENABLE_PARALLEL_DEPLOYMENTS, DEPLOY_MODE, BG_DEPENDENCY_AWARE_STOP_ORDER);
Expand Down
Loading
Loading