From 0b4095b969bc965ca0500d05dcca6987072d4168 Mon Sep 17 00:00:00 2001 From: David Russell Date: Fri, 20 Oct 2017 13:30:00 +0700 Subject: [PATCH] Added Runtime service to centralize config access. --- app/Module.java | 2 + .../gitpitch/controllers/AuthController.java | 147 ------------------ .../gitpitch/controllers/PitchController.java | 39 ++--- app/com/gitpitch/git/GRSManager.java | 10 +- app/com/gitpitch/policies/Dependencies.java | 24 +-- app/com/gitpitch/policies/Runtime.java | 71 +++++++++ app/com/gitpitch/services/DiskService.java | 12 +- app/com/gitpitch/services/GitService.java | 12 +- app/com/gitpitch/services/OfflineService.java | 24 ++- app/com/gitpitch/services/PrintService.java | 12 +- app/com/gitpitch/utils/GitRepoRenderer.java | 19 +-- 11 files changed, 143 insertions(+), 229 deletions(-) delete mode 100644 app/com/gitpitch/controllers/AuthController.java create mode 100644 app/com/gitpitch/policies/Runtime.java diff --git a/app/Module.java b/app/Module.java index 8c2bcda..9ece903 100644 --- a/app/Module.java +++ b/app/Module.java @@ -30,6 +30,7 @@ import com.gitpitch.models.MarkdownModel; import com.gitpitch.services.*; import com.gitpitch.policies.CacheTimeout; import com.gitpitch.policies.Dependencies; +import com.gitpitch.policies.Runtime; import com.gitpitch.executors.FrontEndThreads; import com.gitpitch.executors.BackEndThreads; import com.google.inject.AbstractModule; @@ -67,6 +68,7 @@ public class Module extends AbstractModule { bind(BackEndThreads.class).asEagerSingleton(); bind(Dependencies.class).asEagerSingleton(); bind(CacheTimeout.class).asEagerSingleton(); + bind(Runtime.class).asEagerSingleton(); install(new FactoryModuleBuilder().implement(Markdown.class, MarkdownModel.class) .build(MarkdownModelFactory.class)); } diff --git a/app/com/gitpitch/controllers/AuthController.java b/app/com/gitpitch/controllers/AuthController.java deleted file mode 100644 index 296c811..0000000 --- a/app/com/gitpitch/controllers/AuthController.java +++ /dev/null @@ -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 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"; -} diff --git a/app/com/gitpitch/controllers/PitchController.java b/app/com/gitpitch/controllers/PitchController.java index 14c6780..646bb91 100644 --- a/app/com/gitpitch/controllers/PitchController.java +++ b/app/com/gitpitch/controllers/PitchController.java @@ -32,11 +32,10 @@ import com.gitpitch.models.SlideshowModel; import com.gitpitch.services.PitchService; import com.gitpitch.oembed.PitchEmbed; import com.gitpitch.policies.Dependencies; +import com.gitpitch.policies.Runtime; import com.gitpitch.utils.GitRepoRenderer; import com.gitpitch.utils.PitchParams; import com.gitpitch.utils.RFE; -import play.Configuration; -import play.Environment; import play.Logger; import play.Logger.ALogger; import play.libs.Json; @@ -60,29 +59,21 @@ public class PitchController extends Controller { private final PitchService pitchService; private final FrontEndThreads frontEndThreads; private final Dependencies deps; + private final Runtime runtime; private final GRSManager grsManager; - private final Configuration cfg; - private final WSClient ws; - private final Environment env; - private final String gaToken; @Inject public PitchController(PitchService pitchService, FrontEndThreads frontEndThreads, Dependencies deps, - GRSManager grsManager, - Configuration cfg, - WSClient ws, - Environment env) { + Runtime runtime, + GRSManager grsManager) { this.pitchService = pitchService; this.frontEndThreads = frontEndThreads; this.deps = deps; + this.runtime = runtime; 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(); GitRepoRenderer rndr = - GitRepoRenderer.build(pp, grm, cfg, grsManager.listGRS()); + GitRepoRenderer.build(pp, grm, runtime, grsManager.listGRS()); SlideshowModel ssm = ssmo.get(); /* * Clone cached SlideshowModel in order to adjust for any @@ -148,7 +139,7 @@ public class PitchController extends Controller { return CompletableFuture.completedFuture( ok(com.gitpitch.views.html.Slideshow.render(ssm, rndr, deps, - gaToken, isOffline, serverPrinting, webPrinting))); + gaToken(), isOffline, serverPrinting, webPrinting))); } else { return CompletableFuture.supplyAsync(() -> { @@ -159,7 +150,7 @@ public class PitchController extends Controller { .thenApply(repoFetched -> { GitRepoRenderer rndr = - GitRepoRenderer.build(pp, repoFetched, cfg, + GitRepoRenderer.build(pp, repoFetched, runtime, grsManager.listGRS()); if (ssmo.isPresent()) { @@ -179,7 +170,7 @@ public class PitchController extends Controller { */ ssm = ssm.clone(pp); return ok(com.gitpitch.views.html.Slideshow.render(ssm, - rndr, deps, gaToken, + rndr, deps, gaToken(), isOffline, serverPrinting, webPrinting)); } else { @@ -195,7 +186,7 @@ public class PitchController extends Controller { log.info("slideshow: [ yaml, fetchd, online ] {}", pp); return ok(com.gitpitch.views.html.Slideshow.render(ssm, - rndr, deps, gaToken, + rndr, deps, gaToken(), isOffline, serverPrinting, webPrinting)); } @@ -274,7 +265,7 @@ public class PitchController extends Controller { GitRepoModel grm = grmo.orElse(null); GitRepoRenderer rndr = - GitRepoRenderer.build(pp, grm, cfg, grsManager.listGRS()); + GitRepoRenderer.build(pp, grm, runtime, grsManager.listGRS()); return CompletableFuture.completedFuture( ok(com.gitpitch.views.html.Home.render(rndr, @@ -305,7 +296,7 @@ public class PitchController extends Controller { GitRepoModel grm = grmo.orElse(null); GitRepoRenderer rndr = - GitRepoRenderer.build(pp, grm, cfg, grsManager.listGRS()); + GitRepoRenderer.build(pp, grm, runtime, grsManager.listGRS()); return CompletableFuture.completedFuture( ok(com.gitpitch.views.html.Git.render(rndr, deps, isOffline))); @@ -335,7 +326,7 @@ public class PitchController extends Controller { GitRepoModel grm = grmo.orElse(null); GitRepoRenderer rndr = - GitRepoRenderer.build(pp, grm, cfg, grsManager.listGRS()); + GitRepoRenderer.build(pp, grm, runtime, grsManager.listGRS()); String fixedTheme = null; if(ssmo.isPresent()) { fixedTheme = ssmo.get().fixedTheme() ? ssmo.get().fetchTheme() : null; @@ -531,6 +522,10 @@ public class PitchController extends Controller { return isChrome; } + private String gaToken() { + return runtime.config("gitpitch.google.analytics.token"); + } + private static final String PITCHME_PRINT_ERROR = "GitPitch Slideshow print service temporarily unavailable."; private static final String PITCHME_OFFLINE_ERROR = diff --git a/app/com/gitpitch/git/GRSManager.java b/app/com/gitpitch/git/GRSManager.java index 473ce96..ea5a061 100644 --- a/app/com/gitpitch/git/GRSManager.java +++ b/app/com/gitpitch/git/GRSManager.java @@ -25,11 +25,11 @@ package com.gitpitch.git; import com.gitpitch.git.vendors.*; import com.gitpitch.services.DiskService; +import com.gitpitch.policies.Runtime; import com.gitpitch.utils.PitchParams; import java.util.*; import java.util.stream.Collectors; import javax.inject.*; -import play.Configuration; import play.Logger; import play.Logger.ALogger; @@ -45,13 +45,13 @@ public class GRSManager { private final Logger.ALogger log = Logger.of(this.getClass()); private final DiskService diskService; + private final Runtime runtime; private final GitHub gitHubService; private final GitLab gitLabService; private final BitBucket bitBucketService; private final Gitea giteaService; private final Gogs gogsService; private final GitBucket gitBucketService; - private final Configuration cfg; private final Map grsStore = new HashMap(); private GRS grsDefault; @@ -63,7 +63,7 @@ public class GRSManager { Gitea giteaService, Gogs gogsService, GitBucket gitBucketService, - Configuration cfg) { + Runtime runtime) { this.diskService = diskService; @@ -85,9 +85,9 @@ public class GRSManager { this.gitBucketService = gitBucketService; 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> grsCfgList = (List>) grsCfg; GRS fallback = GRS.build(GRS_FALLBACK); diff --git a/app/com/gitpitch/policies/Dependencies.java b/app/com/gitpitch/policies/Dependencies.java index 02fccd7..b7cb99a 100644 --- a/app/com/gitpitch/policies/Dependencies.java +++ b/app/com/gitpitch/policies/Dependencies.java @@ -23,7 +23,7 @@ */ package com.gitpitch.policies; -import play.Configuration; +import com.gitpitch.policies.Runtime; import javax.inject.*; /* @@ -32,7 +32,7 @@ import javax.inject.*; @Singleton public final class Dependencies { - private final Configuration cfg; + private final Runtime runtime; private final String cdn; private final String revealjsVersion; private final String bootstrapVersion; @@ -43,17 +43,17 @@ public final class Dependencies { private final Boolean highlightPluginEnabled; @Inject - public Dependencies(Configuration cfg) { - this.cfg = cfg; - this.cdn = cfg.getString("gitpitch.dependency.cdn"); - this.revealjsVersion = cfg.getString("gitpitch.dependency.revealjs"); - this.bootstrapVersion = cfg.getString("gitpitch.dependency.bootstrap"); - this.jqueryVersion = cfg.getString("gitpitch.dependency.jquery"); - this.fontawesomeVersion = cfg.getString("gitpitch.dependency.fontawesome"); - this.octiconsVersion = cfg.getString("gitpitch.dependency.octicons"); - this.highlightjsVersion = cfg.getString("gitpitch.dependency.highlightjs"); + public Dependencies(Runtime runtime) { + this.runtime = runtime; + this.cdn = runtime.config("gitpitch.dependency.cdn"); + this.revealjsVersion = runtime.config("gitpitch.dependency.revealjs"); + this.bootstrapVersion = runtime.config("gitpitch.dependency.bootstrap"); + this.jqueryVersion = runtime.config("gitpitch.dependency.jquery"); + this.fontawesomeVersion = runtime.config("gitpitch.dependency.fontawesome"); + this.octiconsVersion = runtime.config("gitpitch.dependency.octicons"); + this.highlightjsVersion = runtime.config("gitpitch.dependency.highlightjs"); this.highlightPluginEnabled = - cfg.getBoolean("gitpitch.dependency.highlight.plugin", false); + runtime.configBool("gitpitch.dependency.highlight.plugin", false); } public String revealjs(boolean offline, String versionOverride) { diff --git a/app/com/gitpitch/policies/Runtime.java b/app/com/gitpitch/policies/Runtime.java new file mode 100644 index 0000000..8edb1ef --- /dev/null +++ b/app/com/gitpitch/policies/Runtime.java @@ -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(); + } + +} diff --git a/app/com/gitpitch/services/DiskService.java b/app/com/gitpitch/services/DiskService.java index d89251a..b84aad4 100644 --- a/app/com/gitpitch/services/DiskService.java +++ b/app/com/gitpitch/services/DiskService.java @@ -27,9 +27,9 @@ import com.gitpitch.git.GRS; import com.gitpitch.git.GRSService; import com.gitpitch.git.GRSManager; import com.gitpitch.services.WebService; +import com.gitpitch.policies.Runtime; import com.gitpitch.utils.PitchParams; import org.apache.commons.io.FileUtils; -import play.Configuration; import play.Logger; import javax.inject.*; @@ -51,19 +51,19 @@ public class DiskService { private final String storage; private final String decktape; private final ShellService shellService; - private final Configuration configuration; + private final Runtime runtime; private final WebService ws; @Inject public DiskService(ShellService shellService, - Configuration configuration, + Runtime runtime, WebService ws) { this.shellService = shellService; - this.configuration = configuration; + this.runtime = runtime; this.ws = ws; - this.storage = configuration.getString("gitpitch.storage.home"); - this.decktape = configuration.getString("gitpitch.decktape.home"); + this.storage = runtime.config("gitpitch.storage.home"); + this.decktape = runtime.config("gitpitch.decktape.home"); } /* diff --git a/app/com/gitpitch/services/GitService.java b/app/com/gitpitch/services/GitService.java index 6efc31c..7268708 100644 --- a/app/com/gitpitch/services/GitService.java +++ b/app/com/gitpitch/services/GitService.java @@ -2,17 +2,17 @@ * 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 @@ -32,7 +32,6 @@ import com.gitpitch.models.SlideshowModel; import com.gitpitch.policies.CacheTimeout; import com.gitpitch.executors.BackEndThreads; import com.gitpitch.utils.*; -import play.Configuration; import play.Logger; import play.cache.*; import play.libs.ws.*; @@ -68,7 +67,6 @@ public class GitService { private final ComposableService composableService; private final WSClient wsClient; private final CacheApi pitchCache; - private final Configuration configuration; @Inject public GitService(GRSManager grsManager, @@ -80,8 +78,7 @@ public class GitService { MarkdownModelFactory markdownModelFactory, ComposableService composableService, WSClient wsClient, - CacheApi pitchCache, - Configuration configuration) { + CacheApi pitchCache) { this.grsManager = grsManager; this.diskService = diskService; @@ -93,7 +90,6 @@ public class GitService { this.composableService = composableService; this.wsClient = wsClient; this.pitchCache = pitchCache; - this.configuration = configuration; } /* diff --git a/app/com/gitpitch/services/OfflineService.java b/app/com/gitpitch/services/OfflineService.java index 04bfaec..0ad4fdc 100644 --- a/app/com/gitpitch/services/OfflineService.java +++ b/app/com/gitpitch/services/OfflineService.java @@ -28,12 +28,11 @@ import com.gitpitch.git.*; import com.gitpitch.models.MarkdownModel; import com.gitpitch.models.SlideshowModel; import com.gitpitch.executors.BackEndThreads; +import com.gitpitch.policies.Runtime; import com.gitpitch.utils.PitchParams; import com.gitpitch.utils.YAMLOptions; import com.gitpitch.utils.MarkdownRenderer; import org.apache.commons.io.FilenameUtils; -import play.Configuration; -import play.Environment; import play.Logger; import javax.inject.*; @@ -66,8 +65,7 @@ public class OfflineService { private final ShellService shellService; private final MarkdownModelFactory markdownModelFactory; private final BackEndThreads backEndThreads; - private final Configuration configuration; - private final Environment env; + private final Runtime runtime; @Inject public OfflineService(GRSManager grsManager, @@ -75,16 +73,14 @@ public class OfflineService { ShellService shellService, MarkdownModelFactory markdownModelFactory, BackEndThreads backEndThreads, - Configuration configuration, - Environment env) { + Runtime runtime) { this.grsManager = grsManager; this.diskService = diskService; this.shellService = shellService; this.markdownModelFactory = markdownModelFactory; this.backEndThreads = backEndThreads; - this.configuration = configuration; - this.env = env; + this.runtime = runtime; } /* @@ -306,7 +302,7 @@ public class OfflineService { Path destPath = diskService.ensure(zipRoot.resolve(ZIP_ASSETS_DIR)); - if(env.isProd()) { + if(runtime.isProd()) { Path jarPath = prodModeDependenciesJar(); if(jarPath.toFile().exists()) { @@ -466,7 +462,7 @@ public class OfflineService { log.debug("pruneYAMLDependencies: yOpts={}", yOpts); Path destPath = zipRoot.resolve(ZIP_ASSETS_DIR); String liveRevealVersion = - configuration.getString("gitpitch.dependency.revealjs"); + runtime.config("gitpitch.dependency.revealjs"); if(yOpts != null && yOpts.fetchRevealVersion(pp) != null) { liveRevealVersion = yOpts.fetchRevealVersion(pp); } @@ -588,22 +584,22 @@ public class OfflineService { } public boolean isEncrypted() { - return configuration.getBoolean("gitpitch.https"); + return runtime.configBool("gitpitch.https"); } public String hostname() { - return configuration.getString("gitpitch.hostname"); + return runtime.config("gitpitch.hostname"); } public Path devModeFixedDependencies() { String fixedAssets = - configuration.getString("gitpitch.offline.dev.fixed.assets.home"); + runtime.config("gitpitch.offline.dev.fixed.assets.home"); return Paths.get(fixedAssets); } public Path prodModeDependenciesJar() { String jarAssets = - configuration.getString("gitpitch.offline.prod.fixed.assets.home"); + runtime.config("gitpitch.offline.prod.fixed.assets.home"); return Paths.get(jarAssets); } diff --git a/app/com/gitpitch/services/PrintService.java b/app/com/gitpitch/services/PrintService.java index c182250..cdec168 100644 --- a/app/com/gitpitch/services/PrintService.java +++ b/app/com/gitpitch/services/PrintService.java @@ -26,7 +26,7 @@ package com.gitpitch.services; import com.gitpitch.models.MarkdownModel; import com.gitpitch.executors.BackEndThreads; import com.gitpitch.utils.PitchParams; -import play.Configuration; +import com.gitpitch.policies.Runtime; import play.Logger; import javax.inject.*; @@ -47,18 +47,18 @@ public class PrintService { private DiskService diskService; private ShellService shellService; private BackEndThreads backEndThreads; - private Configuration configuration; + private Runtime runtime; @Inject public PrintService(DiskService diskService, ShellService shellService, BackEndThreads backEndThreads, - Configuration configuration) { + Runtime runtime) { this.diskService = diskService; this.shellService = shellService; this.backEndThreads = backEndThreads; - this.configuration = configuration; + this.runtime = runtime; } /* @@ -183,11 +183,11 @@ public class PrintService { } public boolean isEncrypted() { - return configuration.getBoolean("gitpitch.https"); + return runtime.configBool("gitpitch.https"); } public String hostname() { - return configuration.getString("gitpitch.hostname"); + return runtime.config("gitpitch.hostname"); } private static final String PDF_PHANTOM = "./bin/phantomjs"; diff --git a/app/com/gitpitch/utils/GitRepoRenderer.java b/app/com/gitpitch/utils/GitRepoRenderer.java index 9248e8e..89cbe8c 100644 --- a/app/com/gitpitch/utils/GitRepoRenderer.java +++ b/app/com/gitpitch/utils/GitRepoRenderer.java @@ -26,8 +26,8 @@ package com.gitpitch.utils; import com.gitpitch.git.GRS; import com.gitpitch.git.vendors.*; import com.gitpitch.models.GitRepoModel; +import com.gitpitch.policies.Runtime; import com.gitpitch.utils.PitchParams; -import play.Configuration; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -44,7 +44,7 @@ public class GitRepoRenderer { private final PitchParams _pp; private final GitRepoModel _grm; - private Configuration _cfg; + private final Runtime runtime; private List _grsServices; /* * Relative URLs for view components. @@ -66,12 +66,12 @@ public class GitRepoRenderer { private GitRepoRenderer(PitchParams pp, GitRepoModel grm, - Configuration cfg, + Runtime runtime, List grsServices) { this._pp = pp; this._grm = grm; - this._cfg = cfg; + this.runtime = runtime; this._grsServices = grsServices; if (grm != null) { @@ -184,10 +184,10 @@ public class GitRepoRenderer { public static GitRepoRenderer build(PitchParams pp, GitRepoModel grm, - Configuration cfg, + Runtime runtime, List grsServices) { - return new GitRepoRenderer(pp, grm, cfg, grsServices); + return new GitRepoRenderer(pp, grm, runtime, grsServices); } /* @@ -581,7 +581,8 @@ public class GitRepoRenderer { } public List listThemes() { - List themesList = _cfg.getStringList("gitpitch.revealjs.themes"); + List themesList = + runtime.configStringList("gitpitch.revealjs.themes"); if(themesList == null || themesList.isEmpty()) { themesList = DEPLOY_THEMES; } @@ -604,11 +605,11 @@ public class GitRepoRenderer { } private boolean isEncrypted() { - return _cfg.getBoolean("gitpitch.https"); + return runtime.configBool("gitpitch.https"); } private String hostname() { - return _cfg.getString("gitpitch.hostname"); + return runtime.config("gitpitch.hostname"); } private static final String GIT_MASTER = "master";