Skip to content

Commit

Permalink
GH-94 Support UI customization and improve configuration loading proc…
Browse files Browse the repository at this point in the history
…ess (Resolve #94)
  • Loading branch information
dzikoysk committed May 31, 2020
1 parent cc47195 commit 9b1239c
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.javalin.core.JavalinConfig;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.panda_lang.reposilite.api.ConfigurationApiController;
import org.panda_lang.reposilite.api.IndexApiController;
import org.panda_lang.reposilite.config.Configuration;
import org.panda_lang.reposilite.frontend.FrontendController;
Expand Down Expand Up @@ -48,6 +49,7 @@ void start(Configuration configuration, Runnable onStart) {
LookupController lookupController = new LookupController(reposilite.getFrontend(), lookupService);

this.javalin = Javalin.create(this::config)
.get("/api/configuration", new ConfigurationApiController(reposilite.getConfiguration()))
.get("/api/*", new IndexApiController(reposilite))
.get("/js/app.js", new FrontendController(reposilite))
.get("/*", lookupController)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.panda_lang.reposilite.api;

import java.io.Serializable;

final class ConfigDto implements Serializable {

private final String title;
private final String description;
private final String accentColor;

ConfigDto(String title, String description, String accentColor) {
this.title = title;
this.description = description;
this.accentColor = accentColor;
}

public String getAccentColor() {
return accentColor;
}


public String getDescription() {
return description;
}

public String getTitle() {
return title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.panda_lang.reposilite.api;

import io.javalin.http.Context;
import org.panda_lang.reposilite.RepositoryController;
import org.panda_lang.reposilite.config.Configuration;

public final class ConfigurationApiController implements RepositoryController {

private final Configuration configuration;

public ConfigurationApiController(Configuration configuration) {
this.configuration = configuration;
}

@Override
public Context handleContext(Context ctx) {
return ctx.json(new ConfigDto(
configuration.getTitle(),
configuration.getDescription(),
configuration.getAccentColor())
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import io.javalin.http.Context;
import io.vavr.collection.Stream;
import org.apache.http.HttpStatus;
import org.panda_lang.reposilite.Reposilite;
import org.panda_lang.reposilite.RepositoryController;
import org.panda_lang.reposilite.auth.Authenticator;
import org.panda_lang.reposilite.config.Configuration;
import org.panda_lang.reposilite.metadata.MetadataUtils;
import org.panda_lang.reposilite.repository.RepositoryService;
Expand All @@ -32,18 +34,24 @@
public final class IndexApiController implements RepositoryController {

private final Configuration configuration;
private final Authenticator authenticator;
private final RepositoryService repositoryService;

public IndexApiController(Reposilite reposilite) {
this.configuration = reposilite.getConfiguration();
this.authenticator = reposilite.getAuthenticator();
this.repositoryService = reposilite.getRepositoryService();
}

@Override
public Context handleContext(Context ctx) {
Reposilite.getLogger().info(ctx.req.getRequestURI() + " API");

String uri = RepositoryUtils.normalizeUri(configuration, StringUtils.replaceFirst(ctx.req.getRequestURI(), "/api/", StringUtils.EMPTY));

if (configuration.isFullAuthEnabled() && authenticator.authUri(ctx, uri).getError().isDefined()) {
return ctx.status(HttpStatus.SC_UNAUTHORIZED);
}

File requestedFile = repositoryService.getFile(uri);

if (requestedFile.getName().equals("latest")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public Authenticator(TokenService tokenService) {
this.tokenService = tokenService;
}

public Result<Session, String> authUri(Context context) {
public Result<Session, String> authDefault(Context context) {
return authUri(context, context.req.getRequestURI());
}

public Result<Session, String> authUri(Context context, String uri) {
Result<Session, String> authResult = auth(context);

if (authResult.getError().isDefined()) {
Expand All @@ -39,7 +43,7 @@ public Result<Session, String> authUri(Context context) {

Session session = authResult.getValue().get();

if (!session.hasPermission(context.req.getRequestURI())) {
if (!session.hasPermission(uri)) {
return Result.error("Unauthorized access");
}

Expand Down Expand Up @@ -81,10 +85,6 @@ public Result<Session, String> auth(Context context) {
return Result.error("Invalid authorization credentials");
}

if (!context.req.getRequestURI().startsWith(token.getPath())) {
return Result.error("Invalid authorization credentials");
}

return Result.ok(new Session(token));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@
package org.panda_lang.reposilite.config;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public final class Configuration implements Serializable {

private String hostname;
private int port;
private List<String> repositories;
private List<String> proxied;
private boolean deployEnabled;
private boolean rewritePathsEnabled;
private boolean fullAuthEnabled;
// Bind properties
private String hostname = "";
private int port = 80;

// Repository properties
private final List<String> repositories = new ArrayList<>(3);
private final List<String> proxied = new ArrayList<>(3);

// Access properties
private boolean deployEnabled = true;
private boolean rewritePathsEnabled = true;
private boolean fullAuthEnabled = false;

// Frontend properties
private String title = "#onlypanda";
private String description = "Public Maven repository hosted through the Reposilite";
private String accentColor = "#009890";

public void setHostname(String hostname) {
this.hostname = hostname;
Expand All @@ -38,11 +49,11 @@ public void setPort(int port) {
}

public void setRepositories(List<String> repositories) {
this.repositories = repositories;
this.repositories.addAll(repositories);
}

public void setProxied(List<String> proxied) {
this.proxied = proxied;
this.proxied.addAll(proxied);
}

public void setDeployEnabled(boolean deployEnabled) {
Expand All @@ -57,6 +68,30 @@ public void setFullAuthEnabled(boolean fullAuthEnabled) {
this.fullAuthEnabled = fullAuthEnabled;
}

public void setTitle(String title) {
this.title = title;
}

public void setDescription(String description) {
this.description = description;
}

public void setAccentColor(String accentColor) {
this.accentColor = accentColor;
}

public String getAccentColor() {
return accentColor;
}

public String getDescription() {
return description;
}

public String getTitle() {
return title;
}

public String getHostname() {
return hostname;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Result<Context, String> deploy(Context context) {
return Result.error("Artifact deployment is disabled");
}

Result<Session, String> authResult = this.authenticator.authUri(context);
Result<Session, String> authResult = this.authenticator.authDefault(context);

if (authResult.getError().isDefined()) {
return Result.error(authResult.getError().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected Result<Context, String> serveProxied(Context context) {

protected Result<Context, String> serveLocal(Context context) {
if (configuration.isFullAuthEnabled()) {
Result<Session, String> authResult = this.authenticator.authUri(context);
Result<Session, String> authResult = this.authenticator.authDefault(context);

if (authResult.getError().isDefined()) {
return Result.error(authResult.getError().get());
Expand Down
2 changes: 1 addition & 1 deletion reposilite-backend/src/main/resources/frontend/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href="data:;base64,iVBORw0KGgo="><title>Reposilite</title><link href="https://fonts.googleapis.com/css2?family=Manrope:wght@300;500&display=swap" rel=stylesheet><script src=https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js></script><script>window.REPOSILITE_MESSAGE = '{{message}}'</script><link href=/js/app.js rel=preload as=script></head><body><noscript><strong>We're sorry but reposilite-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/app.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href="data:;base64,iVBORw0KGgo="><title>Reposilite</title><link href="https://fonts.googleapis.com/css2?family=Manrope:wght@300;500&display=swap" rel=stylesheet><script src=https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js></script><script>window.REPOSILITE_MESSAGE = '{{message}}';</script><link href=/js/app.js rel=preload as=script></head><body><noscript><strong>We're sorry but reposilite-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/app.js></script></body></html>
2 changes: 1 addition & 1 deletion reposilite-backend/src/main/resources/frontend/js/app.js

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions reposilite-backend/src/main/resources/reposilite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# ~~~~~~~~~~~~~~~~~~~~~~ #

# Hostname
hostname: ''
hostname: ""
# Port
port: 80

# List of supported Maven repositories.
# First directory on the list is the main repository.
repositories:
- releases
- snapshots
"releases"
- "snapshots"

# List of proxied repositories.
# Reposilite will search for an artifact in remote repositories listed below, if the requested artifact was not found.
Expand All @@ -26,4 +26,11 @@ deployEnabled: true
rewritePathsEnabled: true
# Require authentication of all requests (download, head requests)
# This option should be set to 'false', if you are hosting public repository
fullAuthEnabled: false
fullAuthEnabled: false

# Title displayed by frontend
title: "#onlypanda"
# Description displayed by frontend
description: "Public Maven repository hosted through the Reposilite"
# Accent color used by frontend
accentColor: "#009890"
9 changes: 8 additions & 1 deletion reposilite-backend/src/test/workspace/reposilite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ deployEnabled: true
rewritePathsEnabled: true
# Require authentication of all requests (download, head requests)
# This option should be set to 'false', if you are hosting public repository
fullAuthEnabled: false
fullAuthEnabled: false

# Title displayed by frontend
title: "#onlypanda-custom"
# Description displayed by frontend
description: "Public Maven repository hosted through the Reposilite - custom"
# Accent color used by frontend
accentColor: "#008000"
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
<?xml version='1.0' encoding='UTF-8'?><!--
~ Copyright (c) 2020 Dzikoysk
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<metadata><groupId>org.panda-lang</groupId><artifactId>reposilite-test</artifactId><version/><versioning><release>1.0.0-SNAPSHOT</release><latest>1.0.0-SNAPSHOT</latest><snapshot/><lastUpdated>20200518095524</lastUpdated><versions><version>1.0.0-SNAPSHOT</version></versions></versioning></metadata>
<metadata><groupId>org.panda-lang</groupId><artifactId>reposilite-test</artifactId><versioning><release>1.0.0-SNAPSHOT</release><latest>1.0.0-SNAPSHOT</latest><lastUpdated>20200526104801</lastUpdated><versions><version>1.0.0-SNAPSHOT</version></versions></versioning></metadata>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d41d8cd98f00b204e9800998ecf8427e
74be16979710d4c4e7c6647856088456
Original file line number Diff line number Diff line change
@@ -1 +1 @@
da39a3ee5e6b4b0d3255bfef95601890afd80709
10a34637ad661d98ba3344717656fcc76209c2f8
30 changes: 4 additions & 26 deletions reposilite-backend/src/test/workspace/stats.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
!!org.panda_lang.reposilite.stats.StatsEntity
"records":
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0-sources.jar.md5": !!int "1"
"/releases/org/panda-lang/reposilite-parent/2.5.0/reposilite-parent-2.5.0.pom.sha1": !!int "1"
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0-sources.jar": !!int "1"
"/releases/brianbb/jpastebin/1.0.0/jpastebin-1.0.0.jar": !!int "4"
"/releases/org/panda-lang/reposilite/maven-metadata.xml": !!int "3"
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0.jar.md5": !!int "1"
"/favicon.ico": !!int "2"
"/": !!int "7"
"/releases/org/panda-lang/reposilite-parent/maven-metadata.xml": !!int "3"
"/releases/org/panda-lang/reposilite-parent/2.5.0/reposilite-parent-2.5.0.pom.md5": !!int "1"
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0.pom": !!int "1"
"/api/x": !!int "1"
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0.pom.sha1": !!int "1"
"/releases/org/panda-lang/reposilite/maven-metadata.xml.md5": !!int "1"
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0.pom.md5": !!int "1"
"/xd": !!int "2"
"/releases/org/panda-lang/reposilite/maven-metadata.xml.sha1": !!int "3"
"/org/panda-lang/reposilite/latest": !!int "1"
"/org/panda-lang/reposilite-test/x/maven-metadata.xml": !!int "1"
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0.jar.sha1": !!int "1"
"/org/panda-lang/reposilite/2.4.0/reposilite-2.4.0.jar": !!int "1"
"/releases/org/panda-lang/reposilite-parent/maven-metadata.xml.sha1": !!int "3"
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0.jar": !!int "1"
"/releases/org/panda-lang/reposilite-parent/2.5.0/reposilite-parent-2.5.0.pom": !!int "2"
"/releases/org/panda-lang/reposilite-parent/maven-metadata.xml.md5": !!int "1"
"/releases/org/panda-lang/reposilite/2.5.0/reposilite-2.5.0-sources.jar.sha1": !!int "1"
"/api/configuration": !!int "1"
"/": !!int "1"
"/api/": !!int "1"
"/js/app.js": !!int "1"
4 changes: 3 additions & 1 deletion reposilite-frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<title>Reposilite</title>
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@300;500&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
<script>window.REPOSILITE_MESSAGE = '{{message}}'</script>
<script>
window.REPOSILITE_MESSAGE = '{{message}}';
</script>
</head>
<body>
<noscript>
Expand Down
10 changes: 8 additions & 2 deletions reposilite-frontend/src/components/Wave.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
svg.w-full.h-264.lg_h-168(viewBox="0 0 1080 640" preserveAspectRatio="none")
path(
fill="#009890"
:fill="this.accentColor"
fill-opacity="1"
d=" \
M 0,260 \
Expand All @@ -20,4 +20,10 @@
L 0,0 \
Z \
")
</template>
</template>

<script>
export default {
props: [ 'accentColor' ]
}
</script>

0 comments on commit 9b1239c

Please sign in to comment.