diff --git a/Dockerfile b/Dockerfile
index b22bfc1..493d689 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,11 +1,3 @@
-# from platten/alpine-oracle-jre8-docker
-# LABEL maintainer = "Webank CTB Team"
-# ADD artifacts-core/target/artifacts-core-0.0.1-SNAPSHOT.jar /application/wecube-plugins-artifacts.jar
-# ADD build/start.sh /scripts/start.sh
-# RUN chmod +x /scripts/start.sh
-# ADD build/tomcat_exporter.tar /scripts/
-# CMD ["/bin/sh","-c","/scripts/start.sh $WECUBE_GATEWAY_SERVER_URL $ARTIFACTS_S3_SERVER_URL $ARTIFACTS_S3_ACCESS_KEY $ARTIFACTS_S3_SECRET_KEY $ARTIFACTS_NEXUS_SERVER_URL $ARTIFACTS_NEXUS_USERNAME $ARTIFACTS_NEXUS_PASSWORD $ARTIFACTS_NEXUS_REPOSITORY $CMDB_ARTIFACT_PATH $JWT_SIGNING_KEY"]
-
from sonatype/nexus3:3.27.0
LABEL maintainer = "Webank CTB Team"
USER root
diff --git a/Dockerfile_nonexus b/Dockerfile_nonexus
new file mode 100644
index 0000000..1a8a264
--- /dev/null
+++ b/Dockerfile_nonexus
@@ -0,0 +1,19 @@
+FROM python:3.7-slim
+LABEL maintainer = "Webank CTB Team"
+RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
+RUN sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
+ADD artifacts-corepy/requirements.txt /tmp/requirements.txt
+ADD artifacts-corepy/dist/* /tmp/
+RUN mkdir -p /etc/artifacts_corepy/
+RUN mkdir -p /var/log/artifacts_corepy/
+ADD artifacts-corepy/etc/* /etc/artifacts_corepy/
+# Install && Clean up
+RUN apt update && apt-get -y install gcc python3-dev && \
+ pip3 install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r /tmp/requirements.txt && \
+ pip3 install /tmp/*.whl && \
+ rm -rf /root/.cache && apt autoclean && \
+ rm -rf /tmp/* /var/lib/apt/* /var/cache/* && \
+ apt purge -y `cat /var/log/apt/history.log|grep 'Install: '|tail -1| sed 's/Install://'| sed 's/\ /\n/g' | sed '/(/d' | sed '/)/d' | sed ':l;N;s/\n/ /;b l'`
+ADD build/start_all.sh /scripts/start_all.sh
+RUN chmod +x /scripts/start_all.sh
+CMD ["/bin/sh","-c","/scripts/start_all.sh"]
\ No newline at end of file
diff --git a/Makefile b/Makefile
index c1e55ea..6ee5189 100644
--- a/Makefile
+++ b/Makefile
@@ -3,42 +3,7 @@ version=$(shell bash ./build/version.sh)
date=$(shell date +%Y%m%d%H%M%S)
project_name=$(shell basename "${current_dir}")
remote_docker_image_registry=ccr.ccs.tencentyun.com/webankpartners/wecube-plugins-artifacts
-
-
-clean:
- rm -rf $(current_dir)/target
-
-.PHONY:build
-build: clean
- mkdir -p repository
- docker run --rm --name wecube-plugins-artifacts-build -v /data/repository:/usr/src/mymaven/repository -v $(current_dir)/build/maven_settings.xml:/usr/share/maven/ref/settings-docker.xml -v $(current_dir):/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn -U clean install -Dmaven.test.skip=true -DbuildType=plugin -s /usr/share/maven/ref/settings-docker.xml dependency:resolve
-
-image: build
- docker build -t $(project_name):$(version) .
-
-s3_server_url=http://10.10.10.1:9000
-s3_access_key=access_key
-s3_secret_key=secret_key
-
-.PHONY:package
-package: image
- rm -rf package
- mkdir -p package
- cd package && docker save $(project_name):$(version) -o image.tar
- cd package && cp ../register.xml .
- cd package && sed -i "s~{{REPOSITORY}}~$(project_name)~g" register.xml
- cd package && sed -i "s~{{VERSION}}~$(version)~g" register.xml
- cd artifacts-ui/dist && zip -r ui.zip .
- cd package && cp ../artifacts-ui/dist/ui.zip .
- cd package && zip -r $(project_name)-$(version).zip .
- docker rmi $(project_name):$(version)
-
-upload: package
- $(eval container_id:=$(shell docker run -v $(current_dir)/package:/package -itd --entrypoint=/bin/sh minio/mc))
- docker exec $(container_id) mc config host add wecubeS3 $(s3_server_url) $(s3_access_key) $(s3_secret_key) wecubeS3
- docker exec $(container_id) mc cp /package/$(project_name)-$(version).zip wecubeS3/wecube-plugin-package-bucket
- docker stop $(container_id)
- docker rm -f $(container_id)
+with_nexus='true'
clean_py:
rm -rf $(current_dir)/artifacts-corepy/dist/
@@ -53,7 +18,12 @@ build_py: clean_py
image_py: build_py
wget -O nexus-data.tar.gz https://wecube-1259801214.cos.ap-guangzhou.myqcloud.com/nexus-data/nexus-data.tar.gz
- docker build -t $(project_name):$(version) .
+ @if [ $(with_nexus) == 'true' ]; \
+ then \
+ docker build -t $(project_name):$(version) .; \
+ else \
+ docker build -t $(project_name):$(version) -f Dockerfile_nonexus .; \
+ fi
package_py: image_py
rm -rf package
diff --git a/artifacts-core/.factorypath b/artifacts-core/.factorypath
deleted file mode 100644
index f484f44..0000000
--- a/artifacts-core/.factorypath
+++ /dev/null
@@ -1,135 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/artifacts-core/.gitignore b/artifacts-core/.gitignore
deleted file mode 100644
index 4b9b730..0000000
--- a/artifacts-core/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/target/
-/bin/
-/.apt_generated/
diff --git a/artifacts-core/pom.xml b/artifacts-core/pom.xml
deleted file mode 100644
index 0cda6e7..0000000
--- a/artifacts-core/pom.xml
+++ /dev/null
@@ -1,158 +0,0 @@
-
- 4.0.0
-
- com.webank
- wecube-plugins-artifacts
- 0.0.1-SNAPSHOT
-
- artifacts-core
-
-
- io.jsonwebtoken
- jjwt
- 0.7.0
-
-
- org.springframework.boot
- spring-boot-starter-data-jpa
-
-
-
- org.springframework.boot
- spring-boot-starter-thymeleaf
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- org.springframework.session
- spring-session-core
-
-
-
- org.springframework.boot
- spring-boot-configuration-processor
-
-
- org.springframework.boot
- spring-boot-starter-security
-
-
-
- org.apache.commons
- commons-lang3
-
-
-
- commons-beanutils
- commons-beanutils
- 1.9.4
-
-
-
- commons-io
- commons-io
- 2.6
-
-
-
- com.google.guava
- guava
- 27.0.1-jre
-
-
- org.projectlombok
- lombok
-
-
-
- io.springfox
- springfox-swagger2
- 2.9.2
- compile
-
-
- io.springfox
- springfox-swagger-ui
- 2.9.2
- compile
-
-
-
- mysql
- mysql-connector-java
- runtime
-
-
-
- com.amazonaws
- aws-java-sdk-s3
- 1.11.106
-
-
-
- org.apache.poi
- poi
- 4.1.0
-
-
-
- org.bouncycastle
- bcprov-ext-jdk15on
- 1.63
-
-
-
- commons-codec
- commons-codec
-
-
-
- com.github.ulisesbocchio
- jasypt-spring-boot-starter
- 3.0.3
-
-
-
- com.h2database
- h2
- test
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- 1.8
- UTF-8
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
- repackage
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/Application.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/Application.java
deleted file mode 100644
index ba4a361..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/Application.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.webank.plugins.artifacts;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
-
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
-@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
-@SpringBootApplication
-@EnableSwagger2
-public class Application {
-
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/DefaultJwtSsoTokenParser.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/DefaultJwtSsoTokenParser.java
deleted file mode 100644
index 3d4d32a..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/DefaultJwtSsoTokenParser.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.webank.plugins.artifacts.auth.filter;
-
-import org.apache.commons.codec.binary.Base64;
-
-import io.jsonwebtoken.Claims;
-import io.jsonwebtoken.Jws;
-import io.jsonwebtoken.JwtParser;
-import io.jsonwebtoken.Jwts;
-
-/**
- *
- * @author gavinli
- *
- */
-public class DefaultJwtSsoTokenParser implements JwtSsoTokenParser {
-
- private static final String SIGNING_KEY = "Platform+Auth+Server+Secret";
-
- private String jwtSigningKey;
-
- private JwtParser jwtParser;
-
- public DefaultJwtSsoTokenParser(String jwtSigningKey) {
- if (jwtSigningKey == null || jwtSigningKey.trim().length() < 1) {
- this.jwtSigningKey = SIGNING_KEY;
- } else {
- this.jwtSigningKey = jwtSigningKey;
- }
-
- this.jwtParser = Jwts.parser().setSigningKey(decodeBase64(getJwtSigningKey()));
- }
-
- @Override
- public Jws parseJwt(String token) {
- return jwtParser.parseClaimsJws(token);
- }
-
- private String getJwtSigningKey() {
- return jwtSigningKey;
- }
-
- private byte[] decodeBase64(String base64String) {
- return Base64.decodeBase64(base64String);
- }
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/Http401AuthenticationEntryPoint.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/Http401AuthenticationEntryPoint.java
deleted file mode 100644
index a409e24..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/Http401AuthenticationEntryPoint.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.webank.plugins.artifacts.auth.filter;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.web.AuthenticationEntryPoint;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class Http401AuthenticationEntryPoint implements AuthenticationEntryPoint {
- private static final Logger log = LoggerFactory.getLogger(Http401AuthenticationEntryPoint.class);
-
- private static String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
-
- private String headerValue = "Bearer realm=\"Central Authentication Server\";profile=\"JWT\";";
-
- private ObjectMapper objectMapper = new ObjectMapper();
-
- @Override
- public void commence(HttpServletRequest request, HttpServletResponse response,
- AuthenticationException authException) throws IOException, ServletException {
-
- log.info("=== authentication failed === ");
- response.setHeader(HEADER_WWW_AUTHENTICATE, translateAuthenticateHeader(authException));
- response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
-
- AuthenticationFailedResponse responseBody = AuthenticationFailedResponse.error(authException.getMessage());
- response.getOutputStream().println(objectMapper.writeValueAsString(responseBody));
- response.getOutputStream().flush();
-
- }
-
- protected String translateAuthenticateHeader(AuthenticationException e){
- StringBuilder sb = new StringBuilder();
- sb.append(this.headerValue);
- sb.append("error=\"").append(e.getMessage()).append("\";");
-
- return sb.toString();
- }
-
- static class AuthenticationFailedResponse {
- public final static String STATUS_OK = "OK";
- public final static String STATUS_ERROR = "ERROR";
-
- public final static String OK_MESSAGE = "success";
-
- private String status;
- private String message;
- private Object data;
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public Object getData() {
- return data;
- }
-
- public void setData(Object data) {
- this.data = data;
- }
-
- public AuthenticationFailedResponse withData(Object data){
- this.data = data;
- return this;
- }
-
- public static AuthenticationFailedResponse okay() {
- AuthenticationFailedResponse result = new AuthenticationFailedResponse();
- result.setStatus(STATUS_OK);
- result.setMessage(OK_MESSAGE);
- return result;
- }
-
- public static AuthenticationFailedResponse okayWithData(Object data) {
- return okay().withData(data);
- }
-
- public static AuthenticationFailedResponse error(String errorMessage) {
- AuthenticationFailedResponse result = new AuthenticationFailedResponse();
- result.setStatus(STATUS_ERROR);
- result.setMessage(errorMessage);
- return result;
- }
- }
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtClientConfig.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtClientConfig.java
deleted file mode 100644
index ae4f1e6..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtClientConfig.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.webank.plugins.artifacts.auth.filter;
-
-public class JwtClientConfig {
- private String signingKey;
-
- public String getSigningKey() {
- return signingKey;
- }
-
- public void setSigningKey(String signingKey) {
- this.signingKey = signingKey;
- }
-
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtSsoBasedAuthenticationFilter.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtSsoBasedAuthenticationFilter.java
deleted file mode 100644
index e7c7e15..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtSsoBasedAuthenticationFilter.java
+++ /dev/null
@@ -1,193 +0,0 @@
-package com.webank.plugins.artifacts.auth.filter;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.security.access.AccessDeniedException;
-import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.web.AuthenticationEntryPoint;
-import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
-
-
-import io.jsonwebtoken.Claims;
-import io.jsonwebtoken.ExpiredJwtException;
-import io.jsonwebtoken.Jws;
-import io.jsonwebtoken.JwtException;
-
-public class JwtSsoBasedAuthenticationFilter extends BasicAuthenticationFilter {
- private static final Logger log = LoggerFactory.getLogger(JwtSsoBasedAuthenticationFilter.class);
-
- private static String HEADER_AUTHORIZATION = "Authorization";
- private static String PREFIX_BEARER_TOKEN = "Bearer ";
- private static String CLAIM_KEY_TYPE = "type";
- private static String CLAIM_KEY_AUTHORITIES = "authority";
- private static String TOKEN_TYPE_ACCESS = "accessToken";
-
- private JwtSsoTokenParser jwtParser = null;
-
- private boolean ignoreFailure = false;
-
- public JwtSsoBasedAuthenticationFilter(AuthenticationManager authenticationManager, JwtClientConfig jwtClientConfig) {
- super(authenticationManager);
- this.ignoreFailure = true;
- this.jwtParser = new DefaultJwtSsoTokenParser(jwtClientConfig.getSigningKey());
- }
-
- public JwtSsoBasedAuthenticationFilter(AuthenticationManager authenticationManager,
- AuthenticationEntryPoint authenticationEntryPoint, JwtClientConfig jwtClientConfig) {
- super(authenticationManager, authenticationEntryPoint);
- this.jwtParser = new DefaultJwtSsoTokenParser(jwtClientConfig.getSigningKey());
- }
-
- @Override
- public void afterPropertiesSet() {
- super.afterPropertiesSet();
-
- if (log.isInfoEnabled()) {
- log.info("Filter:{} applied", this.getClass().getSimpleName());
- }
- }
-
- @Override
- protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
- throws IOException, ServletException {
- if (log.isDebugEnabled()) {
- log.debug("=== doFilterInternal ===");
- }
- SecurityContextHolder.clearContext();
-
- String header = request.getHeader(HEADER_AUTHORIZATION);
- if (header == null || !header.startsWith(PREFIX_BEARER_TOKEN)) {
-
- log.debug("bearer token does not exist");
-
- chain.doFilter(request, response);
-
- return;
- }
-
- if (log.isDebugEnabled()) {
- log.debug("start to authenticate with bearer token");
- }
-
- try {
- UsernamePasswordAuthenticationToken authentication = getAuthentication(request);
- if (authentication != null && authentication.isAuthenticated()) {
- SecurityContextHolder.getContext().setAuthentication(authentication);
- }
- } catch (AuthenticationException failed) {
- log.debug("authentication failed");
-
- SecurityContextHolder.clearContext();
-
- onUnsuccessfulAuthentication(request, response, failed);
-
- if (this.ignoreFailure) {
- chain.doFilter(request, response);
- } else {
- this.getAuthenticationEntryPoint().commence(request, response, failed);
- }
-
- return;
-
- }
- executeFilter(request, response, chain);
- }
-
- protected void executeFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
- throws IOException, ServletException {
- try {
- chain.doFilter(request, response);
- } finally {
- SecurityContextHolder.clearContext();
- }
- }
-
- protected boolean isIgnoreFailure() {
- return this.ignoreFailure;
- }
-
- protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response,
- AuthenticationException failed) throws IOException {
- }
-
- protected void validateRequestHeader(HttpServletRequest request) {
- String header = request.getHeader(HEADER_AUTHORIZATION);
- if (header == null || !header.startsWith(PREFIX_BEARER_TOKEN)) {
- throw new BadCredentialsException("Access token is required.");
- }
- }
-
- protected UsernamePasswordAuthenticationToken getAuthentication(HttpServletRequest request) {
- validateRequestHeader(request);
-
- String sAccessTokenHeader = request.getHeader(HEADER_AUTHORIZATION);
-
- String sAccessToken = sAccessTokenHeader.substring(PREFIX_BEARER_TOKEN.length()).trim();
-
- if (StringUtils.isBlank(sAccessToken)) {
- throw new AuthenticationCredentialsNotFoundException("Access token is blank.");
- }
-
- Jws jwt = null;
- try {
- jwt = jwtParser.parseJwt(sAccessToken);
- } catch (ExpiredJwtException e) {
- throw new BadCredentialsException("Access token has expired.");
- } catch (JwtException e) {
- throw new BadCredentialsException("Access token is not available.");
- }
-
- Claims claims = jwt.getBody();
-
- String sAuthorities = claims.get(CLAIM_KEY_AUTHORITIES, String.class);
-
- String username = claims.getSubject();
-
- log.info("subject:{}", username);
-
- String tokenType = claims.get(CLAIM_KEY_TYPE, String.class);
-
- if (!TOKEN_TYPE_ACCESS.equals(tokenType)) {
- throw new AccessDeniedException("Access token is required.");
- }
-
- if (sAuthorities.length() >= 2) {
- sAuthorities = sAuthorities.substring(1);
- sAuthorities = sAuthorities.substring(0, sAuthorities.length() - 1);
- }
-
- log.info("Authority String:{}", sAuthorities);
-
- ArrayList authorities = new ArrayList();
-
- if (StringUtils.isNotBlank(sAuthorities)) {
- String[] aAuthParts = sAuthorities.split(",");
- for (String s : aAuthParts) {
- GrantedAuthority ga = new SimpleGrantedAuthority(s.trim());
- authorities.add(ga);
- }
- }
-
- log.info("Authorities:{}", authorities);
-
- return new UsernamePasswordAuthenticationToken(username, sAccessTokenHeader, authorities);
-
- }
-
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtSsoTokenParser.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtSsoTokenParser.java
deleted file mode 100644
index 0184d62..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/auth/filter/JwtSsoTokenParser.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.webank.plugins.artifacts.auth.filter;
-
-import io.jsonwebtoken.Claims;
-import io.jsonwebtoken.Jws;
-
-public interface JwtSsoTokenParser {
- Jws parseJwt(String token);
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/ApplicationProperties.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/ApplicationProperties.java
deleted file mode 100644
index 67a88f7..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/ApplicationProperties.java
+++ /dev/null
@@ -1,235 +0,0 @@
-package com.webank.plugins.artifacts.commons;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
-
-@Component
-@ConfigurationProperties(prefix = "plugins")
-public class ApplicationProperties {
-
- private String wecubeGatewayServerUrl = "";
- private String artifactsS3ServerUrl = "";
- private String artifactsS3AccessKey = "";
- private String artifactsS3SecretKey = "";
- private String artifactsS3BucketName = "";
- private String artifactsNexusServerUrl = "";
- private String artifactsNexusUsername = "";
- private String artifactsNexusPassword = "";
- private String artifactsNexusRepository = "";
- private String cmdbArtifactPath = "";
- private Map customHeaders = new LinkedHashMap<>();
- private Set sensitiveHeaders = null;
- private String jwtSigningKey = "Platform+Auth+Server+Secret";
- private boolean artifactsLocalEnabled = true;
- private boolean artifactsNexusEnabled = true;
- private String propertyEncryptKeyPath;
-
- public String getPropertyEncryptKeyPath() {
- return propertyEncryptKeyPath;
- }
-
- public void setPropertyEncryptKeyPath(String propertyEncryptKeyPath) {
- this.propertyEncryptKeyPath = propertyEncryptKeyPath;
- }
-
- public String getWecubeGatewayServerUrl() {
- return wecubeGatewayServerUrl;
- }
-
- public void setWecubeGatewayServerUrl(String wecubeGatewayServerUrl) {
- this.wecubeGatewayServerUrl = wecubeGatewayServerUrl;
- }
-
- public String getArtifactsS3ServerUrl() {
- return artifactsS3ServerUrl;
- }
-
- public void setArtifactsS3ServerUrl(String artifactsS3ServerUrl) {
- this.artifactsS3ServerUrl = artifactsS3ServerUrl;
- }
-
- public String getArtifactsS3AccessKey() {
- return artifactsS3AccessKey;
- }
-
- public void setArtifactsS3AccessKey(String artifactsS3AccessKey) {
- this.artifactsS3AccessKey = artifactsS3AccessKey;
- }
-
- public String getArtifactsS3SecretKey() {
- return artifactsS3SecretKey;
- }
-
- public void setArtifactsS3SecretKey(String artifactsS3SecretKey) {
- this.artifactsS3SecretKey = artifactsS3SecretKey;
- }
-
- public String getArtifactsS3BucketName() {
- return artifactsS3BucketName;
- }
-
- public void setArtifactsS3BucketName(String artifactsS3BucketName) {
- this.artifactsS3BucketName = artifactsS3BucketName;
- }
-
- public String getArtifactsNexusServerUrl() {
- return artifactsNexusServerUrl;
- }
-
- public void setArtifactsNexusServerUrl(String artifactsNexusServerUrl) {
- this.artifactsNexusServerUrl = artifactsNexusServerUrl;
- }
-
- public String getArtifactsNexusUsername() {
- return artifactsNexusUsername;
- }
-
- public void setArtifactsNexusUsername(String artifactsNexusUsername) {
- this.artifactsNexusUsername = artifactsNexusUsername;
- }
-
- public String getArtifactsNexusPassword() {
- return artifactsNexusPassword;
- }
-
- public void setArtifactsNexusPassword(String artifactsNexusPassword) {
- this.artifactsNexusPassword = artifactsNexusPassword;
- }
-
- public String getArtifactsNexusRepository() {
- return artifactsNexusRepository;
- }
-
- public void setArtifactsNexusRepository(String artifactsNexusRepository) {
- this.artifactsNexusRepository = artifactsNexusRepository;
- }
-
- public String getCmdbArtifactPath() {
- return cmdbArtifactPath;
- }
-
- public void setCmdbArtifactPath(String cmdbArtifactPath) {
- this.cmdbArtifactPath = cmdbArtifactPath;
- }
-
- public Map getCustomHeaders() {
- return customHeaders;
- }
-
- public void setCustomHeaders(Map customHeaders) {
- this.customHeaders = customHeaders;
- }
-
- public Set getSensitiveHeaders() {
- return sensitiveHeaders;
- }
-
- public void setSensitiveHeaders(Set sensitiveHeaders) {
- this.sensitiveHeaders = sensitiveHeaders;
- }
-
- public String getJwtSigningKey() {
- return jwtSigningKey;
- }
-
- public void setJwtSigningKey(String jwtSigningKey) {
- this.jwtSigningKey = jwtSigningKey;
- }
-
- public boolean isArtifactsLocalEnabled() {
- return artifactsLocalEnabled;
- }
-
- public void setArtifactsLocalEnabled(boolean artifactsLocalEnabled) {
- this.artifactsLocalEnabled = artifactsLocalEnabled;
- }
-
- public boolean isArtifactsNexusEnabled() {
- return artifactsNexusEnabled;
- }
-
- public void setArtifactsNexusEnabled(boolean artifactsNexusEnabled) {
- this.artifactsNexusEnabled = artifactsNexusEnabled;
- }
-
- @ConfigurationProperties(prefix = "plugins")
- public class CmdbDataProperties {
- private Integer enumCategoryTypeSystem = 1;
- private Integer ciTypeIdOfSystemDesign = 37;
- private Integer ciTypeIdOfUnitDesign = 39;
- private Integer ciTypeIdOfPackage = 45;
- private String enumCategoryNameOfDiffConf = "diff_conf";
- private String propertyNameOfFixedDate = "fixed_date";
- private String enumCodeChangeOfCiStateOfCreate = "update";
- private String enumCodeDestroyedOfCiStateOfCreate = "delete";
-
- public Integer getEnumCategoryTypeSystem() {
- return enumCategoryTypeSystem;
- }
-
- public void setEnumCategoryTypeSystem(Integer enumCategoryTypeSystem) {
- this.enumCategoryTypeSystem = enumCategoryTypeSystem;
- }
-
- public Integer getCiTypeIdOfSystemDesign() {
- return ciTypeIdOfSystemDesign;
- }
-
- public void setCiTypeIdOfSystemDesign(Integer ciTypeIdOfSystemDesign) {
- this.ciTypeIdOfSystemDesign = ciTypeIdOfSystemDesign;
- }
-
- public Integer getCiTypeIdOfUnitDesign() {
- return ciTypeIdOfUnitDesign;
- }
-
- public void setCiTypeIdOfUnitDesign(Integer ciTypeIdOfUnitDesign) {
- this.ciTypeIdOfUnitDesign = ciTypeIdOfUnitDesign;
- }
-
- public Integer getCiTypeIdOfPackage() {
- return ciTypeIdOfPackage;
- }
-
- public void setCiTypeIdOfPackage(Integer ciTypeIdOfPackage) {
- this.ciTypeIdOfPackage = ciTypeIdOfPackage;
- }
-
- public String getEnumCategoryNameOfDiffConf() {
- return enumCategoryNameOfDiffConf;
- }
-
- public void setEnumCategoryNameOfDiffConf(String enumCategoryNameOfDiffConf) {
- this.enumCategoryNameOfDiffConf = enumCategoryNameOfDiffConf;
- }
-
- public String getPropertyNameOfFixedDate() {
- return propertyNameOfFixedDate;
- }
-
- public void setPropertyNameOfFixedDate(String propertyNameOfFixedDate) {
- this.propertyNameOfFixedDate = propertyNameOfFixedDate;
- }
-
- public String getEnumCodeChangeOfCiStateOfCreate() {
- return enumCodeChangeOfCiStateOfCreate;
- }
-
- public void setEnumCodeChangeOfCiStateOfCreate(String enumCodeChangeOfCiStateOfCreate) {
- this.enumCodeChangeOfCiStateOfCreate = enumCodeChangeOfCiStateOfCreate;
- }
-
- public String getEnumCodeDestroyedOfCiStateOfCreate() {
- return enumCodeDestroyedOfCiStateOfCreate;
- }
-
- public void setEnumCodeDestroyedOfCiStateOfCreate(String enumCodeDestroyedOfCiStateOfCreate) {
- this.enumCodeDestroyedOfCiStateOfCreate = enumCodeDestroyedOfCiStateOfCreate;
- }
-
- }
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/HttpClientProperties.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/HttpClientProperties.java
deleted file mode 100644
index 858528c..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/HttpClientProperties.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.webank.plugins.artifacts.commons;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties(prefix = "plugins.httpclient")
-public class HttpClientProperties {
- private int connectTimeout = 30000;
- private int requestTimeout = 30000;
- private int socketTimeout = 1200000;
- private int maxTotalConnections = 50;
- private int poolSizeOfScheduler = 50;
- private int defaultKeepAliveTimeMillis = 1200000;
- private int closeIdleConnectionWaitTimeSecs = 30;
-
- public int getConnectTimeout() {
- return connectTimeout;
- }
-
- public void setConnectTimeout(int connectTimeout) {
- this.connectTimeout = connectTimeout;
- }
-
- public int getRequestTimeout() {
- return requestTimeout;
- }
-
- public void setRequestTimeout(int requestTimeout) {
- this.requestTimeout = requestTimeout;
- }
-
- public int getSocketTimeout() {
- return socketTimeout;
- }
-
- public void setSocketTimeout(int socketTimeout) {
- this.socketTimeout = socketTimeout;
- }
-
- public int getMaxTotalConnections() {
- return maxTotalConnections;
- }
-
- public void setMaxTotalConnections(int maxTotalConnections) {
- this.maxTotalConnections = maxTotalConnections;
- }
-
- public int getPoolSizeOfScheduler() {
- return poolSizeOfScheduler;
- }
-
- public void setPoolSizeOfScheduler(int poolSizeOfScheduler) {
- this.poolSizeOfScheduler = poolSizeOfScheduler;
- }
-
- public int getDefaultKeepAliveTimeMillis() {
- return defaultKeepAliveTimeMillis;
- }
-
- public void setDefaultKeepAliveTimeMillis(int defaultKeepAliveTimeMillis) {
- this.defaultKeepAliveTimeMillis = defaultKeepAliveTimeMillis;
- }
-
- public int getCloseIdleConnectionWaitTimeSecs() {
- return closeIdleConnectionWaitTimeSecs;
- }
-
- public void setCloseIdleConnectionWaitTimeSecs(int closeIdleConnectionWaitTimeSecs) {
- this.closeIdleConnectionWaitTimeSecs = closeIdleConnectionWaitTimeSecs;
- }
-
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/PluginException.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/PluginException.java
deleted file mode 100644
index cf896d6..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/commons/PluginException.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package com.webank.plugins.artifacts.commons;
-
-public class PluginException extends RuntimeException {
- private static final long serialVersionUID = 1L;
-
- private String errorCode;
- private String messageKey;
- private boolean applyMessage = false;
- private Object[] args;
-
- public PluginException(String message) {
- super(message);
- this.applyMessage = true;
- }
-
- public PluginException(String message, Throwable cause) {
- super(message, cause);
- this.applyMessage = true;
- }
-
- public PluginException(String errorCode, String message, Object... objects) {
- this(errorCode, null, message, null, false, objects);
- }
-
- private PluginException(String errorCode, String messageKey, String message, Throwable cause,
- boolean applyMessage, Object... objects) {
- super(message, cause);
- this.errorCode = errorCode;
- this.messageKey = messageKey;
- if (objects != null && (this.args == null)) {
- this.args = new Object[objects.length];
- int index = 0;
- for (Object object : objects) {
- this.args[index] = object;
- index++;
- }
- }
- this.applyMessage = applyMessage;
- }
-
- public PluginException withErrorCode(String errorCode) {
- this.errorCode = errorCode;
- return this;
- }
-
- public PluginException withErrorCode(String errorCode, Object... objects) {
- this.errorCode = errorCode;
- if (objects != null && (this.args == null)) {
- this.args = new Object[objects.length];
- int index = 0;
- for (Object object : objects) {
- this.args[index] = object;
- index++;
- }
- }
- return this;
- }
-
- public PluginException withErrorCodeAndArgs(String errorCode, Object[] objects) {
- this.errorCode = errorCode;
- if (objects != null && (this.args == null)) {
- this.args = new Object[objects.length];
- int index = 0;
- for (Object object : objects) {
- this.args[index] = object;
- index++;
- }
- }
- return this;
- }
-
- public PluginException withMessageKey(String msgKey) {
- this.messageKey = msgKey;
- return this;
- }
-
- public PluginException withMessageKey(String msgKey, Object... objects) {
- this.messageKey = msgKey;
- if (objects != null && (this.args == null)) {
- this.args = new Object[objects.length];
- int index = 0;
- for (Object object : objects) {
- this.args[index] = object;
- index++;
- }
- }
-
- return this;
- }
-
- public String getErrorCode() {
- return errorCode;
- }
-
- public String getMessageKey() {
- return messageKey;
- }
-
- public boolean isApplyMessage() {
- return applyMessage;
- }
-
- public Object[] getArgs() {
- return args;
- }
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/HttpClientConfig.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/HttpClientConfig.java
deleted file mode 100644
index 0168cf3..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/HttpClientConfig.java
+++ /dev/null
@@ -1,212 +0,0 @@
-package com.webank.plugins.artifacts.config;
-
-import java.io.IOException;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.util.Collections;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.http.HeaderElement;
-import org.apache.http.HeaderElementIterator;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.config.Registry;
-import org.apache.http.config.RegistryBuilder;
-import org.apache.http.conn.ConnectionKeepAliveStrategy;
-import org.apache.http.conn.socket.ConnectionSocketFactory;
-import org.apache.http.conn.socket.PlainConnectionSocketFactory;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.message.BasicHeaderElementIterator;
-import org.apache.http.protocol.HTTP;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.ssl.SSLContextBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.web.client.RestTemplateBuilder;
-import org.springframework.boot.web.client.RestTemplateCustomizer;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-import org.springframework.http.HttpRequest;
-import org.springframework.http.client.ClientHttpRequestExecution;
-import org.springframework.http.client.ClientHttpRequestInterceptor;
-import org.springframework.http.client.ClientHttpResponse;
-import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.scheduling.TaskScheduler;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
-import org.springframework.web.client.RestTemplate;
-
-import com.webank.plugins.artifacts.commons.HttpClientProperties;
-import com.webank.plugins.artifacts.interceptor.RestTemplateInterceptor;
-
-@Configuration
-@EnableScheduling
-public class HttpClientConfig {
-
- private static final Logger log = LoggerFactory.getLogger(HttpClientConfig.class);
-
- @Autowired
- private HttpClientProperties httpClientProperties;
-
- @Autowired
- private RestTemplateInterceptor restTemplateInterceptor;
-
- @Bean
- public PoolingHttpClientConnectionManager poolingConnectionManager() {
- SSLContextBuilder builder = new SSLContextBuilder();
- try {
- builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
- } catch (NoSuchAlgorithmException | KeyStoreException e) {
- log.error("Pooling Connection Manager Initialisation failure because of " + e.getMessage(), e);
- }
-
- SSLConnectionSocketFactory sslsf = null;
- try {
- sslsf = new SSLConnectionSocketFactory(builder.build());
- } catch (KeyManagementException | NoSuchAlgorithmException e) {
- log.error("Pooling Connection Manager Initialisation failure because of " + e.getMessage(), e);
- }
-
- Registry socketFactoryRegistry = RegistryBuilder
- .create()
- .register("https", sslsf)
- .register("http", new PlainConnectionSocketFactory())
- .build();
-
- PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
- poolingConnectionManager.setMaxTotal(httpClientProperties.getMaxTotalConnections());
- return poolingConnectionManager;
- }
-
- @Bean
- public ConnectionKeepAliveStrategy connectionKeepAliveStrategy() {
- return new ConnectionKeepAliveStrategy() {
- @Override
- public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
- HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
- while (it.hasNext()) {
- HeaderElement he = it.nextElement();
- String param = he.getName();
- String value = he.getValue();
-
- if (value != null && param.equalsIgnoreCase("timeout")) {
- return Long.parseLong(value) * 1000;
- }
- }
- return httpClientProperties.getDefaultKeepAliveTimeMillis();
- }
- };
- }
-
- @Bean
- public CloseableHttpClient httpClient() {
- RequestConfig requestConfig = RequestConfig.custom()
- .setConnectionRequestTimeout(httpClientProperties.getRequestTimeout())
- .setConnectTimeout(httpClientProperties.getConnectTimeout())
- .setSocketTimeout(httpClientProperties.getSocketTimeout())
- .build();
-
- return HttpClients.custom()
- .setDefaultRequestConfig(requestConfig)
- .setConnectionManager(poolingConnectionManager())
- .setKeepAliveStrategy(connectionKeepAliveStrategy())
- .build();
- }
-
- @Bean
- public Runnable idleConnectionMonitor(final PoolingHttpClientConnectionManager connectionManager) {
- return new Runnable() {
- @Override
- @Scheduled(fixedDelay = 10000)
- public void run() {
- try {
- if (connectionManager != null) {
- log.trace("run IdleConnectionMonitor - Closing expired and idle connections...");
- connectionManager.closeExpiredConnections();
- connectionManager.closeIdleConnections(httpClientProperties.getCloseIdleConnectionWaitTimeSecs(), TimeUnit.SECONDS);
- } else {
- log.trace("run IdleConnectionMonitor - Http Client Connection manager is not initialised");
- }
- } catch (Exception e) {
- log.error("run IdleConnectionMonitor - Exception occurred. msg={}, e={}", e.getMessage(), e);
- }
- }
- };
- }
-
- @Bean
- public HttpComponentsClientHttpRequestFactory clientHttpRequestFactory() {
- HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory();
- clientHttpRequestFactory.setHttpClient(httpClient());
- return clientHttpRequestFactory;
- }
-
- @Bean
- public TaskScheduler taskScheduler() {
- ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
- scheduler.setThreadNamePrefix("poolScheduler");
- scheduler.setPoolSize(httpClientProperties.getPoolSizeOfScheduler());
- return scheduler;
- }
-
- @Bean("userRestTemplate")
- @Primary
- public RestTemplate userRestTemplate() {
- RestTemplate template = restTemplateBuilder().build();
- template.setInterceptors(Collections.singletonList(restTemplateInterceptor));
- return template;
- }
-
- @Bean("simpleRestTemplate")
- public RestTemplate simpleRestTemplate() {
- RestTemplate template = restTemplateBuilder().build();
- return template;
- }
-
- @Bean
- public RestTemplateBuilder restTemplateBuilder() {
- return new RestTemplateBuilder(customRestTemplateCustomizer());
- }
-
- @Bean
- public CustomRestTemplateCustomizer customRestTemplateCustomizer() {
- return new CustomRestTemplateCustomizer();
- }
-
- private class CustomRestTemplateCustomizer implements RestTemplateCustomizer {
- @Override
- public void customize(RestTemplate restTemplate) {
- restTemplate.setRequestFactory(clientHttpRequestFactory());
- restTemplate.getInterceptors().add(new CustomClientHttpRequestInterceptor());
- }
- }
-
- private class CustomClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
-
- @Override
- public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
- logRequestDetails(request);
- ClientHttpResponse response = execution.execute(request, body);
- logResponseDetails(response);
- return response;
- }
-
- private void logRequestDetails(HttpRequest request) {
- log.debug("Request Headers: {}", request.getHeaders());
- log.debug("Request Method: {}", request.getMethod());
- log.debug("Request URI: {}", request.getURI());
- }
-
- private void logResponseDetails(ClientHttpResponse response) {
- log.debug("Response Headers: {}", response.getHeaders());
- }
- }
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/SpringAppConfig.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/SpringAppConfig.java
deleted file mode 100644
index 3dc6fc2..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/SpringAppConfig.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.webank.plugins.artifacts.config;
-
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-import com.webank.plugins.artifacts.commons.ApplicationProperties.CmdbDataProperties;
-import com.webank.plugins.artifacts.commons.HttpClientProperties;
-
-@Configuration
-@EnableConfigurationProperties({ CmdbDataProperties.class, HttpClientProperties.class})
-public class SpringAppConfig {
-
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/SpringWebConfig.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/SpringWebConfig.java
deleted file mode 100644
index f11cc8d..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/config/SpringWebConfig.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.webank.plugins.artifacts.config;
-
-import javax.servlet.Filter;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.web.servlet.config.annotation.EnableWebMvc;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
-import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
-import com.webank.plugins.artifacts.auth.filter.Http401AuthenticationEntryPoint;
-import com.webank.plugins.artifacts.auth.filter.JwtClientConfig;
-import com.webank.plugins.artifacts.auth.filter.JwtSsoBasedAuthenticationFilter;
-import com.webank.plugins.artifacts.commons.ApplicationProperties;
-import com.webank.plugins.artifacts.interceptor.ApiAccessInterceptor;
-
-@Configuration
-@EnableWebMvc
-@EnableWebSecurity
-@EnableGlobalMethodSecurity(jsr250Enabled = true, prePostEnabled = true, securedEnabled = true)
-@EnableEncryptableProperties
-@ComponentScan({ "com.webank.plugins.artifacts.controller" })
-public class SpringWebConfig extends WebSecurityConfigurerAdapter implements WebMvcConfigurer {
-
- @Autowired
- private ApiAccessInterceptor apiAccessInterceptor;
-
- @Autowired
- private ApplicationProperties applicationProperties;
-
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(apiAccessInterceptor).addPathPatterns("/**");
- WebMvcConfigurer.super.addInterceptors(registry);
- }
-
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
- registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
- }
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- configureLocalAuthentication(http);
-
- }
-
- protected void configureLocalAuthentication(HttpSecurity http) throws Exception {
- http.authorizeRequests() //
- .antMatchers("/swagger-ui.html/**", "/swagger-resources/**").permitAll()//
- .antMatchers("/webjars/**").permitAll() //
- .antMatchers("/v2/api-docs").permitAll() //
- .antMatchers("/csrf").permitAll() //
- .anyRequest().authenticated() //
- .and()//
- .addFilter(jwtSsoBasedAuthenticationFilter())//
- .csrf()//
- .disable() //
- .exceptionHandling() //
- .authenticationEntryPoint(new Http401AuthenticationEntryPoint()); //
- }
-
- protected Filter jwtSsoBasedAuthenticationFilter() throws Exception {
- JwtClientConfig jwtClientConfig = new JwtClientConfig();
- jwtClientConfig.setSigningKey(applicationProperties.getJwtSigningKey());
- JwtSsoBasedAuthenticationFilter f = new JwtSsoBasedAuthenticationFilter(authenticationManager(),
- jwtClientConfig);
- return (Filter) f;
- }
-
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/constant/ArtifactsConstants.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/constant/ArtifactsConstants.java
deleted file mode 100644
index 65cfc19..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/constant/ArtifactsConstants.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.webank.plugins.artifacts.constant;
-
-public class ArtifactsConstants {
- public static final String UPLOAD_NAME = "upload_name";
-
- public static final String KEY_OF_TOKEN = "Authorization";
-
- public static String PREFIX_BEARER_TOKEN = "Bearer ";
- public static final String SIGNING_KEY = "Platform+Auth+Server+Secret";
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/controller/ArtifactManagementController.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/controller/ArtifactManagementController.java
deleted file mode 100644
index 54f3af5..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/controller/ArtifactManagementController.java
+++ /dev/null
@@ -1,218 +0,0 @@
-package com.webank.plugins.artifacts.controller;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static com.webank.plugins.artifacts.dto.JsonResponse.okay;
-import static com.webank.plugins.artifacts.dto.JsonResponse.okayWithData;
-import static com.webank.plugins.artifacts.support.cmdb.dto.v2.PaginationQuery.defaultQueryObject;
-import static com.webank.plugins.artifacts.utils.BooleanUtils.isTrue;
-import static org.apache.commons.lang3.StringUtils.isNotEmpty;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
-import com.webank.plugins.artifacts.commons.ApplicationProperties;
-import com.webank.plugins.artifacts.commons.ApplicationProperties.CmdbDataProperties;
-import com.webank.plugins.artifacts.commons.PluginException;
-import com.webank.plugins.artifacts.constant.ArtifactsConstants;
-import com.webank.plugins.artifacts.dto.AutoCreateDeployPackageDto;
-import com.webank.plugins.artifacts.dto.AutoCreateDeployPackageResultDto;
-import com.webank.plugins.artifacts.dto.JsonResponse;
-import com.webank.plugins.artifacts.service.ArtifactService;
-import com.webank.plugins.artifacts.service.NexusArtifactManagementService;
-import com.webank.plugins.artifacts.support.cmdb.CmdbServiceV2Stub;
-import com.webank.plugins.artifacts.support.cmdb.dto.v2.CatCodeDto;
-import com.webank.plugins.artifacts.support.cmdb.dto.v2.OperateCiDto;
-import com.webank.plugins.artifacts.support.cmdb.dto.v2.PaginationQuery;
-
-@RestController
-public class ArtifactManagementController {
-
- private static final Logger logger = LoggerFactory.getLogger(ArtifactManagementController.class);
- @Autowired
- private CmdbDataProperties cmdbDataProperties;
-
- @Autowired
- private CmdbServiceV2Stub cmdbServiceV2Stub;
-
- @Autowired
- private ArtifactService artifactService;
-
- @Autowired
- private NexusArtifactManagementService nexusArtifactManagementService;
-
- @Autowired
- private ApplicationProperties applicationProperties;
-
- @GetMapping("/system-design-versions")
- public JsonResponse getSystemDesignVersions() {
- return okayWithData(artifactService.getSystemDesignVersions());
- }
-
- @GetMapping("/system-design-versions/{system-design-id}")
- public JsonResponse getSystemDesignVersion(@PathVariable(value = "system-design-id") String systemDesignId) {
- return okayWithData(artifactService.getArtifactSystemDesignTree(systemDesignId));
-
- }
-
- @PostMapping("/unit-designs/{unit-design-id}/packages/upload")
- public JsonResponse uploadPackage(@PathVariable(value = "unit-design-id") String unitDesignId,
- @RequestParam(value = "file", required = false) MultipartFile multipartFile, HttpServletRequest request) {
- if(!applicationProperties.isArtifactsLocalEnabled()) {
- throw new PluginException("Package uploading is disabled!").withErrorCode("3010");
- }
- File file = convertMultiPartToFile(multipartFile);
- String url = artifactService.uploadPackageToS3(file);
- return okayWithData(artifactService.savePackageToCmdb(file, unitDesignId,
- (String) request.getAttribute(ArtifactsConstants.UPLOAD_NAME), url, null));
-
- }
-
- @PostMapping("/packages/auto-create-deploy-package")
- public JsonResponse autoCreateDeployPackage(@RequestBody AutoCreateDeployPackageDto autoCreateDeployPackageDto, HttpServletRequest request) {
- String uploadName = (String) request.getAttribute(ArtifactsConstants.UPLOAD_NAME);
- AutoCreateDeployPackageResultDto result = nexusArtifactManagementService.autoCreateDeployPackage(autoCreateDeployPackageDto, uploadName);
- return okayWithData(result);
- }
-
- @PostMapping("/unit-designs/{unit-design-id}/packages/queryNexusDirectiry")
- public JsonResponse queryNexusPackages(@PathVariable(value = "unit-design-id") String unitDesignId,
- @RequestBody PaginationQuery queryObject) {
- if(!applicationProperties.isArtifactsNexusEnabled()) {
- throw new PluginException("Package uploading is disabled!").withErrorCode("3010");
- }
- return okayWithData(nexusArtifactManagementService.queryNexusDirectory(unitDesignId, queryObject));
- }
-
- @PostMapping("/unit-designs/{unit-design-id}/packages/uploadNexusPackage")
- public JsonResponse uploadNexusPackage(@PathVariable(value = "unit-design-id") String unitDesignId,
- @RequestParam(value = "downloadUrl", required = false) String downloadUrl, HttpServletRequest request) {
- if(!applicationProperties.isArtifactsNexusEnabled()) {
- throw new PluginException("Package uploading is disabled!").withErrorCode("3010");
- }
- nexusArtifactManagementService.asyncUploadNexusPackageToS3(unitDesignId, downloadUrl,
- (String) request.getAttribute(ArtifactsConstants.UPLOAD_NAME));
- return okay();
- }
-
- @PostMapping("/unit-designs/{unit-design-id}/packages/{package-id}/deactive")
- public JsonResponse deactivePackage(@PathVariable(value = "package-id") String packageId) {
- artifactService.deactive(packageId);
- return okay();
- }
-
- @PostMapping("/unit-designs/{unit-design-id}/packages/{package-id}/active")
- public JsonResponse activePackage(@PathVariable(value = "package-id") String packageId) {
- artifactService.active(packageId);
- return okay();
- }
-
- @PostMapping("/unit-designs/{unit-design-id}/packages/{package-id}/property-keys/query")
- public JsonResponse getKeys(@PathVariable(value = "package-id") String packageId,
- @RequestBody Map additionalProperties) {
- if (additionalProperties.get("filePath") == null) {
- throw new PluginException("3001", "Field 'filePath' is required.");
- }
- return okayWithData(artifactService.getPropertyKeys(packageId, additionalProperties.get("filePath")));
- }
-
- @PostMapping("/enum/codes/diff-config/save")
- public JsonResponse saveDiffConfigEnumCodes(@RequestBody CatCodeDto code) {
- artifactService.saveDiffConfigEnumCodes(code);
- return okay();
- }
-
- @GetMapping("/enum/codes/diff-config/query")
- public JsonResponse getDiffConfigEnumCodes() {
- return okayWithData(artifactService.getDiffConfigEnumCodes());
- }
-
- @GetMapping("/getPackageCiTypeId")
- public JsonResponse getPackageCiTypeId() {
- return okayWithData(cmdbDataProperties.getCiTypeIdOfPackage());
- }
-
- @PostMapping("/ci/state/operate")
- public JsonResponse operateCiForState(@RequestBody List ciIds,
- @RequestParam("operation") String operation) {
- return okayWithData(artifactService.operateState(ciIds, operation));
- }
-
- @GetMapping("/ci-types")
- public JsonResponse getCiTypes(@RequestParam(name = "group-by", required = false) String groupBy,
- @RequestParam(name = "with-attributes", required = false) String withAttributes,
- @RequestParam(name = "status", required = false) String status) {
- return okayWithData(artifactService.getCiTypes(isTrue(withAttributes), status));
- }
-
- @PostMapping("/ci-types/{ci-type-id}/ci-data/batch-delete")
- public JsonResponse deleteCiData(@PathVariable(value = "ci-type-id") int ciTypeId,
- @RequestBody List ciDataIds) {
- artifactService.deleteCiData(ciTypeId, ciDataIds);
- return okay();
- }
-
- @PostMapping("/enum/system/codes")
- public JsonResponse querySystemEnumCodesWithRefResources(@RequestBody PaginationQuery queryObject) {
- return okayWithData(artifactService.querySystemEnumCodesWithRefResources(queryObject));
- }
-
- @GetMapping("/ci-types/{ci-type-id}/references/by")
- public JsonResponse getCiTypeReferenceBy(@PathVariable(value = "ci-type-id") int ciTypeId) {
- return okayWithData(artifactService.getCiTypeReferenceBy(ciTypeId));
- }
-
- @GetMapping("/ci-types/{ci-type-id}/attributes")
- public JsonResponse getCiTypeAttributes(@PathVariable(value = "ci-type-id") int ciTypeId,
- @RequestParam(name = "accept-input-types", required = false) String acceptInputTypes) {
- if (isNotEmpty(acceptInputTypes)) {
- return okayWithData(cmdbServiceV2Stub.queryCiTypeAttributes(defaultQueryObject("ciTypeId", ciTypeId)
- .addInFilter("inputType", newArrayList(acceptInputTypes.split(",")))));
- } else {
- return okayWithData(cmdbServiceV2Stub.getCiTypeAttributesByCiTypeId(ciTypeId));
- }
- }
-
- @GetMapping("/static-data/special-connector")
- public JsonResponse getSpecialConnector() {
- return okayWithData(artifactService.getSpecialConnector());
- }
-
- private File convertMultiPartToFile(MultipartFile multipartFile) {
- if (multipartFile == null) {
- return null;
- }
-
- File file = new File(multipartFile.getOriginalFilename());
- try (FileOutputStream fos = new FileOutputStream(file)) {
- byte[] buf = new byte[1024];
- int len = 0;
-
- InputStream is = multipartFile.getInputStream();
- while ((len = is.read(buf)) != -1) {
- fos.write(buf, 0, len);
- }
-
- // fos.write(multipartFile.getBytes());
- } catch (Exception e) {
- logger.error("errors while convert multipart file.", e);
- throw new PluginException("3002", "Failed to convert multipart file to file.");
- }
- return file;
- }
-}
diff --git a/artifacts-core/src/main/java/com/webank/plugins/artifacts/controller/PackageConfigManagementController.java b/artifacts-core/src/main/java/com/webank/plugins/artifacts/controller/PackageConfigManagementController.java
deleted file mode 100644
index 0b25a82..0000000
--- a/artifacts-core/src/main/java/com/webank/plugins/artifacts/controller/PackageConfigManagementController.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.webank.plugins.artifacts.controller;
-
-import static com.webank.plugins.artifacts.dto.JsonResponse.okay;
-import static com.webank.plugins.artifacts.dto.JsonResponse.okayWithData;
-
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
-
-import com.webank.plugins.artifacts.dto.DiffConfigurationUpdateDto;
-import com.webank.plugins.artifacts.dto.FileQueryRequestDto;
-import com.webank.plugins.artifacts.dto.FileQueryResultItemDto;
-import com.webank.plugins.artifacts.dto.JsonResponse;
-import com.webank.plugins.artifacts.dto.PackageComparisionRequestDto;
-import com.webank.plugins.artifacts.dto.PackageComparisionResultDto;
-import com.webank.plugins.artifacts.dto.PackageConfigFilesUpdateRequestDto;
-import com.webank.plugins.artifacts.dto.SinglePackageQueryResultDto;
-import com.webank.plugins.artifacts.service.ConfigFileManagementService;
-import com.webank.plugins.artifacts.support.cmdb.dto.v2.PaginationQuery;
-import com.webank.plugins.artifacts.support.cmdb.dto.v2.PaginationQueryResult;
-
-@RestController
-public class PackageConfigManagementController {
-
- @Autowired
- private ConfigFileManagementService configFileManagementService;
-
- @PostMapping("/artifacts/packages/wecmdb/entities/diff_configuration/update")
- public JsonResponse updateDiffConfiguration(List updateRequestDto) {
- configFileManagementService.updateDiffConfigurations(updateRequestDto);
- return okay();
- }
-
- @PostMapping("/unit-designs/{unit-design-id}/packages/{package-id}/files/query")
- public JsonResponse queryPackageFiles(@PathVariable(value = "package-id") String packageId,
- @RequestBody FileQueryRequestDto fileQueryRequestDto) {
- List results = configFileManagementService.queryDeployConfigFiles(packageId,
- fileQueryRequestDto);
- return okayWithData(results);
- }
-
- @PostMapping("/unit-designs/{unit-design-id}/packages/query")
- public JsonResponse queryPackages(@PathVariable(value = "unit-design-id") String unitDesignId,
- @RequestBody PaginationQuery queryObject) {
- PaginationQueryResult