Skip to content

Commit 0878a6b

Browse files
authored
Merge pull request #1 from gridsuite/create_user_admin_server
Create user admin server
2 parents 590f6db + 590c4a2 commit 0878a6b

23 files changed

+885
-0
lines changed

.github/workflows/maven.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
tags:
8+
- 'v[0-9]*'
9+
pull_request:
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Set up JDK 11
18+
uses: actions/setup-java@v1
19+
with:
20+
java-version: 11
21+
22+
- name: Checkout sources
23+
uses: actions/checkout@v1
24+
25+
- name: Build with Maven
26+
run: mvn --batch-mode -P jacoco verify
27+
28+
- name: Run SonarCloud analysis
29+
run: >
30+
mvn --batch-mode -DskipTests sonar:sonar
31+
-Dsonar.host.url=https://sonarcloud.io
32+
-Dsonar.organization=gridsuite
33+
-Dsonar.projectKey=org.gridsuite:user-admin-server
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37+
38+
- name: Build Docker image - Main
39+
if: github.ref == 'refs/heads/main'
40+
run: >
41+
mvn --batch-mode deploy -DskipTests -Dmaven.install.skip -Dmaven.deploy.skip -Dpowsybl.docker.deploy
42+
-Djib.httpTimeout=60000
43+
-Djib.to.image=docker.io/gridsuite/user-admin-server
44+
-Djib.to.auth.username=gridsuiteci
45+
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
46+
47+
- name: Build Docker image - Tag
48+
if: startsWith(github.ref, 'refs/tags/')
49+
run: >
50+
mvn --batch-mode deploy -DskipTests -Dmaven.install.skip -Dmaven.deploy.skip -Dpowsybl.docker.deploy
51+
-Djib.httpTimeout=60000
52+
-Djib.to.image=docker.io/gridsuite/user-admin-server:${GITHUB_REF_NAME#v}
53+
-Djib.to.auth.username=gridsuiteci
54+
-Djib.to.auth.password=${{ secrets.DOCKERHUB_TOKEN }}
55+
56+
- name: Broadcast update event
57+
if: github.ref == 'refs/heads/main'
58+
uses: gridsuite/broadcast-event@main
59+
with:
60+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
61+
event-type: user_admin_server_updated

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# VSCode
2+
/.vscode
3+
/.settings
4+
.classpath
5+
.factorypath
6+
.project
7+
8+
target/
9+
10+
# IntelliJ
11+
/.idea
12+
*.iml

pom.xml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2022, RTE (http://www.rte-france.com)
5+
This Source Code Form is subject to the terms of the Mozilla Public
6+
License, v. 2.0. If a copy of the MPL was not distributed with this
7+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+
-->
10+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
11+
xmlns="http://maven.apache.org/POM/4.0.0"
12+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
13+
<modelVersion>4.0.0</modelVersion>
14+
15+
<parent>
16+
<groupId>com.powsybl</groupId>
17+
<artifactId>powsybl-parent-ws</artifactId>
18+
<version>8</version>
19+
<relativePath/>
20+
</parent>
21+
22+
<groupId>org.gridsuite</groupId>
23+
<artifactId>gridsuite-user-admin-server</artifactId>
24+
<version>1.0.0-SNAPSHOT</version>
25+
26+
<packaging>jar</packaging>
27+
<name>User admin server</name>
28+
<description>User admin server</description>
29+
<url>http://www.gridsuite.org/</url>
30+
31+
<scm>
32+
<connection>scm:git:https://github.com/gridsuite/user-admin-server.git</connection>
33+
<developerConnection>scm:git:https://github.com/gridsuite/user-admin-server.git</developerConnection>
34+
<url>https://github.com/gridsuite/user-admin-server</url>
35+
</scm>
36+
37+
<developers>
38+
<developer>
39+
<name>Etienne HOMER</name>
40+
<email>[email protected]</email>
41+
<organization>RTE</organization>
42+
<organizationUrl>http://www.rte-france.com</organizationUrl>
43+
</developer>
44+
</developers>
45+
46+
<properties>
47+
<java.version>11</java.version>
48+
<gridsuite-dependencies.version>18</gridsuite-dependencies.version>
49+
<liquibase-hibernate-package>org.gridsuite.useradmin.server</liquibase-hibernate-package>
50+
</properties>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>com.google.cloud.tools</groupId>
56+
<artifactId>jib-maven-plugin</artifactId>
57+
</plugin>
58+
<plugin>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-maven-plugin</artifactId>
61+
</plugin>
62+
<plugin>
63+
<groupId>pl.project13.maven</groupId>
64+
<artifactId>git-commit-id-plugin</artifactId>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
69+
<dependencyManagement>
70+
<dependencies>
71+
<!-- overrides of imports -->
72+
73+
<!-- imports -->
74+
<dependency>
75+
<groupId>org.gridsuite</groupId>
76+
<artifactId>gridsuite-dependencies</artifactId>
77+
<version>${gridsuite-dependencies.version}</version>
78+
<type>pom</type>
79+
<scope>import</scope>
80+
</dependency>
81+
82+
<!-- project specific dependencies -->
83+
</dependencies>
84+
</dependencyManagement>
85+
86+
<dependencies>
87+
<!-- Compilation dependencies -->
88+
<dependency>
89+
<groupId>com.fasterxml.jackson.core</groupId>
90+
<artifactId>jackson-databind</artifactId>
91+
</dependency>
92+
<dependency>
93+
<groupId>com.powsybl</groupId>
94+
<artifactId>powsybl-ws-commons</artifactId>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.projectlombok</groupId>
98+
<artifactId>lombok</artifactId>
99+
</dependency>
100+
<!-- jpa, crud repository -->
101+
<dependency>
102+
<groupId>org.springframework.boot</groupId>
103+
<artifactId>spring-boot-starter-data-jpa</artifactId>
104+
</dependency>
105+
<dependency>
106+
<groupId>org.springframework.boot</groupId>
107+
<artifactId>spring-boot-starter-web</artifactId>
108+
</dependency>
109+
<dependency>
110+
<groupId>org.springdoc</groupId>
111+
<artifactId>springdoc-openapi-ui</artifactId>
112+
</dependency>
113+
114+
<!-- Runtime dependencies -->
115+
<dependency>
116+
<groupId>org.liquibase</groupId>
117+
<artifactId>liquibase-core</artifactId>
118+
<scope>runtime</scope>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.postgresql</groupId>
122+
<artifactId>postgresql</artifactId>
123+
<scope>runtime</scope>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.springframework.boot</groupId>
127+
<artifactId>spring-boot-starter-actuator</artifactId>
128+
<scope>runtime</scope>
129+
</dependency>
130+
131+
<!-- Test dependencies -->
132+
<dependency>
133+
<groupId>com.h2database</groupId>
134+
<artifactId>h2</artifactId>
135+
<scope>test</scope>
136+
</dependency>
137+
<dependency>
138+
<groupId>junit</groupId>
139+
<artifactId>junit</artifactId>
140+
<scope>test</scope>
141+
</dependency>
142+
<dependency>
143+
<groupId>org.junit.vintage</groupId>
144+
<artifactId>junit-vintage-engine</artifactId>
145+
<scope>test</scope>
146+
</dependency>
147+
<dependency>
148+
<groupId>org.mockito</groupId>
149+
<artifactId>mockito-core</artifactId>
150+
<scope>test</scope>
151+
</dependency>
152+
<dependency>
153+
<groupId>org.springframework.boot</groupId>
154+
<artifactId>spring-boot-starter-test</artifactId>
155+
<scope>test</scope>
156+
</dependency>
157+
</dependencies>
158+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) 2022, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.useradmin.server;
8+
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.PropertySource;
11+
12+
/**
13+
* @author Etienne Homer <etienne.homer at rte-france.com>
14+
*/
15+
16+
@Configuration
17+
@PropertySource(value = {"classpath:database.properties"})
18+
@PropertySource(value = {"file:/config/database.properties"}, ignoreResourceNotFound = true)
19+
public class DataSourceConfig {
20+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) 2022, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.useradmin.server;
8+
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.ControllerAdvice;
12+
import org.springframework.web.bind.annotation.ExceptionHandler;
13+
14+
import static org.gridsuite.useradmin.server.UserAdminException.Type.FORBIDDEN;
15+
16+
/**
17+
* @author Etienne Homer <etienne.homer at rte-france.com>
18+
*/
19+
@ControllerAdvice
20+
public class RestResponseEntityExceptionHandler {
21+
22+
@ExceptionHandler(value = { UserAdminException.class })
23+
protected ResponseEntity<Object> handleException(RuntimeException exception) {
24+
if (exception instanceof UserAdminException) {
25+
UserAdminException userAdminException = (UserAdminException) exception;
26+
if (userAdminException.getType().equals(FORBIDDEN)) {
27+
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(userAdminException.getType());
28+
}
29+
}
30+
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (c) 2022, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.useradmin.server;
8+
9+
import io.swagger.v3.oas.models.OpenAPI;
10+
import io.swagger.v3.oas.models.info.Info;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.Configuration;
13+
14+
/**
15+
* @author Etienne Homer <etienne.homer at rte-france.com>
16+
*/
17+
@Configuration
18+
public class SwaggerConfig {
19+
20+
@Bean
21+
public OpenAPI openAPI() {
22+
return new OpenAPI()
23+
.info(new Info()
24+
.title("User Admin API")
25+
.description("This is the documentation of the user admin REST API")
26+
.version(UserAdminApi.API_VERSION));
27+
}
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) 2022, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.useradmin.server;
8+
9+
/**
10+
* @author Etienne Homer <etienne.homer at rte-france.com>
11+
*/
12+
public final class UserAdminApi {
13+
14+
private UserAdminApi() {
15+
}
16+
17+
public static final String API_VERSION = "v1";
18+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2022, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.useradmin.server;
8+
9+
import com.powsybl.ws.commons.Utils;
10+
import org.springframework.boot.SpringApplication;
11+
import org.springframework.boot.autoconfigure.SpringBootApplication;
12+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
13+
14+
/**
15+
* @author Etienne Homer <etienne.homer at rte-france.com>
16+
*/
17+
@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
18+
@SpringBootApplication
19+
@EnableConfigurationProperties(UserAdminApplicationProps.class)
20+
public class UserAdminApplication {
21+
22+
public static void main(String[] args) {
23+
Utils.initProperties();
24+
SpringApplication.run(UserAdminApplication.class, args);
25+
}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2022, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.useradmin.server;
8+
9+
import lombok.Getter;
10+
import lombok.Setter;
11+
import org.springframework.boot.context.properties.ConfigurationProperties;
12+
13+
import java.util.List;
14+
15+
/**
16+
* @author Etienne Homer <etienne.homer at rte-france.com>
17+
*/
18+
@Getter
19+
@Setter
20+
@ConfigurationProperties(prefix = "useradmin")
21+
public class UserAdminApplicationProps {
22+
23+
private List<String> admins;
24+
}

0 commit comments

Comments
 (0)