mirror of
https://github.com/gitpitch/gitpitch.git
synced 2024-04-18 07:30:55 +08:00
Added Runtime service to centralize config access.
This commit is contained in:
parent
ac97fe1eb6
commit
0b4095b969
|
@ -30,6 +30,7 @@ import com.gitpitch.models.MarkdownModel;
|
||||||
import com.gitpitch.services.*;
|
import com.gitpitch.services.*;
|
||||||
import com.gitpitch.policies.CacheTimeout;
|
import com.gitpitch.policies.CacheTimeout;
|
||||||
import com.gitpitch.policies.Dependencies;
|
import com.gitpitch.policies.Dependencies;
|
||||||
|
import com.gitpitch.policies.Runtime;
|
||||||
import com.gitpitch.executors.FrontEndThreads;
|
import com.gitpitch.executors.FrontEndThreads;
|
||||||
import com.gitpitch.executors.BackEndThreads;
|
import com.gitpitch.executors.BackEndThreads;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
|
@ -67,6 +68,7 @@ public class Module extends AbstractModule {
|
||||||
bind(BackEndThreads.class).asEagerSingleton();
|
bind(BackEndThreads.class).asEagerSingleton();
|
||||||
bind(Dependencies.class).asEagerSingleton();
|
bind(Dependencies.class).asEagerSingleton();
|
||||||
bind(CacheTimeout.class).asEagerSingleton();
|
bind(CacheTimeout.class).asEagerSingleton();
|
||||||
|
bind(Runtime.class).asEagerSingleton();
|
||||||
install(new FactoryModuleBuilder().implement(Markdown.class, MarkdownModel.class)
|
install(new FactoryModuleBuilder().implement(Markdown.class, MarkdownModel.class)
|
||||||
.build(MarkdownModelFactory.class));
|
.build(MarkdownModelFactory.class));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016 David Russell
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.gitpitch.controllers;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.gitpitch.executors.FrontEndThreads;
|
|
||||||
import play.Configuration;
|
|
||||||
import play.Logger;
|
|
||||||
import play.Logger.ALogger;
|
|
||||||
import play.libs.ws.*;
|
|
||||||
import play.mvc.*;
|
|
||||||
import views.html.*;
|
|
||||||
|
|
||||||
import javax.inject.*;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.CompletionStage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GitHub OAuth controller for GitPitch service.
|
|
||||||
*/
|
|
||||||
public class AuthController extends Controller {
|
|
||||||
|
|
||||||
private final Logger.ALogger log = Logger.of(this.getClass());
|
|
||||||
|
|
||||||
private final FrontEndThreads frontEndThreads;
|
|
||||||
private final WSClient ws;
|
|
||||||
private final Configuration cfg;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public AuthController(FrontEndThreads frontEndThreads,
|
|
||||||
WSClient ws,
|
|
||||||
Configuration cfg) {
|
|
||||||
|
|
||||||
this.frontEndThreads = frontEndThreads;
|
|
||||||
this.ws = ws;
|
|
||||||
this.cfg = cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Generate GitHub OAuth Request.
|
|
||||||
*/
|
|
||||||
public Result authreq() {
|
|
||||||
|
|
||||||
String state = Long.toHexString(System.currentTimeMillis());
|
|
||||||
session("state", state);
|
|
||||||
|
|
||||||
String redirectPath = GITHUB_OAUTH +
|
|
||||||
"?client_id=" +
|
|
||||||
"xxx" +
|
|
||||||
"&scope=" +
|
|
||||||
"public_repo" +
|
|
||||||
"&state=" +
|
|
||||||
state;
|
|
||||||
|
|
||||||
return redirect(redirectPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletionStage<Result> authorized(String code, String state) {
|
|
||||||
|
|
||||||
log.debug("authorized: params code={}, state={}", code, state);
|
|
||||||
String sessionUser = session("user");
|
|
||||||
String sessionRepo = session("repo");
|
|
||||||
String sessionState = session("state");
|
|
||||||
log.debug("authorized: session.user={}", sessionUser);
|
|
||||||
log.debug("authorized: session.repo={}", sessionRepo);
|
|
||||||
log.debug("authorized: session.state={}", sessionState);
|
|
||||||
|
|
||||||
if (state != null && state.equals(sessionState)) {
|
|
||||||
|
|
||||||
WSRequest wsReq = ws.url(GITHUB_ACCESS)
|
|
||||||
.setHeader("Accept", "application/json")
|
|
||||||
.setQueryParameter("client_id", "xxx")
|
|
||||||
.setQueryParameter("client_secret", "xxx")
|
|
||||||
.setQueryParameter("code", code)
|
|
||||||
.setQueryParameter("state", state);
|
|
||||||
|
|
||||||
return wsReq.post(" ").thenCompose(authResp -> {
|
|
||||||
|
|
||||||
log.debug("authorized: status={}", authResp.getStatus());
|
|
||||||
|
|
||||||
String accessToken = null;
|
|
||||||
|
|
||||||
if (authResp.getStatus() == 200) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
JsonNode json = authResp.asJson();
|
|
||||||
|
|
||||||
accessToken = json.findPath("access_token").textValue();
|
|
||||||
String accessScope = json.findPath("scope").textValue();
|
|
||||||
String accessType = json.findPath("token_type").textValue();
|
|
||||||
log.debug("authorized: json access_token={}", accessToken);
|
|
||||||
log.debug("authorized: json scope={}", accessScope);
|
|
||||||
log.debug("authorized: json token_type={}", accessType);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception jex) {
|
|
||||||
log.warn("authorized: parsing json ex={}", jex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("authorized: returning accessToken={}", accessToken);
|
|
||||||
return CompletableFuture.completedFuture(accessToken);
|
|
||||||
|
|
||||||
}).handle((result, error) -> {
|
|
||||||
|
|
||||||
log.debug("authorized: handle result={}, error={}", result, error);
|
|
||||||
return ok("End-of-Auth");
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
log.debug("authorized: state={} != sessionState={}",
|
|
||||||
state, sessionState);
|
|
||||||
return CompletableFuture.completedFuture(ok("Failed to Authorize!"));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String GITHUB_OAUTH =
|
|
||||||
"https://github.com/login/oauth/authorize";
|
|
||||||
private static final String GITHUB_ACCESS =
|
|
||||||
"https://github.com/login/oauth/access_token";
|
|
||||||
private static final String GITHUB_OAUTH_CID = "client_id";
|
|
||||||
private static final String GITHUB_OAUTH_STATE = "state";
|
|
||||||
}
|
|
|
@ -32,11 +32,10 @@ import com.gitpitch.models.SlideshowModel;
|
||||||
import com.gitpitch.services.PitchService;
|
import com.gitpitch.services.PitchService;
|
||||||
import com.gitpitch.oembed.PitchEmbed;
|
import com.gitpitch.oembed.PitchEmbed;
|
||||||
import com.gitpitch.policies.Dependencies;
|
import com.gitpitch.policies.Dependencies;
|
||||||
|
import com.gitpitch.policies.Runtime;
|
||||||
import com.gitpitch.utils.GitRepoRenderer;
|
import com.gitpitch.utils.GitRepoRenderer;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
import com.gitpitch.utils.RFE;
|
import com.gitpitch.utils.RFE;
|
||||||
import play.Configuration;
|
|
||||||
import play.Environment;
|
|
||||||
import play.Logger;
|
import play.Logger;
|
||||||
import play.Logger.ALogger;
|
import play.Logger.ALogger;
|
||||||
import play.libs.Json;
|
import play.libs.Json;
|
||||||
|
@ -60,29 +59,21 @@ public class PitchController extends Controller {
|
||||||
private final PitchService pitchService;
|
private final PitchService pitchService;
|
||||||
private final FrontEndThreads frontEndThreads;
|
private final FrontEndThreads frontEndThreads;
|
||||||
private final Dependencies deps;
|
private final Dependencies deps;
|
||||||
|
private final Runtime runtime;
|
||||||
private final GRSManager grsManager;
|
private final GRSManager grsManager;
|
||||||
private final Configuration cfg;
|
|
||||||
private final WSClient ws;
|
|
||||||
private final Environment env;
|
|
||||||
private final String gaToken;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PitchController(PitchService pitchService,
|
public PitchController(PitchService pitchService,
|
||||||
FrontEndThreads frontEndThreads,
|
FrontEndThreads frontEndThreads,
|
||||||
Dependencies deps,
|
Dependencies deps,
|
||||||
GRSManager grsManager,
|
Runtime runtime,
|
||||||
Configuration cfg,
|
GRSManager grsManager) {
|
||||||
WSClient ws,
|
|
||||||
Environment env) {
|
|
||||||
|
|
||||||
this.pitchService = pitchService;
|
this.pitchService = pitchService;
|
||||||
this.frontEndThreads = frontEndThreads;
|
this.frontEndThreads = frontEndThreads;
|
||||||
this.deps = deps;
|
this.deps = deps;
|
||||||
|
this.runtime = runtime;
|
||||||
this.grsManager = grsManager;
|
this.grsManager = grsManager;
|
||||||
this.cfg = cfg;
|
|
||||||
this.ws = ws;
|
|
||||||
this.env = env;
|
|
||||||
this.gaToken = cfg.getString("gitpitch.google.analytics.token");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -138,7 +129,7 @@ public class PitchController extends Controller {
|
||||||
|
|
||||||
GitRepoModel grm = grmo.get();
|
GitRepoModel grm = grmo.get();
|
||||||
GitRepoRenderer rndr =
|
GitRepoRenderer rndr =
|
||||||
GitRepoRenderer.build(pp, grm, cfg, grsManager.listGRS());
|
GitRepoRenderer.build(pp, grm, runtime, grsManager.listGRS());
|
||||||
SlideshowModel ssm = ssmo.get();
|
SlideshowModel ssm = ssmo.get();
|
||||||
/*
|
/*
|
||||||
* Clone cached SlideshowModel in order to adjust for any
|
* Clone cached SlideshowModel in order to adjust for any
|
||||||
|
@ -148,7 +139,7 @@ public class PitchController extends Controller {
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(
|
return CompletableFuture.completedFuture(
|
||||||
ok(com.gitpitch.views.html.Slideshow.render(ssm, rndr, deps,
|
ok(com.gitpitch.views.html.Slideshow.render(ssm, rndr, deps,
|
||||||
gaToken, isOffline, serverPrinting, webPrinting)));
|
gaToken(), isOffline, serverPrinting, webPrinting)));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
@ -159,7 +150,7 @@ public class PitchController extends Controller {
|
||||||
.thenApply(repoFetched -> {
|
.thenApply(repoFetched -> {
|
||||||
|
|
||||||
GitRepoRenderer rndr =
|
GitRepoRenderer rndr =
|
||||||
GitRepoRenderer.build(pp, repoFetched, cfg,
|
GitRepoRenderer.build(pp, repoFetched, runtime,
|
||||||
grsManager.listGRS());
|
grsManager.listGRS());
|
||||||
|
|
||||||
if (ssmo.isPresent()) {
|
if (ssmo.isPresent()) {
|
||||||
|
@ -179,7 +170,7 @@ public class PitchController extends Controller {
|
||||||
*/
|
*/
|
||||||
ssm = ssm.clone(pp);
|
ssm = ssm.clone(pp);
|
||||||
return ok(com.gitpitch.views.html.Slideshow.render(ssm,
|
return ok(com.gitpitch.views.html.Slideshow.render(ssm,
|
||||||
rndr, deps, gaToken,
|
rndr, deps, gaToken(),
|
||||||
isOffline, serverPrinting, webPrinting));
|
isOffline, serverPrinting, webPrinting));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -195,7 +186,7 @@ public class PitchController extends Controller {
|
||||||
log.info("slideshow: [ yaml, fetchd, online ] {}", pp);
|
log.info("slideshow: [ yaml, fetchd, online ] {}", pp);
|
||||||
|
|
||||||
return ok(com.gitpitch.views.html.Slideshow.render(ssm,
|
return ok(com.gitpitch.views.html.Slideshow.render(ssm,
|
||||||
rndr, deps, gaToken,
|
rndr, deps, gaToken(),
|
||||||
isOffline, serverPrinting, webPrinting));
|
isOffline, serverPrinting, webPrinting));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +265,7 @@ public class PitchController extends Controller {
|
||||||
|
|
||||||
GitRepoModel grm = grmo.orElse(null);
|
GitRepoModel grm = grmo.orElse(null);
|
||||||
GitRepoRenderer rndr =
|
GitRepoRenderer rndr =
|
||||||
GitRepoRenderer.build(pp, grm, cfg, grsManager.listGRS());
|
GitRepoRenderer.build(pp, grm, runtime, grsManager.listGRS());
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(
|
return CompletableFuture.completedFuture(
|
||||||
ok(com.gitpitch.views.html.Home.render(rndr,
|
ok(com.gitpitch.views.html.Home.render(rndr,
|
||||||
|
@ -305,7 +296,7 @@ public class PitchController extends Controller {
|
||||||
|
|
||||||
GitRepoModel grm = grmo.orElse(null);
|
GitRepoModel grm = grmo.orElse(null);
|
||||||
GitRepoRenderer rndr =
|
GitRepoRenderer rndr =
|
||||||
GitRepoRenderer.build(pp, grm, cfg, grsManager.listGRS());
|
GitRepoRenderer.build(pp, grm, runtime, grsManager.listGRS());
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(
|
return CompletableFuture.completedFuture(
|
||||||
ok(com.gitpitch.views.html.Git.render(rndr, deps, isOffline)));
|
ok(com.gitpitch.views.html.Git.render(rndr, deps, isOffline)));
|
||||||
|
@ -335,7 +326,7 @@ public class PitchController extends Controller {
|
||||||
|
|
||||||
GitRepoModel grm = grmo.orElse(null);
|
GitRepoModel grm = grmo.orElse(null);
|
||||||
GitRepoRenderer rndr =
|
GitRepoRenderer rndr =
|
||||||
GitRepoRenderer.build(pp, grm, cfg, grsManager.listGRS());
|
GitRepoRenderer.build(pp, grm, runtime, grsManager.listGRS());
|
||||||
String fixedTheme = null;
|
String fixedTheme = null;
|
||||||
if(ssmo.isPresent()) {
|
if(ssmo.isPresent()) {
|
||||||
fixedTheme = ssmo.get().fixedTheme() ? ssmo.get().fetchTheme() : null;
|
fixedTheme = ssmo.get().fixedTheme() ? ssmo.get().fetchTheme() : null;
|
||||||
|
@ -531,6 +522,10 @@ public class PitchController extends Controller {
|
||||||
return isChrome;
|
return isChrome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String gaToken() {
|
||||||
|
return runtime.config("gitpitch.google.analytics.token");
|
||||||
|
}
|
||||||
|
|
||||||
private static final String PITCHME_PRINT_ERROR =
|
private static final String PITCHME_PRINT_ERROR =
|
||||||
"GitPitch Slideshow print service temporarily unavailable.";
|
"GitPitch Slideshow print service temporarily unavailable.";
|
||||||
private static final String PITCHME_OFFLINE_ERROR =
|
private static final String PITCHME_OFFLINE_ERROR =
|
||||||
|
|
|
@ -25,11 +25,11 @@ package com.gitpitch.git;
|
||||||
|
|
||||||
import com.gitpitch.git.vendors.*;
|
import com.gitpitch.git.vendors.*;
|
||||||
import com.gitpitch.services.DiskService;
|
import com.gitpitch.services.DiskService;
|
||||||
|
import com.gitpitch.policies.Runtime;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
import play.Configuration;
|
|
||||||
import play.Logger;
|
import play.Logger;
|
||||||
import play.Logger.ALogger;
|
import play.Logger.ALogger;
|
||||||
|
|
||||||
|
@ -45,13 +45,13 @@ public class GRSManager {
|
||||||
private final Logger.ALogger log = Logger.of(this.getClass());
|
private final Logger.ALogger log = Logger.of(this.getClass());
|
||||||
|
|
||||||
private final DiskService diskService;
|
private final DiskService diskService;
|
||||||
|
private final Runtime runtime;
|
||||||
private final GitHub gitHubService;
|
private final GitHub gitHubService;
|
||||||
private final GitLab gitLabService;
|
private final GitLab gitLabService;
|
||||||
private final BitBucket bitBucketService;
|
private final BitBucket bitBucketService;
|
||||||
private final Gitea giteaService;
|
private final Gitea giteaService;
|
||||||
private final Gogs gogsService;
|
private final Gogs gogsService;
|
||||||
private final GitBucket gitBucketService;
|
private final GitBucket gitBucketService;
|
||||||
private final Configuration cfg;
|
|
||||||
private final Map<String,GRS> grsStore = new HashMap<String,GRS>();
|
private final Map<String,GRS> grsStore = new HashMap<String,GRS>();
|
||||||
private GRS grsDefault;
|
private GRS grsDefault;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class GRSManager {
|
||||||
Gitea giteaService,
|
Gitea giteaService,
|
||||||
Gogs gogsService,
|
Gogs gogsService,
|
||||||
GitBucket gitBucketService,
|
GitBucket gitBucketService,
|
||||||
Configuration cfg) {
|
Runtime runtime) {
|
||||||
|
|
||||||
this.diskService = diskService;
|
this.diskService = diskService;
|
||||||
|
|
||||||
|
@ -85,9 +85,9 @@ public class GRSManager {
|
||||||
this.gitBucketService = gitBucketService;
|
this.gitBucketService = gitBucketService;
|
||||||
this.gitBucketService.init(this, diskService);
|
this.gitBucketService.init(this, diskService);
|
||||||
|
|
||||||
this.cfg = cfg;
|
this.runtime = runtime;
|
||||||
|
|
||||||
List grsCfg = cfg.getList("gitpitch.git.repo.services");
|
List grsCfg = runtime.configList("gitpitch.git.repo.services");
|
||||||
List<HashMap<String,String>> grsCfgList = (List<HashMap<String,String>>) grsCfg;
|
List<HashMap<String,String>> grsCfgList = (List<HashMap<String,String>>) grsCfg;
|
||||||
|
|
||||||
GRS fallback = GRS.build(GRS_FALLBACK);
|
GRS fallback = GRS.build(GRS_FALLBACK);
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package com.gitpitch.policies;
|
package com.gitpitch.policies;
|
||||||
|
|
||||||
import play.Configuration;
|
import com.gitpitch.policies.Runtime;
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -32,7 +32,7 @@ import javax.inject.*;
|
||||||
@Singleton
|
@Singleton
|
||||||
public final class Dependencies {
|
public final class Dependencies {
|
||||||
|
|
||||||
private final Configuration cfg;
|
private final Runtime runtime;
|
||||||
private final String cdn;
|
private final String cdn;
|
||||||
private final String revealjsVersion;
|
private final String revealjsVersion;
|
||||||
private final String bootstrapVersion;
|
private final String bootstrapVersion;
|
||||||
|
@ -43,17 +43,17 @@ public final class Dependencies {
|
||||||
private final Boolean highlightPluginEnabled;
|
private final Boolean highlightPluginEnabled;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Dependencies(Configuration cfg) {
|
public Dependencies(Runtime runtime) {
|
||||||
this.cfg = cfg;
|
this.runtime = runtime;
|
||||||
this.cdn = cfg.getString("gitpitch.dependency.cdn");
|
this.cdn = runtime.config("gitpitch.dependency.cdn");
|
||||||
this.revealjsVersion = cfg.getString("gitpitch.dependency.revealjs");
|
this.revealjsVersion = runtime.config("gitpitch.dependency.revealjs");
|
||||||
this.bootstrapVersion = cfg.getString("gitpitch.dependency.bootstrap");
|
this.bootstrapVersion = runtime.config("gitpitch.dependency.bootstrap");
|
||||||
this.jqueryVersion = cfg.getString("gitpitch.dependency.jquery");
|
this.jqueryVersion = runtime.config("gitpitch.dependency.jquery");
|
||||||
this.fontawesomeVersion = cfg.getString("gitpitch.dependency.fontawesome");
|
this.fontawesomeVersion = runtime.config("gitpitch.dependency.fontawesome");
|
||||||
this.octiconsVersion = cfg.getString("gitpitch.dependency.octicons");
|
this.octiconsVersion = runtime.config("gitpitch.dependency.octicons");
|
||||||
this.highlightjsVersion = cfg.getString("gitpitch.dependency.highlightjs");
|
this.highlightjsVersion = runtime.config("gitpitch.dependency.highlightjs");
|
||||||
this.highlightPluginEnabled =
|
this.highlightPluginEnabled =
|
||||||
cfg.getBoolean("gitpitch.dependency.highlight.plugin", false);
|
runtime.configBool("gitpitch.dependency.highlight.plugin", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String revealjs(boolean offline, String versionOverride) {
|
public String revealjs(boolean offline, String versionOverride) {
|
||||||
|
|
71
app/com/gitpitch/policies/Runtime.java
Normal file
71
app/com/gitpitch/policies/Runtime.java
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 David Russell
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.gitpitch.policies;
|
||||||
|
|
||||||
|
import play.Configuration;
|
||||||
|
import play.Environment;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.*;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* External dependency manager for the GitPitch server.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public final class Runtime {
|
||||||
|
|
||||||
|
private final Configuration cfg;
|
||||||
|
private final Environment env;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public Runtime(Configuration cfg,
|
||||||
|
Environment env) {
|
||||||
|
this.cfg = cfg;
|
||||||
|
this.env = env;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String config(String cid) {
|
||||||
|
return cfg.getString(cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List configList(String cid) {
|
||||||
|
return cfg.getList(cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List configStringList(String cid) {
|
||||||
|
return cfg.getStringList(cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean configBool(String cid) {
|
||||||
|
return cfg.getBoolean(cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean configBool(String cid, boolean defaultCfg) {
|
||||||
|
return cfg.getBoolean(cid, defaultCfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isProd() {
|
||||||
|
return env.isProd();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -27,9 +27,9 @@ import com.gitpitch.git.GRS;
|
||||||
import com.gitpitch.git.GRSService;
|
import com.gitpitch.git.GRSService;
|
||||||
import com.gitpitch.git.GRSManager;
|
import com.gitpitch.git.GRSManager;
|
||||||
import com.gitpitch.services.WebService;
|
import com.gitpitch.services.WebService;
|
||||||
|
import com.gitpitch.policies.Runtime;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import play.Configuration;
|
|
||||||
import play.Logger;
|
import play.Logger;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
@ -51,19 +51,19 @@ public class DiskService {
|
||||||
private final String storage;
|
private final String storage;
|
||||||
private final String decktape;
|
private final String decktape;
|
||||||
private final ShellService shellService;
|
private final ShellService shellService;
|
||||||
private final Configuration configuration;
|
private final Runtime runtime;
|
||||||
private final WebService ws;
|
private final WebService ws;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DiskService(ShellService shellService,
|
public DiskService(ShellService shellService,
|
||||||
Configuration configuration,
|
Runtime runtime,
|
||||||
WebService ws) {
|
WebService ws) {
|
||||||
|
|
||||||
this.shellService = shellService;
|
this.shellService = shellService;
|
||||||
this.configuration = configuration;
|
this.runtime = runtime;
|
||||||
this.ws = ws;
|
this.ws = ws;
|
||||||
this.storage = configuration.getString("gitpitch.storage.home");
|
this.storage = runtime.config("gitpitch.storage.home");
|
||||||
this.decktape = configuration.getString("gitpitch.decktape.home");
|
this.decktape = runtime.config("gitpitch.decktape.home");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -32,7 +32,6 @@ import com.gitpitch.models.SlideshowModel;
|
||||||
import com.gitpitch.policies.CacheTimeout;
|
import com.gitpitch.policies.CacheTimeout;
|
||||||
import com.gitpitch.executors.BackEndThreads;
|
import com.gitpitch.executors.BackEndThreads;
|
||||||
import com.gitpitch.utils.*;
|
import com.gitpitch.utils.*;
|
||||||
import play.Configuration;
|
|
||||||
import play.Logger;
|
import play.Logger;
|
||||||
import play.cache.*;
|
import play.cache.*;
|
||||||
import play.libs.ws.*;
|
import play.libs.ws.*;
|
||||||
|
@ -68,7 +67,6 @@ public class GitService {
|
||||||
private final ComposableService composableService;
|
private final ComposableService composableService;
|
||||||
private final WSClient wsClient;
|
private final WSClient wsClient;
|
||||||
private final CacheApi pitchCache;
|
private final CacheApi pitchCache;
|
||||||
private final Configuration configuration;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GitService(GRSManager grsManager,
|
public GitService(GRSManager grsManager,
|
||||||
|
@ -80,8 +78,7 @@ public class GitService {
|
||||||
MarkdownModelFactory markdownModelFactory,
|
MarkdownModelFactory markdownModelFactory,
|
||||||
ComposableService composableService,
|
ComposableService composableService,
|
||||||
WSClient wsClient,
|
WSClient wsClient,
|
||||||
CacheApi pitchCache,
|
CacheApi pitchCache) {
|
||||||
Configuration configuration) {
|
|
||||||
|
|
||||||
this.grsManager = grsManager;
|
this.grsManager = grsManager;
|
||||||
this.diskService = diskService;
|
this.diskService = diskService;
|
||||||
|
@ -93,7 +90,6 @@ public class GitService {
|
||||||
this.composableService = composableService;
|
this.composableService = composableService;
|
||||||
this.wsClient = wsClient;
|
this.wsClient = wsClient;
|
||||||
this.pitchCache = pitchCache;
|
this.pitchCache = pitchCache;
|
||||||
this.configuration = configuration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -28,12 +28,11 @@ import com.gitpitch.git.*;
|
||||||
import com.gitpitch.models.MarkdownModel;
|
import com.gitpitch.models.MarkdownModel;
|
||||||
import com.gitpitch.models.SlideshowModel;
|
import com.gitpitch.models.SlideshowModel;
|
||||||
import com.gitpitch.executors.BackEndThreads;
|
import com.gitpitch.executors.BackEndThreads;
|
||||||
|
import com.gitpitch.policies.Runtime;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
import com.gitpitch.utils.YAMLOptions;
|
import com.gitpitch.utils.YAMLOptions;
|
||||||
import com.gitpitch.utils.MarkdownRenderer;
|
import com.gitpitch.utils.MarkdownRenderer;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import play.Configuration;
|
|
||||||
import play.Environment;
|
|
||||||
import play.Logger;
|
import play.Logger;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
@ -66,8 +65,7 @@ public class OfflineService {
|
||||||
private final ShellService shellService;
|
private final ShellService shellService;
|
||||||
private final MarkdownModelFactory markdownModelFactory;
|
private final MarkdownModelFactory markdownModelFactory;
|
||||||
private final BackEndThreads backEndThreads;
|
private final BackEndThreads backEndThreads;
|
||||||
private final Configuration configuration;
|
private final Runtime runtime;
|
||||||
private final Environment env;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public OfflineService(GRSManager grsManager,
|
public OfflineService(GRSManager grsManager,
|
||||||
|
@ -75,16 +73,14 @@ public class OfflineService {
|
||||||
ShellService shellService,
|
ShellService shellService,
|
||||||
MarkdownModelFactory markdownModelFactory,
|
MarkdownModelFactory markdownModelFactory,
|
||||||
BackEndThreads backEndThreads,
|
BackEndThreads backEndThreads,
|
||||||
Configuration configuration,
|
Runtime runtime) {
|
||||||
Environment env) {
|
|
||||||
|
|
||||||
this.grsManager = grsManager;
|
this.grsManager = grsManager;
|
||||||
this.diskService = diskService;
|
this.diskService = diskService;
|
||||||
this.shellService = shellService;
|
this.shellService = shellService;
|
||||||
this.markdownModelFactory = markdownModelFactory;
|
this.markdownModelFactory = markdownModelFactory;
|
||||||
this.backEndThreads = backEndThreads;
|
this.backEndThreads = backEndThreads;
|
||||||
this.configuration = configuration;
|
this.runtime = runtime;
|
||||||
this.env = env;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -306,7 +302,7 @@ public class OfflineService {
|
||||||
Path destPath =
|
Path destPath =
|
||||||
diskService.ensure(zipRoot.resolve(ZIP_ASSETS_DIR));
|
diskService.ensure(zipRoot.resolve(ZIP_ASSETS_DIR));
|
||||||
|
|
||||||
if(env.isProd()) {
|
if(runtime.isProd()) {
|
||||||
|
|
||||||
Path jarPath = prodModeDependenciesJar();
|
Path jarPath = prodModeDependenciesJar();
|
||||||
if(jarPath.toFile().exists()) {
|
if(jarPath.toFile().exists()) {
|
||||||
|
@ -466,7 +462,7 @@ public class OfflineService {
|
||||||
log.debug("pruneYAMLDependencies: yOpts={}", yOpts);
|
log.debug("pruneYAMLDependencies: yOpts={}", yOpts);
|
||||||
Path destPath = zipRoot.resolve(ZIP_ASSETS_DIR);
|
Path destPath = zipRoot.resolve(ZIP_ASSETS_DIR);
|
||||||
String liveRevealVersion =
|
String liveRevealVersion =
|
||||||
configuration.getString("gitpitch.dependency.revealjs");
|
runtime.config("gitpitch.dependency.revealjs");
|
||||||
if(yOpts != null && yOpts.fetchRevealVersion(pp) != null) {
|
if(yOpts != null && yOpts.fetchRevealVersion(pp) != null) {
|
||||||
liveRevealVersion = yOpts.fetchRevealVersion(pp);
|
liveRevealVersion = yOpts.fetchRevealVersion(pp);
|
||||||
}
|
}
|
||||||
|
@ -588,22 +584,22 @@ public class OfflineService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEncrypted() {
|
public boolean isEncrypted() {
|
||||||
return configuration.getBoolean("gitpitch.https");
|
return runtime.configBool("gitpitch.https");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hostname() {
|
public String hostname() {
|
||||||
return configuration.getString("gitpitch.hostname");
|
return runtime.config("gitpitch.hostname");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path devModeFixedDependencies() {
|
public Path devModeFixedDependencies() {
|
||||||
String fixedAssets =
|
String fixedAssets =
|
||||||
configuration.getString("gitpitch.offline.dev.fixed.assets.home");
|
runtime.config("gitpitch.offline.dev.fixed.assets.home");
|
||||||
return Paths.get(fixedAssets);
|
return Paths.get(fixedAssets);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path prodModeDependenciesJar() {
|
public Path prodModeDependenciesJar() {
|
||||||
String jarAssets =
|
String jarAssets =
|
||||||
configuration.getString("gitpitch.offline.prod.fixed.assets.home");
|
runtime.config("gitpitch.offline.prod.fixed.assets.home");
|
||||||
return Paths.get(jarAssets);
|
return Paths.get(jarAssets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ package com.gitpitch.services;
|
||||||
import com.gitpitch.models.MarkdownModel;
|
import com.gitpitch.models.MarkdownModel;
|
||||||
import com.gitpitch.executors.BackEndThreads;
|
import com.gitpitch.executors.BackEndThreads;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
import play.Configuration;
|
import com.gitpitch.policies.Runtime;
|
||||||
import play.Logger;
|
import play.Logger;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
@ -47,18 +47,18 @@ public class PrintService {
|
||||||
private DiskService diskService;
|
private DiskService diskService;
|
||||||
private ShellService shellService;
|
private ShellService shellService;
|
||||||
private BackEndThreads backEndThreads;
|
private BackEndThreads backEndThreads;
|
||||||
private Configuration configuration;
|
private Runtime runtime;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PrintService(DiskService diskService,
|
public PrintService(DiskService diskService,
|
||||||
ShellService shellService,
|
ShellService shellService,
|
||||||
BackEndThreads backEndThreads,
|
BackEndThreads backEndThreads,
|
||||||
Configuration configuration) {
|
Runtime runtime) {
|
||||||
|
|
||||||
this.diskService = diskService;
|
this.diskService = diskService;
|
||||||
this.shellService = shellService;
|
this.shellService = shellService;
|
||||||
this.backEndThreads = backEndThreads;
|
this.backEndThreads = backEndThreads;
|
||||||
this.configuration = configuration;
|
this.runtime = runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -183,11 +183,11 @@ public class PrintService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEncrypted() {
|
public boolean isEncrypted() {
|
||||||
return configuration.getBoolean("gitpitch.https");
|
return runtime.configBool("gitpitch.https");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hostname() {
|
public String hostname() {
|
||||||
return configuration.getString("gitpitch.hostname");
|
return runtime.config("gitpitch.hostname");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String PDF_PHANTOM = "./bin/phantomjs";
|
private static final String PDF_PHANTOM = "./bin/phantomjs";
|
||||||
|
|
|
@ -26,8 +26,8 @@ package com.gitpitch.utils;
|
||||||
import com.gitpitch.git.GRS;
|
import com.gitpitch.git.GRS;
|
||||||
import com.gitpitch.git.vendors.*;
|
import com.gitpitch.git.vendors.*;
|
||||||
import com.gitpitch.models.GitRepoModel;
|
import com.gitpitch.models.GitRepoModel;
|
||||||
|
import com.gitpitch.policies.Runtime;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
import play.Configuration;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -44,7 +44,7 @@ public class GitRepoRenderer {
|
||||||
|
|
||||||
private final PitchParams _pp;
|
private final PitchParams _pp;
|
||||||
private final GitRepoModel _grm;
|
private final GitRepoModel _grm;
|
||||||
private Configuration _cfg;
|
private final Runtime runtime;
|
||||||
private List<GRS> _grsServices;
|
private List<GRS> _grsServices;
|
||||||
/*
|
/*
|
||||||
* Relative URLs for view components.
|
* Relative URLs for view components.
|
||||||
|
@ -66,12 +66,12 @@ public class GitRepoRenderer {
|
||||||
|
|
||||||
private GitRepoRenderer(PitchParams pp,
|
private GitRepoRenderer(PitchParams pp,
|
||||||
GitRepoModel grm,
|
GitRepoModel grm,
|
||||||
Configuration cfg,
|
Runtime runtime,
|
||||||
List<GRS> grsServices) {
|
List<GRS> grsServices) {
|
||||||
|
|
||||||
this._pp = pp;
|
this._pp = pp;
|
||||||
this._grm = grm;
|
this._grm = grm;
|
||||||
this._cfg = cfg;
|
this.runtime = runtime;
|
||||||
this._grsServices = grsServices;
|
this._grsServices = grsServices;
|
||||||
|
|
||||||
if (grm != null) {
|
if (grm != null) {
|
||||||
|
@ -184,10 +184,10 @@ public class GitRepoRenderer {
|
||||||
|
|
||||||
public static GitRepoRenderer build(PitchParams pp,
|
public static GitRepoRenderer build(PitchParams pp,
|
||||||
GitRepoModel grm,
|
GitRepoModel grm,
|
||||||
Configuration cfg,
|
Runtime runtime,
|
||||||
List<GRS> grsServices) {
|
List<GRS> grsServices) {
|
||||||
|
|
||||||
return new GitRepoRenderer(pp, grm, cfg, grsServices);
|
return new GitRepoRenderer(pp, grm, runtime, grsServices);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -581,7 +581,8 @@ public class GitRepoRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> listThemes() {
|
public List<String> listThemes() {
|
||||||
List<String> themesList = _cfg.getStringList("gitpitch.revealjs.themes");
|
List<String> themesList =
|
||||||
|
runtime.configStringList("gitpitch.revealjs.themes");
|
||||||
if(themesList == null || themesList.isEmpty()) {
|
if(themesList == null || themesList.isEmpty()) {
|
||||||
themesList = DEPLOY_THEMES;
|
themesList = DEPLOY_THEMES;
|
||||||
}
|
}
|
||||||
|
@ -604,11 +605,11 @@ public class GitRepoRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEncrypted() {
|
private boolean isEncrypted() {
|
||||||
return _cfg.getBoolean("gitpitch.https");
|
return runtime.configBool("gitpitch.https");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String hostname() {
|
private String hostname() {
|
||||||
return _cfg.getString("gitpitch.hostname");
|
return runtime.config("gitpitch.hostname");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String GIT_MASTER = "master";
|
private static final String GIT_MASTER = "master";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user