Commit 76adda57 authored by Cheremnov Dmitriy's avatar Cheremnov Dmitriy
Browse files

Merge branch 'master' into 'master'

From pro-sd/pro-sd-ump:master into public-group/pro-sd-ump:master

See merge request !4
parents 8be304a9 8c7e0678
Pipeline #106 failed with stages
in 1 second
This diff is collapsed.
......@@ -40,6 +40,7 @@
<module>ump-config</module>
<module>ump-registry</module>
<module>ump-mattermostio</module>
<module>ump-gitlabio</module>
<module>ump-logstash</module>
<module>ump-elasticsearch</module>
<module>ump-kibana</module>
......
/*
UMP (Unified Modular Platform)
Copyright (C) 2019 Dmitry Cheremnov (d.cheremnov@asvoip.com)
See LICENSE for license information.
*/
package com.asvoip.ump.bootadminserver;
import org.springframework.boot.SpringApplication;
......
......@@ -20,8 +20,19 @@
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
<sonar-maven-plugin.version>3.7.0.1746</sonar-maven-plugin.version>
<lombok.version>1.18.10</lombok.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
......
package com.asvoip.ump.commonmodule.dto;
public class ApplicationId extends Id<String> {
}
package com.asvoip.ump.commonmodule.dto;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@RequiredArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Channel extends ChannelId {
private ChannelType type;
private String code;
private String name;
private String group;
private String user;
}
package com.asvoip.ump.commonmodule.dto;
public class ChannelId extends Id<String> {
}
package com.asvoip.ump.commonmodule.dto;
public enum ChannelType {
GITLAB,
MATTERMOST
}
package com.asvoip.ump.commonmodule.dto;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@RequiredArgsConstructor
@ToString
public class Envelope<T> {
private Session session;
private T data;
}
package com.asvoip.ump.commonmodule.dto;
import java.io.Serializable;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@RequiredArgsConstructor
@ToString
@EqualsAndHashCode
public class Id<I extends Serializable> implements Identifier<I> {
private I id;
}
\ No newline at end of file
/*
UMP (Unified Modular Platform)
Copyright (C) 2019 Dmitry Cheremnov (d.cheremnov@asvoip.com)
See LICENSE for license information.
*/
package com.asvoip.ump.commonmodule.dto;
import java.io.Serializable;
public interface Identifier<ID extends Serializable> extends Serializable {
public interface Identifier<I extends Serializable> extends Serializable {
ID getId();
I getId();
void setId(ID id);
void setId(I id);
}
package com.asvoip.ump.commonmodule.dto;
import java.io.Serializable;
public class IdentifierDTO<ID extends Serializable> implements Identifier<ID> {
private ID id;
public IdentifierDTO() {
}
public IdentifierDTO(ID id) {
this.id = id;
}
public ID getId() {
return id;
}
public void setId(ID id) {
this.id = id;
}
}
\ No newline at end of file
package com.asvoip.ump.commonmodule.dto;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@RequiredArgsConstructor
@ToString(callSuper = true)
public class Session extends Id<String> {
TenantId tenantId;
ApplicationId applicationId;
Channel channel;
UserId userId;
Long timestamp;
}
package com.asvoip.ump.commonmodule.dto;
public class TenantId extends Id<String> {
}
package com.asvoip.ump.commonmodule.dto;
public class UserId extends Id<String> {
}
/*
UMP (Unified Modular Platform)
Copyright (C) 2019 Dmitry Cheremnov (d.cheremnov@asvoip.com)
See LICENSE for license information.
*/
package com.asvoip.ump.component;
import org.slf4j.Logger;
......
/*
UMP (Unified Modular Platform)
Copyright (C) 2019 Dmitry Cheremnov (d.cheremnov@asvoip.com)
See LICENSE for license information.
*/
package com.asvoip.ump.config;
import org.springframework.boot.SpringApplication;
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>ump-gitlabio</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<name>UMP GitLab IO</name>
<description>UMP GitLab IO</description>
<parent>
<groupId>com.asvoip.ump</groupId>
<artifactId>ump</artifactId>
<version>0.1.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<java.version>1.8</java.version>
<lombok.version>1.18.8</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>com.asvoip.ump</groupId>
<artifactId>ump-commonmodule</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot-starter-test.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gitlab4j</groupId>
<artifactId>gitlab4j-api</artifactId>
<version>4.14.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
/*
UMP (Unified Modular Platform)
Copyright (C) 2019 Dmitry Cheremnov (d.cheremnov@asvoip.com)
See LICENSE for license information.
*/
package com.asvoip.ump.gitlabio;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
/**
* Main class - GitlabIOApplication.
*/
@SpringBootApplication
public class GitlabIOApplication {
private static final Logger log = LoggerFactory.getLogger(GitlabIOApplication.class);
public static void main(String[] args) {
final ApplicationContext context = SpringApplication.run(GitlabIOApplication.class, args);
log.info("Starting up, ApplicationName: {}", context.getApplicationName());
}
}
package com.asvoip.ump.gitlabio.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@RestController
@RequestMapping(value = GitlabIOController.URL_V1_GITLABIO)
@RequiredArgsConstructor
@Slf4j
public class GitlabIOController {
static final String URL_V1_GITLABIO = "/api/v1/gitlabio";
private static final String HEADER_X_GITLAB_EVENT = "X-Gitlab-Event";
private static final String HEADER_X_GITLAB_TOKEN = "X-Gitlab-Token";
private static final String VARIABLE_PATH_PROJECT_ID = "projectId";
private static final String URL_SYSTEM_HOOK = "/systemhook";
private static final String URL_WEB_HOOK = "/webhook/{" + VARIABLE_PATH_PROJECT_ID + "}";
private static final String LS = System.lineSeparator();
@Value("${gitlab.system-hook.token}")
private String systemHookToken;
@Value("${gitlab.web-hook.token}")
private String webHookToken;
@PostMapping(value = URL_SYSTEM_HOOK + "debug", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<String> systemhook(
@RequestHeader(HEADER_X_GITLAB_EVENT) String gitlabEvent,
@RequestHeader(HEADER_X_GITLAB_TOKEN) String gitlabToken,
@RequestBody Map<String, Object> attributes) {
boolean check = systemHookToken.equals(gitlabToken);
StringBuffer sb = new StringBuffer("systemhook POST ")
.append(HEADER_X_GITLAB_EVENT).append(": ").append(gitlabEvent)
.append("; check: ").append(check)
.append("; attributes:").append(LS);
attributes.forEach((key, value) -> sb.append("key: ").append(key)
.append("; value: ").append(value)
.append("; class: ").append(value.getClass().getSimpleName())
.append(LS));
log.info(sb.toString());
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping(value = URL_SYSTEM_HOOK, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<String> systemhook(
@RequestHeader(HEADER_X_GITLAB_EVENT) String gitlabEvent,
@RequestHeader(HEADER_X_GITLAB_TOKEN) String gitlabToken,
@RequestBody String json) {
boolean check = systemHookToken.equals(gitlabToken);
log.info("systemhook POST {}: {}; check: {}, json: {}", HEADER_X_GITLAB_EVENT, gitlabEvent, check, json);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping(value = URL_WEB_HOOK, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<String> webhook(
@RequestHeader(HEADER_X_GITLAB_EVENT) String gitlabEvent,
@RequestHeader(HEADER_X_GITLAB_TOKEN) String gitlabToken,
@PathVariable(VARIABLE_PATH_PROJECT_ID) Long projectId,
@RequestBody String json) {
boolean check = webHookToken.equals(gitlabToken);
log.info("webhook POST {}: {}; projectId: {}; check: {}, json: {}", HEADER_X_GITLAB_EVENT, gitlabEvent, projectId, check, json);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment