K8s doesn't necessarily support DNS
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / sso / AAFSSO.java
index 75cddff..c9b21b2 100644 (file)
@@ -36,14 +36,24 @@ import java.util.Properties;
 
 import org.onap.aaf.cadi.Access.Level;
 import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.LocatorException;
 import org.onap.aaf.cadi.PropAccess;
 import org.onap.aaf.cadi.Symm;
 import org.onap.aaf.cadi.aaf.Defaults;
+import org.onap.aaf.cadi.aaf.v2_0.AAFCon;
+import org.onap.aaf.cadi.client.Future;
 import org.onap.aaf.cadi.config.Config;
 import org.onap.aaf.cadi.configure.ArtifactDir;
+import org.onap.aaf.cadi.locator.SingleEndpointLocator;
 import org.onap.aaf.cadi.util.MyConsole;
 import org.onap.aaf.cadi.util.SubStandardConsole;
 import org.onap.aaf.cadi.util.TheConsole;
+import org.onap.aaf.misc.env.APIException;
+import org.onap.aaf.misc.rosetta.env.RosettaDF;
+import org.onap.aaf.misc.rosetta.env.RosettaEnv;
+
+import locate.v1_1.Configuration;
+import locate.v1_1.Configuration.Props;
 
 public class AAFSSO {
     public static final MyConsole  cons = TheConsole.implemented() ? new TheConsole() : new SubStandardConsole();
@@ -135,7 +145,7 @@ public class AAFSSO {
             //    Config.setDefaultRealm(access);
     
             if (!dot_aaf_kf.exists()) {
-               // This will create, as required, or reuse
+                // This will create, as required, or reuse
                 ArtifactDir.getSymm(dot_aaf_kf);
             }
 
@@ -179,16 +189,20 @@ public class AAFSSO {
                 appID=null;
             }
             
+            String aaf_container_ns = "";
             if (appID!=null) {
-               diskprops.setProperty(Config.AAF_APPID,appID);
-               if( access.getProperty(Config.AAF_APPPASS)==null) {
-                       char[] password = cons.readPassword("Password for %s: ", appID);
-                       if(password.length>0) {
-                               String app_pass = access.encrypt(new String(password));
-                               access.setProperty(Config.AAF_APPPASS,app_pass);
-                               diskprops.setProperty(Config.AAF_APPPASS,app_pass);
-                       }
-               }
+                if( access.getProperty(Config.AAF_APPPASS)==null) {
+                    appID = user = cons.readLine("Deployer ID [%s]: ", user);
+                    access.setProperty(Config.AAF_APPID,appID);
+                    char[] password = cons.readPassword("Password for %s: ", user);
+                    if(password.length>0) {
+                        String app_pass = access.encrypt(new String(password));
+                           access.setProperty(Config.AAF_APPPASS,app_pass);
+                           diskprops.setProperty(Config.AAF_APPPASS,app_pass);
+                    }
+                    aaf_container_ns = cons.readLine("Container Namespace (blank if none)? [\"\"]: ", aaf_container_ns);
+                }
+                 diskprops.setProperty(Config.AAF_APPID,appID);
             }
             
             String keystore=access.getProperty(Config.CADI_KEYSTORE);
@@ -246,7 +260,7 @@ public class AAFSSO {
                 Symm decryptor = ArtifactDir.getSymm(dot_aaf_kf);
                 if (user == null) {
                     if (sso.exists()) {
-                        String cm_url = access.getProperty(Config.CM_URL); // SSO might overwrite...
+                        String cm_url = access.getProperty(Config.AAF_URL_CM); // SSO might overwrite...
                         FileInputStream fos = new FileInputStream(sso);
                         try {
                             access.load(fos);
@@ -256,7 +270,7 @@ public class AAFSSO {
                             access.setProperty(Config.AAF_APPPASS,
                                     access.encrypt(decryptor.depass(encrypted_pass)));
                             if (cm_url != null) { //Command line CM_URL Overwrites ssofile.
-                                access.setProperty(Config.CM_URL, cm_url);
+                                access.setProperty(Config.AAF_URL_CM, cm_url);
                             }
                         } finally {
                             fos.close();
@@ -298,36 +312,6 @@ public class AAFSSO {
                 err.append("-D" + Config.AAF_APPPASS + "=<passwd> ");
             }
             
-            String locateUrl = access.getProperty(Config.AAF_LOCATE_URL);
-            if (locateUrl==null) {
-                locateUrl=AAFSSO.cons.readLine("AAF Locator URL=https://");
-                if (locateUrl==null || locateUrl.length()==0) {
-                    err = new StringBuilder(Config.AAF_LOCATE_URL);
-                    err.append(" is required.");
-                    ok = false;
-                    return;
-                } else {
-                    locateUrl="https://"+locateUrl;
-                }
-                access.setProperty(Config.AAF_LOCATE_URL, locateUrl);
-                addProp(Config.AAF_LOCATE_URL, locateUrl);
-            }
-            
-            final String apiVersion = access.getProperty(Config.AAF_API_VERSION, Config.AAF_DEFAULT_API_VERSION);
-            final String aaf_root_ns = access.getProperty(Config.AAF_ROOT_NS);
-            String locateRoot;
-            if(aaf_root_ns==null) {
-               locateRoot=Defaults.AAF_ROOT;
-            } else {
-               locateRoot = Defaults.AAF_LOCATE_CONST + "/%CNS.%" + aaf_root_ns;
-            }
-            if(access.getProperty(Config.AAF_URL)==null) {
-               
-               access.setProperty(Config.AAF_URL, locateRoot+".service:"+apiVersion);
-            }
-            if(access.getProperty(Config.CM_URL)==null) {
-               access.setProperty(Config.CM_URL, locateRoot+".cm:"+apiVersion);
-            }
             String cadiLatitude = access.getProperty(Config.CADI_LATITUDE);
             if (cadiLatitude==null) {
                 System.out.println("# If you do not know your Global Coordinates, we suggest bing.com/maps");
@@ -381,6 +365,55 @@ public class AAFSSO {
             }
             ok = err==null;
         }
+        String locateUrl = Config.getAAFLocateUrl(access);
+        if (locateUrl==null) {
+            locateUrl=AAFSSO.cons.readLine("AAF Locator URL=https://");
+            if (locateUrl==null || locateUrl.length()==0) {
+                err = new StringBuilder(Config.AAF_LOCATE_URL);
+                err.append(" is required.");
+                ok = false;
+                return;
+            } else {
+                locateUrl="https://"+locateUrl;
+            }
+            access.setProperty(Config.AAF_LOCATE_URL, locateUrl);
+            addProp(Config.AAF_LOCATE_URL, locateUrl);
+            try {
+                if(access.getProperty(Config.AAF_URL)==null) {
+                    access.setProperty(Config.AAF_URL, Defaults.AAF_ROOT+".service:"+Defaults.AAF_VERSION);
+                }
+                AAFCon<?> aafCon = AAFCon.newInstance(access);
+                Future<Configuration> acf;
+                RosettaDF<Configuration> configDF = new RosettaEnv().newDataFactory(Configuration.class);
+                acf = aafCon.client(new SingleEndpointLocator(locateUrl))
+                        .read("/configure/"+user+"/aaf", configDF);
+                if (acf.get(aafCon.connTimeout)) {
+                    for(Props p : acf.value.getProps()) {
+                        addProp(p.getTag(),p.getValue());
+                        if(access.getProperty(p.getTag())==null) {
+                            access.setProperty(p.getTag(), p.getValue());
+                        }
+                    }
+                } else {
+                    access.log(Level.INFO,acf.body());
+                }
+            } catch (LocatorException | APIException e) {
+                access.log(e);
+            }
+        }
+        
+        final String apiVersion = access.getProperty(Config.AAF_API_VERSION, Config.AAF_DEFAULT_API_VERSION);
+        final String aaf_root_ns = access.getProperty(Config.AAF_ROOT_NS);
+        String locateRoot;
+        if(aaf_root_ns==null) {
+            locateRoot=Defaults.AAF_ROOT;
+        } else {
+            locateRoot = Defaults.AAF_LOCATE_CONST + "/%CNS." + aaf_root_ns;
+        }
+        if(access.getProperty(Config.AAF_URL)==null) {
+            access.setProperty(Config.AAF_URL, locateRoot+".service:"+apiVersion);
+        }
+
         writeFiles();
     }