This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit bd205643 authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Adding Application Deployment Info

parent 93cebb94
2 merge requests!17Initial Merge to Prepare Release 1.0.0,!7Resolve "Fix secrets in source code!"
......@@ -17,6 +17,8 @@ public class ApplicationProperties {
private GitLab gitLab;
private DeploymentInfo deploymentInfo;
private List<String> registeredPlugins;
/**
......@@ -50,7 +52,21 @@ public class ApplicationProperties {
this.gitLab = gitLab;
}
public static class Search {
/**
* @return the deploymentInfo
*/
public DeploymentInfo getDeploymentInfo() {
return deploymentInfo;
}
/**
* @param deploymentInfo the deploymentInfo to set
*/
public void setDeploymentInfo(DeploymentInfo deploymentInfo) {
this.deploymentInfo = deploymentInfo;
}
public static class Search {
private String highlightPre;
private String highlightPost;
......@@ -108,4 +124,33 @@ public class ApplicationProperties {
}
}
public static class DeploymentInfo {
private String commitId;
private String branch;
/**
* @return the commitId
*/
public String getCommitId() {
return commitId;
}
/**
* @param commitId the commitId to set
*/
public void setCommitId(String commitId) {
this.commitId = commitId;
}
/**
* @return the branch
*/
public String getBranch() {
return branch;
}
/**
* @param branch the branch to set
*/
public void setBranch(String branch) {
this.branch = branch;
}
}
}
......@@ -129,7 +129,6 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
http
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers("/api/search/**") // Allowing search even without CSRF Token
.ignoringAntMatchers("/api/pluginIF/**") // Allowing plugin Access. security is checked by token
.and()
.authenticationProvider(customJWTauthenticationProvider())
......@@ -158,6 +157,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.antMatchers("/oauth2/**").permitAll()
.antMatchers("/api/search/**").permitAll() // search is always allowed, may return more data, if authenticated
.antMatchers("/api/pluginIF/**").permitAll() // plugins calls are always allowed, security by tokens
.antMatchers("/api/deploymentInfo").permitAll() // everybody may retrieve deployment infos
.antMatchers("/api/authenticate").permitAll()
.antMatchers("/api/refreshToken").permitAll()
.antMatchers("/api/register").denyAll()
......
package at.ac.uibk.gitsearch.web.rest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import at.ac.uibk.gitsearch.config.ApplicationProperties;
import at.ac.uibk.gitsearch.config.ApplicationProperties.DeploymentInfo;
/**
* REST controller to retrieve deployment infos.
*/
@RestController
@RequestMapping("/api")
public class ApplicationInfoResource {
private final Logger log = LoggerFactory.getLogger(ApplicationInfoResource.class);
private final ApplicationProperties applicationProperties;
public ApplicationInfoResource(ApplicationProperties applicationProperties) {
this.applicationProperties = applicationProperties;
}
/**
* {@code GET /deploymentInfo} : get generic deployment info.
*
*/
@GetMapping("/deploymentInfo")
public ApplicationProperties.DeploymentInfo getApplicationInfo() {
final DeploymentInfo deploymentInfo = applicationProperties.getDeploymentInfo();
if(deploymentInfo==null || "${git.branch}".equals(deploymentInfo.getBranch())) {
return new ApplicationProperties.DeploymentInfo(); // application info is not initialized properly! Return an empty info
}
return deploymentInfo;
}
}
......@@ -174,3 +174,6 @@ application:
gitlab:
url: http://dev-exchange.codeability.org
mainGroup: exchange
deployment-info:
commit-id: "${git.commitId}"
branch: "${git.branch}"
\ No newline at end of file
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, } from 'rxjs';
import { SERVER_API_URL } from 'app/app.constants';
export class DeploymentInfo {
branch = "";
commitId = "";
}
@Injectable({ providedIn: 'root' })
export class ApplicationInfoService {
cachedDeploymentInfo: DeploymentInfo;
inLoading = false;
constructor(
private http: HttpClient,
) {
this.cachedDeploymentInfo = {} as DeploymentInfo;
}
private loadDeploymentInfo(): Observable<DeploymentInfo> {
return this.http.get<DeploymentInfo>(SERVER_API_URL + 'api/deploymentInfo');
}
public getDeploymentInfo(): DeploymentInfo {
if(!this.cachedDeploymentInfo.branch && !this.inLoading) {
this.inLoading = true;
this.loadDeploymentInfo().subscribe((res) => {
this.cachedDeploymentInfo = res;
this.inLoading = false;
});
}
return this.cachedDeploymentInfo;
}
}
......@@ -24,5 +24,9 @@
</div>
</div>
</div>
<div class="row" *ngIf="applicationInfoService.getDeploymentInfo().branch">
{{applicationInfoService.getDeploymentInfo().branch}} {{applicationInfoService.getDeploymentInfo().commitId}}
</div>
</div>
</div>
import { Component } from '@angular/core';
import { ApplicationInfoService } from 'app/core/application/applicationInfo.service'
@Component({
selector: 'jhi-footer',
templateUrl: './footer.component.html',
})
export class FooterComponent {}
export class FooterComponent {
constructor(public applicationInfoService: ApplicationInfoService) {}
}
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