-
Notifications
You must be signed in to change notification settings - Fork 41
Add cloud logging service feature #1847
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
|
|
||
| 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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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
|
||
| 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) { | ||
|
|
@@ -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) { | ||
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
|
||
| 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(); | ||
| } |
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.
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