Skip to content

Commit

Permalink
#207 Allow local development
Browse files Browse the repository at this point in the history
  • Loading branch information
sklein94 committed Mar 30, 2023
1 parent a7ac063 commit 4cd0c12
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/development/start_and_debug_locally_de.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Smeagol lokal starten
Im folgenden wird beschrieben, wie Smeagol lokal ausgeführt werden kann.
Dennoch ist dafür ein lokales EcoSystem mit einem lauffähigen SCM-Manager notwendig.
Außerdem muss der CAS in die development-Stage gebracht werden.
Dafür folgendes ausführen: `etcdctl set config/_global/stage development && docker restart cas`


## 1. Frontend starten
* Sicherstellen dass die installierte Node-Version kleiner als 18 ist. Mit Node 16 wurde es erfolgreich getestet.
* Aus dem Root-Ordner des Repositories folgendes ausführen: `node src/main/scripts/start.js`


## 2. Backend starten
* Beim SCM-Manager ein API-Token erstellen: `https://192.168.56.2/scm/me/settings/apiKeys`
* Den API-Key kopieren und in die application.yml unter `src/main/resources` eintragen

Beispiel:
```
scm:
url: https://192.168.56.2/scm
accessKey: eyJhcGlLZXlJZCI6IjVFVFp5ZUNlckEiLCJ1c2VyIjoiYWRtaW4iLCJwYXNzcGhyYXNlIjoieDFodXliWkhIaWpuTnNoNFlqQngifQ
```

* Mit `./mvwnw spring-boot:run` bzw `mvn spring-boot:run` Smeagol starten - Applikation läuft nun.
* Alternativ kann Smeagol auch einfach über die IDE gestartet werden. Die Konfiguration dafür sollte automatisch angelegt worden sein.

25 changes: 25 additions & 0 deletions docs/development/start_and_debug_locally_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Start Smeagol locally
The following describes how to run Smeagol locally.
However, this requires a local EcoSystem with a running SCM manager.
In addition, the CAS must be brought into the development stage.
To do this, execute the following: `etcdctl set config/_global/stage development && docker restart cas`.


## 1. start frontend
* Make sure that the installed node version is lower than 18. With Node 16 it was tested successfully.
* From the root folder of the repository execute: `node src/main/scripts/start.js`.


## 2. start backend
* Create an API token at the SCM manager: `https://192.168.56.2/scm/me/settings/apiKeys`.
* Copy the API key and add it to the application.yml under `src/main/resources`.

Example:
```
scm:
url: https://192.168.56.2/scm
accessKey: eyJhcGlLZXlJZCI6IjVFVFp5ZUNlckEiLCJ1c2VyIjoiYWRtaW4iLCJwYXNzcGhyYXNlIjoieDFodXliWkhIaWpuTnNoNFlqQngifQ
```

* Start Smeagol with `./mvwnw spring-boot:run` or `mvn spring-boot:run` - application is now running.
* Alternatively, Smeagol can also be started simply via the IDE. The configuration for this should have been created automatically.
12 changes: 12 additions & 0 deletions src/main/java/com/cloudogu/smeagol/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ public class AccountService {
private final String scmUrl;
private final RestTemplate scmRestTemplate;

// For local development purposes only
private final String accessKey;

private static final String ACCESS_TOKEN_ENDPOINT = "/api/v2/cas/auth/";

@Autowired
public AccountService(ObjectFactory<HttpServletRequest> requestFactory, RestTemplateBuilder restTemplateBuilder,
@Value("${scm.accessKey:#{null}}") String accessKey,
@Value("${scm.url}") String scmUrl, Stage stage) {
this.scmRestTemplate = createRestTemplate(restTemplateBuilder, stage, scmUrl);
this.requestFactory = requestFactory;
this.scmUrl = scmUrl;
// For local development purposes only
this.accessKey = accessKey;
}

/**
Expand Down Expand Up @@ -98,6 +104,12 @@ private Account getNewAccount(HttpServletRequest request) {
}

private String getAccessToken(AttributePrincipal principal) {
// Should be used in local development only
if (this.accessKey != null){
String accessKey = this.accessKey;
return accessKey;
}

String accessTokenEndpointURL = getAccessTokenEndpoint();
String pt = principal.getProxyTicketFor(accessTokenEndpointURL);
if (Strings.isNullOrEmpty(pt)) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ ui:

scm:
url: https://192.168.56.2/scm
accessKey: eyJhcGlLZXlJZCI6IjVFVFp5ZUNlckEiLCJ1c2VyIjoiYWRtaW4iLCJwYXNzcGhyYXNlIjoieDFodXliWkhIaWpuTnNoNFlqQngifQ


cas:
url: https://192.168.56.2/cas
Expand Down

0 comments on commit 4cd0c12

Please sign in to comment.