forked from bclozel/initializr-stats
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,985 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/build/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= Initializr Stats | ||
|
||
See https://springoneplatform.io/2018/sessions/spring-boot-2-0-web-applications |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/build/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?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> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.1.5.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>io.spring.sample</groupId> | ||
<artifactId>dashboard</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<name>dashboard</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>webjars-locator-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.webjars.npm</groupId> | ||
<artifactId>bulma</artifactId> | ||
<version>0.7.1</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.webjars.npm</groupId> | ||
<artifactId>flatpickr</artifactId> | ||
<version>4.5.1</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.webjars.npm</groupId> | ||
<artifactId>font-awesome</artifactId> | ||
<version>4.7.0</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>highcharts</artifactId> | ||
<version>6.1.1</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
dashboard/src/main/java/io/spring/sample/dashboard/DashboardApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.spring.sample.dashboard; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class DashboardApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DashboardApplication.class, args); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
dashboard/src/main/java/io/spring/sample/dashboard/DashboardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.spring.sample.dashboard; | ||
|
||
import java.time.LocalDate; | ||
|
||
import io.spring.sample.dashboard.stats.StatsService; | ||
|
||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
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.RequestParam; | ||
|
||
@Controller | ||
public class DashboardController { | ||
|
||
private final StatsService statsService; | ||
|
||
public DashboardController(StatsService statsService) { | ||
this.statsService = statsService; | ||
} | ||
|
||
@GetMapping("/") | ||
public String index() { | ||
return redirect(LocalDate.now().minusWeeks(1).toString(), LocalDate.now().toString()); | ||
} | ||
|
||
@PostMapping("/") | ||
public String redirect(@RequestParam String fromDate, @RequestParam String toDate) { | ||
return String.format("redirect:/stats/%s/%s", fromDate, toDate); | ||
} | ||
|
||
@GetMapping("/stats/{fromDate}/{toDate}") | ||
public String showDashboard(@PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate, | ||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @PathVariable LocalDate toDate, | ||
Model model) { | ||
model.addAttribute("fromDate", fromDate); | ||
model.addAttribute("toDate", toDate); | ||
model.addAttribute("stats", statsService.fetchStats(fromDate.toString(), toDate.toString())); | ||
return "index"; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
dashboard/src/main/java/io/spring/sample/dashboard/ReverseLookupHealthIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.spring.sample.dashboard; | ||
|
||
import io.spring.sample.dashboard.stats.ReverseLookupClient; | ||
|
||
import org.springframework.boot.actuate.health.AbstractHealthIndicator; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class ReverseLookupHealthIndicator extends AbstractHealthIndicator { | ||
|
||
private final ReverseLookupClient client; | ||
|
||
public ReverseLookupHealthIndicator(ReverseLookupClient client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
protected void doHealthCheck(Health.Builder builder) { | ||
client.freeReverseLookup("10.10.10.10"); | ||
builder.up(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
dashboard/src/main/java/io/spring/sample/dashboard/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.spring.sample.dashboard; | ||
|
||
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; | ||
import org.springframework.boot.actuate.health.HealthEndpoint; | ||
import org.springframework.boot.actuate.info.InfoEndpoint; | ||
import org.springframework.boot.autoconfigure.security.servlet.PathRequest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.security.provisioning.InMemoryUserDetailsManager; | ||
|
||
@Configuration | ||
class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.authorizeRequests() | ||
.requestMatchers(EndpointRequest.to(InfoEndpoint.class, HealthEndpoint.class)).permitAll() | ||
.requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ADMIN") | ||
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() | ||
.anyRequest().authenticated() | ||
.and().formLogin().loginPage("/login").permitAll() | ||
.and().httpBasic(); | ||
} | ||
|
||
@Bean | ||
@SuppressWarnings("deprecation") | ||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() { | ||
return new InMemoryUserDetailsManager( | ||
User.withDefaultPasswordEncoder().username("user").password("user").roles("USER").build(), | ||
User.withDefaultPasswordEncoder().username("admin").password("admin").roles("USER", "ADMIN").build() | ||
); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
dashboard/src/main/java/io/spring/sample/dashboard/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.spring.sample.dashboard; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addViewControllers(ViewControllerRegistry registry) { | ||
registry.addViewController("/login").setViewName("login"); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
dashboard/src/main/java/io/spring/sample/dashboard/stats/Annotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.spring.sample.dashboard.stats; | ||
|
||
public class Annotation { | ||
|
||
private String text; | ||
|
||
private String date; | ||
|
||
public Annotation(String text, String date) { | ||
this.text = text; | ||
this.date = date; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public String getDate() { | ||
return date; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
dashboard/src/main/java/io/spring/sample/dashboard/stats/Client.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.spring.sample.dashboard.stats; | ||
|
||
public class Client { | ||
|
||
private String ip; | ||
private String hostname; | ||
|
||
public Client(String ip, String hostname) { | ||
this.ip = ip; | ||
this.hostname = hostname; | ||
} | ||
|
||
public String getIp() { | ||
return ip; | ||
} | ||
|
||
public String getHostname() { | ||
return hostname; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
dashboard/src/main/java/io/spring/sample/dashboard/stats/ProjectCreations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.spring.sample.dashboard.stats; | ||
|
||
public class ProjectCreations { | ||
|
||
public ProjectCreations(String date, int count) { | ||
this.date = date; | ||
this.count = count; | ||
} | ||
|
||
private String date; | ||
|
||
private int count; | ||
|
||
public String getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(String date) { | ||
this.date = date; | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
|
||
public void setCount(int count) { | ||
this.count = count; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
dashboard/src/main/java/io/spring/sample/dashboard/stats/ReverseLookupClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.spring.sample.dashboard.stats; | ||
|
||
import io.spring.sample.dashboard.stats.support.ReverseLookupDescriptor; | ||
|
||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Component | ||
public class ReverseLookupClient { | ||
|
||
private final RestTemplate client; | ||
|
||
public ReverseLookupClient(RestTemplateBuilder builder) { | ||
this.client = builder.build(); | ||
} | ||
|
||
public ReverseLookupDescriptor freeReverseLookup(String ip) { | ||
return this.client.getForObject("http://localhost:8081/reverse-lookup/free/{ip}", ReverseLookupDescriptor.class, ip); | ||
} | ||
|
||
public ReverseLookupDescriptor payingReverseLookup(String ip) { | ||
return this.client.getForObject("http://localhost:8081/reverse-lookup/costly/{ip}", ReverseLookupDescriptor.class, ip); | ||
} | ||
} |
Oops, something went wrong.