Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/improve-docker-email-setting' in…
Browse files Browse the repository at this point in the history
…to improve-docker-email-setting

# Conflicts:
#	streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/SettingAlertEmailConfigParams.java
#	streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/SettingDockerConfigParams.java
#	streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/SettingController.java
#	streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/SettingService.java
#	streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SettingServiceImpl.java
#	streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/bean/SettingAlertEmailConfigParamsTest.java
#	streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/bean/SettingDockerConfigParamsTest.java
#	streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/SettingServiceTest.java
  • Loading branch information
zzzk1 committed Feb 27, 2024
2 parents 779f878 + ed745ed commit 9db8616
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 0 deletions.
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 org.apache.streampark.console.core.bean;

import org.apache.streampark.console.core.service.SettingService;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
* The DockerConfig class represents the configuration for an email system. It holds the SMTP host,
* port, from address, username, password, and whether SSL is enabled.
*
* <p>This class also provides a static factory method to create an DockerConfig object from a map
* of settings.
*/
@Data
@Slf4j
public class DockerConfig {

private String address;
private String user;
private String password;
private String namespace;

public static DockerConfig fromSetting() {
try {
DockerConfig dockerConfig = new DockerConfig();

dockerConfig.setAddress(
SettingService.SETTINGS
.get(SettingService.KEY_DOCKER_REGISTER_ADDRESS)
.getSettingValue());

dockerConfig.setUser(
SettingService.SETTINGS.get(SettingService.KEY_DOCKER_REGISTER_USER).getSettingValue());

dockerConfig.setPassword(
SettingService.SETTINGS
.get(SettingService.KEY_DOCKER_REGISTER_PASSWORD)
.getSettingValue());

dockerConfig.setNamespace(
SettingService.SETTINGS
.get(SettingService.KEY_DOCKER_REGISTER_NAMESPACE)
.getSettingValue());

return dockerConfig;
} catch (Exception e) {
log.warn("Failed to create DockerConfig from settings", e);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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 org.apache.streampark.console.core.bean;

import org.apache.streampark.common.conf.CommonConfig;
import org.apache.streampark.common.conf.InternalConfigHolder;
import org.apache.streampark.console.core.entity.Setting;
import org.apache.streampark.console.core.service.SettingService;

import org.apache.commons.lang3.StringUtils;

import lombok.Data;

import java.util.Map;

/**
* This class represents the Maven configuration for the application. It provides methods to
* retrieve the various Maven configuration options.
*/
@Data
public class MavenConfig {

/** File path for Maven settings. */
private String mvnSettings;

/** Repository URL for Maven. */
private String mvnRepository;

/** User for Maven authentication. */
private String mvnAuthUser;

/** Password for Maven authentication. */
private String mvnAuthPassword;

/** */
public static MavenConfig fromSetting() {
MavenConfig mavenConfig = new MavenConfig();
Map<String, Setting> settings = SettingService.SETTINGS;
if (settings.containsKey(CommonConfig.MAVEN_SETTINGS_PATH().key())) {
mavenConfig.setMvnSettings(
settings.get(CommonConfig.MAVEN_SETTINGS_PATH().key()).getSettingValue());
}

if (settings.containsKey(CommonConfig.MAVEN_REMOTE_URL().key())) {
mavenConfig.setMvnRepository(
settings.get(CommonConfig.MAVEN_REMOTE_URL().key()).getSettingValue());
}

if (settings.containsKey(CommonConfig.MAVEN_AUTH_USER().key())) {
mavenConfig.setMvnAuthUser(
settings.get(CommonConfig.MAVEN_AUTH_USER().key()).getSettingValue());
}

if (settings.containsKey(CommonConfig.MAVEN_AUTH_PASSWORD().key())) {
mavenConfig.setMvnAuthPassword(
settings.get(CommonConfig.MAVEN_AUTH_PASSWORD().key()).getSettingValue());
}

return mavenConfig;
}

/**
* Updates the internal configuration of Maven based on the assigned instance variables. If the
* instance variables mvnSettings, mvnRepository, mvnAuthUser, or mvnAuthPassword have non-empty
* values, they will be updated in the internal configuration.
*/
public void updateConfig() {

if (StringUtils.isNotBlank(mvnSettings)) {
InternalConfigHolder.set(CommonConfig.MAVEN_SETTINGS_PATH(), mvnSettings);
}

if (StringUtils.isNotBlank(mvnRepository)) {
InternalConfigHolder.set(CommonConfig.MAVEN_REMOTE_URL(), mvnRepository);
}

if (StringUtils.isNotBlank(mvnAuthUser)) {
InternalConfigHolder.set(CommonConfig.MAVEN_AUTH_USER(), mvnAuthUser);
}

if (StringUtils.isNotBlank(mvnAuthPassword)) {
InternalConfigHolder.set(CommonConfig.MAVEN_AUTH_PASSWORD(), mvnAuthPassword);
}
}
}

0 comments on commit 9db8616

Please sign in to comment.