-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #61 Create new GitHub Projects Section - [x] GET projects by GIT username endpoints (via request parameter or by path variable in URI) - [x] Add new section to home page for Github projects - Update project configurations & refactoring of package/project structure - Unit tests for all new code * #61 Adding username validation & unit tests, Unpack imports where wildcard used
- Loading branch information
1 parent
f5ae0da
commit b7a3ab8
Showing
33 changed files
with
1,231 additions
and
61 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
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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
FROM eclipse-temurin:21-jdk | ||
|
||
VOLUME /tmp | ||
|
||
#for aws | ||
COPY target/*.war app.war | ||
RUN sh -c 'touch /app.war' | ||
|
||
|
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
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 com.ironoc.portfolio.client; | ||
|
||
import javax.net.ssl.HttpsURLConnection; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public interface Client { | ||
|
||
HttpsURLConnection createConn(String url) throws IOException; | ||
|
||
InputStream readInputStream(HttpsURLConnection conn) throws IOException; | ||
|
||
void closeConn(InputStream inputStream) throws IOException; | ||
} |
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,51 @@ | ||
package com.ironoc.portfolio.client; | ||
|
||
import com.ironoc.portfolio.config.PropertyConfigI; | ||
import io.micrometer.common.util.StringUtils; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.net.ssl.HttpsURLConnection; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
|
||
@Component | ||
@Slf4j | ||
public class GitClient implements Client { | ||
|
||
private final PropertyConfigI propertyConfig; | ||
|
||
public GitClient(PropertyConfigI propertyConfig) { | ||
this.propertyConfig = propertyConfig; | ||
} | ||
|
||
@Override | ||
public HttpsURLConnection createConn(String url) throws IOException { | ||
URL apiUrlEndpoint = new URL(url); | ||
HttpsURLConnection conn = (HttpsURLConnection) apiUrlEndpoint.openConnection(); | ||
String token = propertyConfig.getGitToken(); | ||
if (StringUtils.isBlank(token)) { | ||
log.warn("GIT token not set, the lower request rate will apply"); | ||
} else { | ||
conn.setRequestProperty("Authorization", token); | ||
} | ||
conn.setRequestMethod(HttpMethod.GET.name()); | ||
conn.setFollowRedirects(propertyConfig.getGitFollowRedirects()); | ||
conn.setConnectTimeout(propertyConfig.getGitTimeoutConnect()); | ||
conn.setReadTimeout(propertyConfig.getGitTimeoutRead()); | ||
conn.setInstanceFollowRedirects(propertyConfig.getGitInstanceFollowRedirects()); | ||
return conn; | ||
} | ||
|
||
@Override | ||
public InputStream readInputStream(HttpsURLConnection conn) throws IOException { | ||
return conn.getInputStream(); | ||
} | ||
|
||
@Override | ||
public void closeConn(InputStream inputStream) throws IOException { | ||
inputStream.close(); | ||
} | ||
} |
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
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,21 @@ | ||
package com.ironoc.portfolio.config; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum Properties { | ||
|
||
GIT_TOKEN("com.ironoc.portfolio.github.token"), | ||
GIT_API_ENDPOINT("com.ironoc.portfolio.github.api.endpoint"), | ||
GIT_REPOS_URI("com.ironoc.portfolio.github.uri.repos"), | ||
GIT_TIMEOUT_CONNECT ("com.ironoc.portfolio.github.timeout.connect"), | ||
GIT_TIMEOUT_READ("com.ironoc.portfolio.github.timeout.read"), | ||
GIT_INSTANCE_FOLLOW_REDIRECTS("com.ironoc.portfolio.github.instance-follow-redirects"), | ||
GIT_FOLLOW_REDIRECTS("com.ironoc.portfolio.github.follow-redirects"); | ||
|
||
private String key; | ||
|
||
Properties(String key) { | ||
this.key = key; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/ironoc/portfolio/config/PropertyConfig.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,52 @@ | ||
package com.ironoc.portfolio.config; | ||
|
||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class PropertyConfig implements PropertyConfigI { | ||
|
||
private final Environment environment; | ||
|
||
private final PropertyKeyI propertyKey; | ||
|
||
public PropertyConfig(Environment environment, PropertyKeyI propertyKey) { | ||
this.environment = environment; | ||
this.propertyKey = propertyKey; | ||
} | ||
|
||
@Override | ||
public String getGitApiEndpoint() { | ||
return environment.getRequiredProperty(propertyKey.getGitApiEndpoint()); | ||
} | ||
|
||
@Override | ||
public String getGitReposUri() { | ||
return environment.getRequiredProperty(propertyKey.getGitReposUri()); | ||
} | ||
|
||
@Override | ||
public Integer getGitTimeoutConnect() { | ||
return Integer.valueOf(environment.getRequiredProperty(propertyKey.getGitTimeoutConnect())); | ||
} | ||
|
||
@Override | ||
public Integer getGitTimeoutRead() { | ||
return Integer.valueOf(environment.getRequiredProperty(propertyKey.getGitTimeoutRead())); | ||
} | ||
|
||
@Override | ||
public Boolean getGitInstanceFollowRedirects() { | ||
return Boolean.valueOf(environment.getRequiredProperty(propertyKey.getGitInstanceFollowRedirects())); | ||
} | ||
|
||
@Override | ||
public Boolean getGitFollowRedirects() { | ||
return Boolean.valueOf(environment.getRequiredProperty(propertyKey.getGitFollowRedirects())); | ||
} | ||
|
||
@Override | ||
public String getGitToken() { | ||
return environment.getProperty(propertyKey.getGitToken(), ""); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/ironoc/portfolio/config/PropertyConfigI.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,18 @@ | ||
package com.ironoc.portfolio.config; | ||
|
||
public interface PropertyConfigI { | ||
|
||
String getGitApiEndpoint(); | ||
|
||
String getGitReposUri(); | ||
|
||
Integer getGitTimeoutConnect(); | ||
|
||
Integer getGitTimeoutRead(); | ||
|
||
Boolean getGitInstanceFollowRedirects(); | ||
|
||
Boolean getGitFollowRedirects(); | ||
|
||
String getGitToken(); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/ironoc/portfolio/config/PropertyKey.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,42 @@ | ||
package com.ironoc.portfolio.config; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class PropertyKey implements PropertyKeyI { | ||
|
||
@Override | ||
public String getGitApiEndpoint() { | ||
return Properties.GIT_API_ENDPOINT.getKey(); | ||
} | ||
|
||
@Override | ||
public String getGitReposUri() { | ||
return Properties.GIT_REPOS_URI.getKey(); | ||
} | ||
|
||
@Override | ||
public String getGitTimeoutConnect() { | ||
return Properties.GIT_TIMEOUT_CONNECT.getKey(); | ||
} | ||
|
||
@Override | ||
public String getGitTimeoutRead() { | ||
return Properties.GIT_TIMEOUT_READ.getKey(); | ||
} | ||
|
||
@Override | ||
public String getGitInstanceFollowRedirects() { | ||
return Properties.GIT_INSTANCE_FOLLOW_REDIRECTS.getKey(); | ||
} | ||
|
||
@Override | ||
public String getGitFollowRedirects() { | ||
return Properties.GIT_FOLLOW_REDIRECTS.getKey(); | ||
} | ||
|
||
@Override | ||
public String getGitToken() { | ||
return Properties.GIT_TOKEN.getKey(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/ironoc/portfolio/config/PropertyKeyI.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,18 @@ | ||
package com.ironoc.portfolio.config; | ||
|
||
public interface PropertyKeyI { | ||
|
||
String getGitApiEndpoint(); | ||
|
||
String getGitReposUri(); | ||
|
||
String getGitTimeoutConnect(); | ||
|
||
String getGitTimeoutRead(); | ||
|
||
String getGitInstanceFollowRedirects(); | ||
|
||
String getGitFollowRedirects(); | ||
|
||
String getGitToken(); | ||
} |
9 changes: 4 additions & 5 deletions
9
src/main/java/com/ironoc/portfolio/controller/CustomErrorController.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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/ironoc/portfolio/controller/GitProjectsController.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,60 @@ | ||
package com.ironoc.portfolio.controller; | ||
|
||
import com.ironoc.portfolio.domain.RepositoryDetailDomain; | ||
import com.ironoc.portfolio.dto.RepositoryDetailDto; | ||
import com.ironoc.portfolio.logger.AbstractLogger; | ||
import com.ironoc.portfolio.service.GitDetailsService; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Controller | ||
public class GitProjectsController extends AbstractLogger { | ||
|
||
@Autowired | ||
private final GitDetailsService gitDetailsService; | ||
|
||
public GitProjectsController(GitDetailsService gitDetailsService) { | ||
this.gitDetailsService = gitDetailsService; | ||
} | ||
|
||
@GetMapping(value = {"/get-repo-detail/{username}/"}, produces= MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<List<RepositoryDetailDomain>> getReposByUsernamePathVar(HttpServletRequest request, | ||
@PathVariable(value = "username") String username) { | ||
return getReposByUsername(request, username); | ||
} | ||
|
||
@GetMapping(value = {"/get-repo-detail"}, produces= MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<List<RepositoryDetailDomain>> getReposByUsernameReqParam(HttpServletRequest request, | ||
@RequestParam(value = "username") String username) { | ||
return getReposByUsername(request, username); | ||
} | ||
|
||
private ResponseEntity<List<RepositoryDetailDomain>> getReposByUsername(HttpServletRequest request, | ||
String username) { | ||
// username validation | ||
if (StringUtils.isBlank(username) | !StringUtils.isAlphanumeric(username) | !StringUtils.isAlpha(username)) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Collections.emptyList()); | ||
} | ||
|
||
info("Github get repositories by username={} for request, host={}, uri={}, user-agent={}", | ||
username, | ||
request.getHeader("host"), | ||
request.getRequestURI(), | ||
request.getHeader("user-agent")); | ||
List<RepositoryDetailDto> repositories = gitDetailsService.getRepoDetails(username); | ||
info("The repository details for user={} are: {}", username, repositories); | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(gitDetailsService.mapRepositoriesToResponse(repositories)); | ||
} | ||
} |
Oops, something went wrong.