Skip to content

Commit

Permalink
Refactoring protocol serialization (#4).
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkins committed Oct 30, 2023
1 parent 40b987f commit adf1697
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,17 @@ public ConfigDto getConfig() {
@Operation(summary = "get cipherduck bookmark for this hub")
public String cipherduckhubbookmark(@Context UriInfo uriInfo) throws IOException {
final URI requestUri = uriInfo.getRequestUri();
String profileTemplate = new String(ConfigResource.class.getResourceAsStream("/cipherduck/hubprotocol.cyberduckprofile").readAllBytes());
String bookmarkTemplate = new String(ConfigResource.class.getResourceAsStream("/cipherduck/hubbookmark.duck").readAllBytes());

// Scheme
profileTemplate = profileTemplate.replace("<string>Scheme</string>", String.format("<string>%s</string>", requestUri.getScheme()));
bookmarkTemplate = bookmarkTemplate.replace("<string>Scheme</string>", String.format("<string>%s</string>", requestUri.getScheme()));

// N.B. we use client_id="cryptomator" in cipherduck, see discussion https://github.com/chenkins/cipherduck-hub/issues/6
profileTemplate = profileTemplate.replace("<string>OAuth Client ID</string>", String.format("<string>%s</string>", getConfig().keycloakClientIdCryptomator()));
profileTemplate = profileTemplate.replace("<string>OAuth Authorization Url</string>", String.format("<string>%s</string>", getConfig().authEndpoint()));
profileTemplate = profileTemplate.replace("<string>OAuth Token Url</string>", String.format("<string>%s</string>", getConfig().tokenEndpoint()));
bookmarkTemplate = bookmarkTemplate.replace("<string>OAuth Client ID</string>", String.format("<string>%s</string>", getConfig().keycloakClientIdCryptomator()));
bookmarkTemplate = bookmarkTemplate.replace("<string>OAuth Authorization Url</string>", String.format("<string>%s</string>", getConfig().authEndpoint()));
bookmarkTemplate = bookmarkTemplate.replace("<string>OAuth Token Url</string>", String.format("<string>%s</string>", getConfig().tokenEndpoint()));



String bookmarkTemplate = new String(ConfigResource.class.getResourceAsStream("/cipherduck/hubbookmark.duck").readAllBytes());
String hubUrl = String.format("%s://%s:%s", requestUri.getScheme(), requestUri.getHost(), requestUri.getPort());
// nickname
bookmarkTemplate = bookmarkTemplate.replace("<string>Cipherduck</string>", String.format("<string>Cipherduck (%s)</string>", hubUrl));
Expand All @@ -92,7 +90,7 @@ public String cipherduckhubbookmark(@Context UriInfo uriInfo) throws IOException
bookmarkTemplate = bookmarkTemplate.replace("<string>c36acf24-e331-4919-9f19-ff52a08e7885</string>", String.format("<string>%s</string>", Settings.get().hubId));

// protocol
bookmarkTemplate = bookmarkTemplate.replace("<string>serialized_protocol/string>", String.format("<string>%s</string>", new String(Base64.getEncoder().encode(profileTemplate.getBytes(StandardCharsets.UTF_8)))));
bookmarkTemplate = bookmarkTemplate.replace("<string>serialized_protocol/string>", String.format("<string>%s</string>", new String(Base64.getEncoder().encode(bookmarkTemplate.getBytes(StandardCharsets.UTF_8)))));



Expand Down
15 changes: 13 additions & 2 deletions backend/src/main/resources/cipherduck/hubbookmark.duck
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
<string>localhost</string>
<key>Port</key>
<string>8080</string>
<key>serialized_protocol</key>
<string>serialized_protocol/string>
<key>Custom</key>
<dict>
<key>Protocol</key>
<string>hub</string>
<key>Scheme</key>
<string>Scheme</string>
<key>OAuth Authorization Url</key>
<string>OAuth Authorization Url</string>
<key>OAuth Token Url</key>
<string>OAuth Token Url</string>
<key>OAuth Client ID</key>
<string>OAuth Client ID</string>
</dict>
</dict>
</plist>
16 changes: 0 additions & 16 deletions backend/src/main/resources/cipherduck/hubprotocol.cyberduckprofile

This file was deleted.

0 comments on commit adf1697

Please sign in to comment.