package org.aslak.github.merge.model;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;

@Singleton @Startup
public class CurrentApp {

    private String clientId;
    private String clientSecret;
    
    public CurrentApp() {
    }
    
    public String getClientId() {
        return clientId;
    }
    
    public String getClientSecret() {
        return clientSecret;
    }
    
    @PostConstruct
    private void init() {
        String clientId = System.getenv("GITHUB_CLIENT_ID");
        String clientSecret = System.getenv("GITHUB_CLIENT_SECRET");

        if(clientId == null || clientId.isEmpty()) {
            throw new IllegalStateException("GITHUB_CLIENT_ID env variable is missing");
        }
        if(clientSecret == null || clientSecret.isEmpty()) {
            throw new IllegalStateException("GITHUB_CLIENT_SECRET env variable is missing");
        }
        this.clientId = clientId;
        this.clientSecret = clientSecret;
    }
}

@@ -173,16 +173,244 @@
 tApp %7B%0A%0A
+    private static final String GITHUB_CLIENT_SECRET = %22GITHUB_CLIENT_SECRET%22;%0A    private static final String GITHUB_CLIENT_ID = %22GITHUB_CLIENT_ID%22;%0A    private static final String MERGER_CALLBACK_URL = %22MERGER_CALLBACK_URL%22;%0A%0A
     priv
@@ -463,24 +463,56 @@
 Secret;%0A    
+private String baseCallbackUrl;%0A
 %0A    public 
@@ -528,28 +528,24 @@
 p() %7B%0A    %7D%0A
-    
 %0A    public 
@@ -594,28 +594,24 @@
 ntId;%0A    %7D%0A
-    
 %0A    public 
@@ -672,20 +672,96 @@
 ;%0A    %7D%0A
+%0A
     
+public String getBaseCallbackUrl() %7B%0A        return baseCallbackUrl;%0A    %7D%0A
 %0A    @Po
@@ -830,33 +830,32 @@
 = System.getenv(
-%22
 GITHUB_CLIENT_ID
@@ -854,17 +854,16 @@
 LIENT_ID
-%22
 );%0A     
@@ -901,17 +901,16 @@
 .getenv(
-%22
 GITHUB_C
@@ -921,17 +921,85 @@
 T_SECRET
-%22
+);%0A        String baseCallbackUrl = System.getenv(MERGER_CALLBACK_URL
 );%0A%0A    
@@ -1083,33 +1083,32 @@
 lStateException(
-%22
 GITHUB_CLIENT_ID
@@ -1107,16 +1107,20 @@
 LIENT_ID
+ + %22
  env var
@@ -1254,17 +1254,16 @@
 ception(
-%22
 GITHUB_C
@@ -1274,16 +1274,192 @@
 T_SECRET
+ + %22 env variable is missing%22);%0A        %7D%0A        if(baseCallbackUrl == null %7C%7C baseCallbackUrl.isEmpty()) %7B%0A            throw new IllegalStateException(MERGER_CALLBACK_URL + %22
  env var
@@ -1560,20 +1560,68 @@
 ientSecret;%0A
+        this.baseCallbackUrl = baseCallbackUrl;%0A
     %7D%0A%7D%0A

Add baseCalbackUrl as app configuration