target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void getSettingsHandler() throws Exception { final HandlerFactory factory = new HandlerFactoryImpl(); final SettingsHandler handler = factory.getSettingsHandler(mojo); assertNotNull(handler); assertTrue(handler instanceof SettingsHandlerImpl); }
@Override public SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo) { return new SettingsHandlerImpl(mojo); }
HandlerFactoryImpl extends HandlerFactory { @Override public SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo) { return new SettingsHandlerImpl(mojo); } }
HandlerFactoryImpl extends HandlerFactory { @Override public SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo) { return new SettingsHandlerImpl(mojo); } }
HandlerFactoryImpl extends HandlerFactory { @Override public SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo) { return new SettingsHandlerImpl(mojo); } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); }
HandlerFactoryImpl extends HandlerFactory { @Override public SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo) { return new SettingsHandlerImpl(mojo); } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); static final String UNKNOWN_DEPLOYMENT_TYPE; }
@Test public void getDefaultArtifactHandler() throws AzureExecutionException { doReturn(project).when(mojo).getProject(); doReturn(DeploymentType.EMPTY).when(mojo).getDeploymentType(); project.setPackaging("jar"); final HandlerFactory factory = new HandlerFactoryImpl(); final ArtifactHandler handler = factory.getArtifactHandler(mojo); assertTrue(handler instanceof JarArtifactHandlerImpl); }
@Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } }
HandlerFactoryImpl extends HandlerFactory { @Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } } }
HandlerFactoryImpl extends HandlerFactory { @Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } } }
HandlerFactoryImpl extends HandlerFactory { @Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); }
HandlerFactoryImpl extends HandlerFactory { @Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); static final String UNKNOWN_DEPLOYMENT_TYPE; }
@Test public void getAutoArtifactHandler() throws AzureExecutionException { doReturn(project).when(mojo).getProject(); doReturn(DeploymentType.AUTO).when(mojo).getDeploymentType(); project.setPackaging("war"); final HandlerFactory factory = new HandlerFactoryImpl(); final ArtifactHandler handler = factory.getArtifactHandler(mojo); assertTrue(handler instanceof WarArtifactHandlerImpl); }
@Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } }
HandlerFactoryImpl extends HandlerFactory { @Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } } }
HandlerFactoryImpl extends HandlerFactory { @Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } } }
HandlerFactoryImpl extends HandlerFactory { @Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); }
HandlerFactoryImpl extends HandlerFactory { @Override public ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo) throws AzureExecutionException { switch (SchemaVersion.fromString(mojo.getSchemaVersion())) { case V1: return getV1ArtifactHandler(mojo); case V2: return getV2ArtifactHandler(mojo); default: throw new AzureExecutionException(SchemaVersion.UNKNOWN_SCHEMA_VERSION); } } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); static final String UNKNOWN_DEPLOYMENT_TYPE; }
@Test public void getDeploymentSlotHandler() throws AzureExecutionException { final HandlerFactory factory = new HandlerFactoryImpl(); final DeploymentSlotHandler handler = factory.getDeploymentSlotHandler(mojo); assertNotNull(handler); assertTrue(handler instanceof DeploymentSlotHandler); }
@Override public DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo) { return new DeploymentSlotHandler(mojo); }
HandlerFactoryImpl extends HandlerFactory { @Override public DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo) { return new DeploymentSlotHandler(mojo); } }
HandlerFactoryImpl extends HandlerFactory { @Override public DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo) { return new DeploymentSlotHandler(mojo); } }
HandlerFactoryImpl extends HandlerFactory { @Override public DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo) { return new DeploymentSlotHandler(mojo); } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); }
HandlerFactoryImpl extends HandlerFactory { @Override public DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo) { return new DeploymentSlotHandler(mojo); } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); static final String UNKNOWN_DEPLOYMENT_TYPE; }
@Test public void getArtifactHandlerFromPackaging() throws Exception { doReturn(project).when(mojo).getProject(); final HandlerFactoryImpl factory = new HandlerFactoryImpl(); assertTrue(factory.getArtifactHandlerBuilderFromPackaging(mojo).build() instanceof JarArtifactHandlerImpl); }
protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } }
HandlerFactoryImpl extends HandlerFactory { protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } }
HandlerFactoryImpl extends HandlerFactory { protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } }
HandlerFactoryImpl extends HandlerFactory { protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); }
HandlerFactoryImpl extends HandlerFactory { protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); static final String UNKNOWN_DEPLOYMENT_TYPE; }
@Test(expected = AzureExecutionException.class) public void getArtifactHandlerFromPackagingThrowException() throws AzureExecutionException { doReturn(project).when(mojo).getProject(); project.setPackaging("ear"); final HandlerFactoryImpl factory = new HandlerFactoryImpl(); factory.getArtifactHandlerBuilderFromPackaging(mojo); }
protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } }
HandlerFactoryImpl extends HandlerFactory { protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } }
HandlerFactoryImpl extends HandlerFactory { protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } }
HandlerFactoryImpl extends HandlerFactory { protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); }
HandlerFactoryImpl extends HandlerFactory { protected ArtifactHandlerBase.Builder getArtifactHandlerBuilderFromPackaging(final AbstractWebAppMojo mojo) throws AzureExecutionException { String packaging = mojo.getProject().getPackaging(); if (StringUtils.isEmpty(packaging)) { throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } packaging = packaging.toLowerCase(Locale.ENGLISH).trim(); switch (packaging) { case "war": return new WarArtifactHandlerImpl.Builder().warFile(mojo.getWarFile()) .contextPath(mojo.getPath()); case "jar": return new JarArtifactHandlerImpl.Builder().jarFile(mojo.getJarFile()); default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); static final String UNKNOWN_DEPLOYMENT_TYPE; }
@Test public void writeFunctionJsonFile() throws Exception { final PackageMojo mojo = getMojoFromPom(); final PackageMojo mojoSpy = spy(mojo); doReturn("target/azure-functions").when(mojoSpy).getDeploymentStagingDirectoryPath(); doNothing().when(mojoSpy).writeObjectToFile(isNull(), isNull(), isNotNull()); mojoSpy.writeFunctionJsonFile(null, "httpTrigger", null); }
protected void writeFunctionJsonFile(final ObjectWriter objectWriter, final String functionName, final FunctionConfiguration config) throws IOException { Log.info(SAVE_FUNCTION_JSON + functionName); final File functionJsonFile = Paths.get(getDeploymentStagingDirectoryPath(), functionName, FUNCTION_JSON).toFile(); writeObjectToFile(objectWriter, config, functionJsonFile); Log.info(SAVE_SUCCESS + functionJsonFile.getAbsolutePath()); }
PackageMojo extends AbstractFunctionMojo { protected void writeFunctionJsonFile(final ObjectWriter objectWriter, final String functionName, final FunctionConfiguration config) throws IOException { Log.info(SAVE_FUNCTION_JSON + functionName); final File functionJsonFile = Paths.get(getDeploymentStagingDirectoryPath(), functionName, FUNCTION_JSON).toFile(); writeObjectToFile(objectWriter, config, functionJsonFile); Log.info(SAVE_SUCCESS + functionJsonFile.getAbsolutePath()); } }
PackageMojo extends AbstractFunctionMojo { protected void writeFunctionJsonFile(final ObjectWriter objectWriter, final String functionName, final FunctionConfiguration config) throws IOException { Log.info(SAVE_FUNCTION_JSON + functionName); final File functionJsonFile = Paths.get(getDeploymentStagingDirectoryPath(), functionName, FUNCTION_JSON).toFile(); writeObjectToFile(objectWriter, config, functionJsonFile); Log.info(SAVE_SUCCESS + functionJsonFile.getAbsolutePath()); } }
PackageMojo extends AbstractFunctionMojo { protected void writeFunctionJsonFile(final ObjectWriter objectWriter, final String functionName, final FunctionConfiguration config) throws IOException { Log.info(SAVE_FUNCTION_JSON + functionName); final File functionJsonFile = Paths.get(getDeploymentStagingDirectoryPath(), functionName, FUNCTION_JSON).toFile(); writeObjectToFile(objectWriter, config, functionJsonFile); Log.info(SAVE_SUCCESS + functionJsonFile.getAbsolutePath()); } @Override List<Resource> getResources(); }
PackageMojo extends AbstractFunctionMojo { protected void writeFunctionJsonFile(final ObjectWriter objectWriter, final String functionName, final FunctionConfiguration config) throws IOException { Log.info(SAVE_FUNCTION_JSON + functionName); final File functionJsonFile = Paths.get(getDeploymentStagingDirectoryPath(), functionName, FUNCTION_JSON).toFile(); writeObjectToFile(objectWriter, config, functionJsonFile); Log.info(SAVE_SUCCESS + functionJsonFile.getAbsolutePath()); } @Override List<Resource> getResources(); static final String SEARCH_FUNCTIONS; static final String FOUND_FUNCTIONS; static final String NO_FUNCTIONS; static final String GENERATE_CONFIG; static final String GENERATE_SKIP; static final String GENERATE_DONE; static final String VALIDATE_CONFIG; static final String VALIDATE_SKIP; static final String VALIDATE_DONE; static final String SAVE_HOST_JSON; static final String SAVE_FUNCTION_JSONS; static final String SAVE_SKIP; static final String SAVE_FUNCTION_JSON; static final String SAVE_SUCCESS; static final String COPY_JARS; static final String COPY_SUCCESS; static final String INSTALL_EXTENSIONS; static final String SKIP_INSTALL_EXTENSIONS_HTTP; static final String INSTALL_EXTENSIONS_FINISH; static final String BUILD_SUCCESS; static final String FUNCTION_JSON; static final String HOST_JSON; static final String EXTENSION_BUNDLE; static final String EXTENSION_BUNDLE_ID; static final String SKIP_INSTALL_EXTENSIONS_BUNDLE; }
@Test public void getRuntimeStackFromString() { assertEquals(RuntimeStackUtils.getRuntimeStack("jre8", "tomcat 8.5"), RuntimeStack.TOMCAT_8_5_JRE8); assertEquals(RuntimeStackUtils.getRuntimeStack("java11", "TOMCAT 9.0"), RuntimeStack.TOMCAT_9_0_JAVA11); assertEquals(RuntimeStackUtils.getRuntimeStack("java11", null), RuntimeStack.JAVA_11_JAVA11); assertEquals(RuntimeStackUtils.getRuntimeStack("jre8", "jre8"), RuntimeStack.JAVA_8_JRE8); }
public static RuntimeStack getRuntimeStack(String javaVersion) { for (final RuntimeStack runtimeStack : getValidRuntimeStacks()) { if (runtimeStack.stack().equals("JAVA") && getJavaVersionFromRuntimeStack(runtimeStack).equalsIgnoreCase(javaVersion)) { return runtimeStack; } } return null; }
RuntimeStackUtils { public static RuntimeStack getRuntimeStack(String javaVersion) { for (final RuntimeStack runtimeStack : getValidRuntimeStacks()) { if (runtimeStack.stack().equals("JAVA") && getJavaVersionFromRuntimeStack(runtimeStack).equalsIgnoreCase(javaVersion)) { return runtimeStack; } } return null; } }
RuntimeStackUtils { public static RuntimeStack getRuntimeStack(String javaVersion) { for (final RuntimeStack runtimeStack : getValidRuntimeStacks()) { if (runtimeStack.stack().equals("JAVA") && getJavaVersionFromRuntimeStack(runtimeStack).equalsIgnoreCase(javaVersion)) { return runtimeStack; } } return null; } }
RuntimeStackUtils { public static RuntimeStack getRuntimeStack(String javaVersion) { for (final RuntimeStack runtimeStack : getValidRuntimeStacks()) { if (runtimeStack.stack().equals("JAVA") && getJavaVersionFromRuntimeStack(runtimeStack).equalsIgnoreCase(javaVersion)) { return runtimeStack; } } return null; } static String getJavaVersionFromRuntimeStack(RuntimeStack runtimeStack); static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack); static RuntimeStack getRuntimeStack(String javaVersion); static RuntimeStack getRuntimeStack(String javaVersion, String webContainer); static List<RuntimeStack> getValidRuntimeStacks(); static List<String> getValidWebContainer(String javaVersion); static BidiMap<String, String> getValidJavaVersions(); }
RuntimeStackUtils { public static RuntimeStack getRuntimeStack(String javaVersion) { for (final RuntimeStack runtimeStack : getValidRuntimeStacks()) { if (runtimeStack.stack().equals("JAVA") && getJavaVersionFromRuntimeStack(runtimeStack).equalsIgnoreCase(javaVersion)) { return runtimeStack; } } return null; } static String getJavaVersionFromRuntimeStack(RuntimeStack runtimeStack); static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack); static RuntimeStack getRuntimeStack(String javaVersion); static RuntimeStack getRuntimeStack(String javaVersion, String webContainer); static List<RuntimeStack> getValidRuntimeStacks(); static List<String> getValidWebContainer(String javaVersion); static BidiMap<String, String> getValidJavaVersions(); }
@Test public void getWebContainerFromRuntimeStack() { assertEquals(RuntimeStackUtils.getWebContainerFromRuntimeStack(RuntimeStack.TOMCAT_8_5_JAVA11), "TOMCAT 8.5"); assertEquals(RuntimeStackUtils.getWebContainerFromRuntimeStack(RuntimeStack.JAVA_8_JRE8), "jre8"); assertEquals(RuntimeStackUtils.getWebContainerFromRuntimeStack(RuntimeStack.JAVA_11_JAVA11), "java11"); }
public static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack) { final String stack = runtimeStack.stack(); final String version = runtimeStack.version(); return stack.equalsIgnoreCase("JAVA") ? version.split("-")[1] : stack + " " + version.split("-")[0]; }
RuntimeStackUtils { public static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack) { final String stack = runtimeStack.stack(); final String version = runtimeStack.version(); return stack.equalsIgnoreCase("JAVA") ? version.split("-")[1] : stack + " " + version.split("-")[0]; } }
RuntimeStackUtils { public static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack) { final String stack = runtimeStack.stack(); final String version = runtimeStack.version(); return stack.equalsIgnoreCase("JAVA") ? version.split("-")[1] : stack + " " + version.split("-")[0]; } }
RuntimeStackUtils { public static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack) { final String stack = runtimeStack.stack(); final String version = runtimeStack.version(); return stack.equalsIgnoreCase("JAVA") ? version.split("-")[1] : stack + " " + version.split("-")[0]; } static String getJavaVersionFromRuntimeStack(RuntimeStack runtimeStack); static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack); static RuntimeStack getRuntimeStack(String javaVersion); static RuntimeStack getRuntimeStack(String javaVersion, String webContainer); static List<RuntimeStack> getValidRuntimeStacks(); static List<String> getValidWebContainer(String javaVersion); static BidiMap<String, String> getValidJavaVersions(); }
RuntimeStackUtils { public static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack) { final String stack = runtimeStack.stack(); final String version = runtimeStack.version(); return stack.equalsIgnoreCase("JAVA") ? version.split("-")[1] : stack + " " + version.split("-")[0]; } static String getJavaVersionFromRuntimeStack(RuntimeStack runtimeStack); static String getWebContainerFromRuntimeStack(RuntimeStack runtimeStack); static RuntimeStack getRuntimeStack(String javaVersion); static RuntimeStack getRuntimeStack(String javaVersion, String webContainer); static List<RuntimeStack> getValidRuntimeStacks(); static List<String> getValidWebContainer(String javaVersion); static BidiMap<String, String> getValidJavaVersions(); }
@Test public void getOs() throws AzureExecutionException { final RuntimeSetting runtime = mock(RuntimeSetting.class); doReturn(runtime).when(mojo).getRuntime(); doReturn(true).when(runtime).isEmpty(); assertEquals(null, parser.getOs()); doReturn(false).when(runtime).isEmpty(); doReturn("windows").when(runtime).getOs(); assertEquals(OperatingSystemEnum.Windows, parser.getOs()); doReturn("linux").when(runtime).getOs(); assertEquals(OperatingSystemEnum.Linux, parser.getOs()); doReturn("docker").when(runtime).getOs(); assertEquals(OperatingSystemEnum.Docker, parser.getOs()); try { doReturn(null).when(runtime).getOs(); parser.getOs(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Pleas configure the <os> of <runtime> in pom.xml."); } try { doReturn("unknown-os").when(runtime).getOs(); parser.getOs(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The value of <os> is not correct, supported values are: windows, " + "linux and docker."); } }
@Override protected OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final RuntimeSetting runtime = mojo.getRuntime(); final String os = runtime.getOs(); if (runtime.isEmpty()) { return null; } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: return null; } }
V2ConfigurationParser extends ConfigurationParser { @Override protected OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final RuntimeSetting runtime = mojo.getRuntime(); final String os = runtime.getOs(); if (runtime.isEmpty()) { return null; } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: return null; } } }
V2ConfigurationParser extends ConfigurationParser { @Override protected OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final RuntimeSetting runtime = mojo.getRuntime(); final String os = runtime.getOs(); if (runtime.isEmpty()) { return null; } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: return null; } } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final RuntimeSetting runtime = mojo.getRuntime(); final String os = runtime.getOs(); if (runtime.isEmpty()) { return null; } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: return null; } } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final RuntimeSetting runtime = mojo.getRuntime(); final String os = runtime.getOs(); if (runtime.isEmpty()) { return null; } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: return null; } } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void getRegion() throws AzureExecutionException { doReturn("unknown-region").when(mojo).getRegion(); try { parser.getRegion(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The value of <region> is not supported, please correct it in pom.xml."); } doReturn(Region.US_WEST.name()).when(mojo).getRegion(); assertEquals(Region.US_WEST, parser.getRegion()); }
@Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); final String region = mojo.getRegion(); return Region.fromName(region); }
V2ConfigurationParser extends ConfigurationParser { @Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); final String region = mojo.getRegion(); return Region.fromName(region); } }
V2ConfigurationParser extends ConfigurationParser { @Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); final String region = mojo.getRegion(); return Region.fromName(region); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); final String region = mojo.getRegion(); return Region.fromName(region); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); final String region = mojo.getRegion(); return Region.fromName(region); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void getRuntimeStack() throws AzureExecutionException { doReturn(null).when(mojo).getRuntime(); assertNull(parser.getRuntimeStack()); final RuntimeSetting runtime = mock(RuntimeSetting.class); doReturn(true).when(runtime).isEmpty(); doReturn(runtime).when(mojo).getRuntime(); assertNull(parser.getRuntimeStack()); doReturn(false).when(runtime).isEmpty(); doReturn(RuntimeStack.TOMCAT_8_5_JRE8).when(runtime).getLinuxRuntime(); assertEquals(RuntimeStack.TOMCAT_8_5_JRE8, parser.getRuntimeStack()); doReturn(RuntimeStack.TOMCAT_9_0_JRE8).when(runtime).getLinuxRuntime(); assertEquals(RuntimeStack.TOMCAT_9_0_JRE8, parser.getRuntimeStack()); doReturn(RuntimeStack.JAVA_8_JRE8).when(runtime).getLinuxRuntime(); assertEquals(RuntimeStack.JAVA_8_JRE8, parser.getRuntimeStack()); }
@Override protected RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null || runtime.isEmpty()) { return null; } return runtime.getLinuxRuntime(); }
V2ConfigurationParser extends ConfigurationParser { @Override protected RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null || runtime.isEmpty()) { return null; } return runtime.getLinuxRuntime(); } }
V2ConfigurationParser extends ConfigurationParser { @Override protected RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null || runtime.isEmpty()) { return null; } return runtime.getLinuxRuntime(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null || runtime.isEmpty()) { return null; } return runtime.getLinuxRuntime(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null || runtime.isEmpty()) { return null; } return runtime.getLinuxRuntime(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void getImage() throws AzureExecutionException { doReturn(null).when(mojo).getRuntime(); try { parser.getImage(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Please configure the <runtime> in pom.xml."); } final RuntimeSetting runtime = mock(RuntimeSetting.class); doReturn("").when(runtime).getImage(); doReturn(runtime).when(mojo).getRuntime(); try { parser.getImage(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Please config the <image> of <runtime> in pom.xml."); } doReturn("imageName").when(runtime).getImage(); assertEquals("imageName", parser.getImage()); }
@Override protected String getImage() throws AzureExecutionException { validate(validator.validateImage()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getImage(); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getImage() throws AzureExecutionException { validate(validator.validateImage()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getImage(); } }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getImage() throws AzureExecutionException { validate(validator.validateImage()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getImage(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getImage() throws AzureExecutionException { validate(validator.validateImage()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getImage(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getImage() throws AzureExecutionException { validate(validator.validateImage()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getImage(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void getServerId() { assertNull(parser.getServerId()); final RuntimeSetting runtime = mock(RuntimeSetting.class); doReturn(runtime).when(mojo).getRuntime(); doReturn("serverId").when(runtime).getServerId(); assertEquals("serverId", parser.getServerId()); }
@Override protected String getServerId() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getServerId(); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getServerId() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getServerId(); } }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getServerId() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getServerId(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getServerId() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getServerId(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getServerId() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getServerId(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void getRegistryUrl() { assertNull(parser.getRegistryUrl()); final RuntimeSetting runtime = mock(RuntimeSetting.class); doReturn(runtime).when(mojo).getRuntime(); doReturn("serverId").when(runtime).getRegistryUrl(); assertEquals("serverId", parser.getRegistryUrl()); }
@Override protected String getRegistryUrl() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getRegistryUrl(); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getRegistryUrl() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getRegistryUrl(); } }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getRegistryUrl() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getRegistryUrl(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getRegistryUrl() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getRegistryUrl(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected String getRegistryUrl() { final RuntimeSetting runtime = mojo.getRuntime(); if (runtime == null) { return null; } return runtime.getRegistryUrl(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void getWebContainer() throws AzureExecutionException { doReturn(null).when(mojo).getRuntime(); try { parser.getWebContainer(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Pleas config the <runtime> in pom.xml."); } final RuntimeSetting runtime = mock(RuntimeSetting.class); doReturn(runtime).when(mojo).getRuntime(); doReturn("windows").when(runtime).getOs(); doReturn(null).when(runtime).getWebContainer(); try { parser.getWebContainer(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The configuration <webContainer> in pom.xml is not correct."); } doReturn(WebContainer.TOMCAT_8_5_NEWEST).when(runtime).getWebContainer(); assertEquals(WebContainer.TOMCAT_8_5_NEWEST, parser.getWebContainer()); }
@Override protected WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getWebContainer(); }
V2ConfigurationParser extends ConfigurationParser { @Override protected WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getWebContainer(); } }
V2ConfigurationParser extends ConfigurationParser { @Override protected WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getWebContainer(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getWebContainer(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getWebContainer(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void getJavaVersion() throws AzureExecutionException { doReturn(null).when(mojo).getRuntime(); try { parser.getJavaVersion(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Pleas config the <runtime> in pom.xml."); } final RuntimeSetting runtime = mock(RuntimeSetting.class); doReturn(runtime).when(mojo).getRuntime(); doReturn(null).when(runtime).getJavaVersion(); try { parser.getJavaVersion(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The configuration <javaVersion> in pom.xml is not correct."); } doReturn(JavaVersion.JAVA_8_NEWEST).when(runtime).getJavaVersion(); assertEquals(JavaVersion.JAVA_8_NEWEST, parser.getJavaVersion()); }
@Override protected JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getJavaVersion(); }
V2ConfigurationParser extends ConfigurationParser { @Override protected JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getJavaVersion(); } }
V2ConfigurationParser extends ConfigurationParser { @Override protected JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getJavaVersion(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getJavaVersion(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); final RuntimeSetting runtime = mojo.getRuntime(); return runtime.getJavaVersion(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void testGetSPCredentialsBadParameter() throws Exception { final AuthConfiguration config = new AuthConfiguration(); try { AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(config); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } try { config.setClient("client_id"); AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(config); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } try { config.setTenant("tenant_id"); AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(config); fail("Should throw exception when there is no key and no certificate"); } catch (InvalidConfigurationException ex) { } try { config.setKey("key"); assertNotNull(AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(config)); } catch (IllegalArgumentException ex) { fail("Should not throw IAE"); } try { config.setKey(null); config.setCertificate(this.getClass().getResource("/test.pem").getFile()); assertNotNull(AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(config)); config.setCertificatePassword("pass1"); assertNotNull(AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(config)); } catch (IllegalArgumentException ex) { fail("Should not throw IAE"); } }
static AzureTokenCredentials getAzureServicePrincipleCredentials(AuthConfiguration config) throws InvalidConfigurationException, IOException { if (StringUtils.isBlank(config.getClient())) { throw new IllegalArgumentException("'Client Id' of your service principal is not configured."); } if (StringUtils.isBlank(config.getTenant())) { throw new IllegalArgumentException("'Tenant Id' of your service principal is not configured."); } final AzureEnvironment env = AzureAuthHelper.getAzureEnvironment(config.getEnvironment()); if (StringUtils.isNotBlank(config.getCertificate())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), FileUtils.readFileToByteArray(new File(config.getCertificate())), config.getCertificatePassword(), env); } else if (StringUtils.isNotBlank(config.getKey())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), config.getKey(), env); } throw new InvalidConfigurationException("Invalid auth configuration, either 'key' or 'certificate' is required."); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getAzureServicePrincipleCredentials(AuthConfiguration config) throws InvalidConfigurationException, IOException { if (StringUtils.isBlank(config.getClient())) { throw new IllegalArgumentException("'Client Id' of your service principal is not configured."); } if (StringUtils.isBlank(config.getTenant())) { throw new IllegalArgumentException("'Tenant Id' of your service principal is not configured."); } final AzureEnvironment env = AzureAuthHelper.getAzureEnvironment(config.getEnvironment()); if (StringUtils.isNotBlank(config.getCertificate())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), FileUtils.readFileToByteArray(new File(config.getCertificate())), config.getCertificatePassword(), env); } else if (StringUtils.isNotBlank(config.getKey())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), config.getKey(), env); } throw new InvalidConfigurationException("Invalid auth configuration, either 'key' or 'certificate' is required."); } }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getAzureServicePrincipleCredentials(AuthConfiguration config) throws InvalidConfigurationException, IOException { if (StringUtils.isBlank(config.getClient())) { throw new IllegalArgumentException("'Client Id' of your service principal is not configured."); } if (StringUtils.isBlank(config.getTenant())) { throw new IllegalArgumentException("'Tenant Id' of your service principal is not configured."); } final AzureEnvironment env = AzureAuthHelper.getAzureEnvironment(config.getEnvironment()); if (StringUtils.isNotBlank(config.getCertificate())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), FileUtils.readFileToByteArray(new File(config.getCertificate())), config.getCertificatePassword(), env); } else if (StringUtils.isNotBlank(config.getKey())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), config.getKey(), env); } throw new InvalidConfigurationException("Invalid auth configuration, either 'key' or 'certificate' is required."); } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getAzureServicePrincipleCredentials(AuthConfiguration config) throws InvalidConfigurationException, IOException { if (StringUtils.isBlank(config.getClient())) { throw new IllegalArgumentException("'Client Id' of your service principal is not configured."); } if (StringUtils.isBlank(config.getTenant())) { throw new IllegalArgumentException("'Tenant Id' of your service principal is not configured."); } final AzureEnvironment env = AzureAuthHelper.getAzureEnvironment(config.getEnvironment()); if (StringUtils.isNotBlank(config.getCertificate())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), FileUtils.readFileToByteArray(new File(config.getCertificate())), config.getCertificatePassword(), env); } else if (StringUtils.isNotBlank(config.getKey())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), config.getKey(), env); } throw new InvalidConfigurationException("Invalid auth configuration, either 'key' or 'certificate' is required."); } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getAzureServicePrincipleCredentials(AuthConfiguration config) throws InvalidConfigurationException, IOException { if (StringUtils.isBlank(config.getClient())) { throw new IllegalArgumentException("'Client Id' of your service principal is not configured."); } if (StringUtils.isBlank(config.getTenant())) { throw new IllegalArgumentException("'Tenant Id' of your service principal is not configured."); } final AzureEnvironment env = AzureAuthHelper.getAzureEnvironment(config.getEnvironment()); if (StringUtils.isNotBlank(config.getCertificate())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), FileUtils.readFileToByteArray(new File(config.getCertificate())), config.getCertificatePassword(), env); } else if (StringUtils.isNotBlank(config.getKey())) { return new ApplicationTokenCredentials(config.getClient(), config.getTenant(), config.getKey(), env); } throw new InvalidConfigurationException("Invalid auth configuration, either 'key' or 'certificate' is required."); } private AzureServicePrincipleAuthHelper(); }
@Test public void getResources() { doReturn(null).when(mojo).getDeployment(); assertNull(parser.getResources()); final List<Resource> resources = new ArrayList<Resource>(); resources.add(new Resource()); final Deployment deployment = mock(Deployment.class); doReturn(deployment).when(mojo).getDeployment(); doReturn(resources).when(deployment).getResources(); assertEquals(resources, parser.getResources()); }
@Override protected List<Resource> getResources() { final Deployment deployment = mojo.getDeployment(); return deployment == null ? null : deployment.getResources(); }
V2ConfigurationParser extends ConfigurationParser { @Override protected List<Resource> getResources() { final Deployment deployment = mojo.getDeployment(); return deployment == null ? null : deployment.getResources(); } }
V2ConfigurationParser extends ConfigurationParser { @Override protected List<Resource> getResources() { final Deployment deployment = mojo.getDeployment(); return deployment == null ? null : deployment.getResources(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected List<Resource> getResources() { final Deployment deployment = mojo.getDeployment(); return deployment == null ? null : deployment.getResources(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V2ConfigurationParser extends ConfigurationParser { @Override protected List<Resource> getResources() { final Deployment deployment = mojo.getDeployment(); return deployment == null ? null : deployment.getResources(); } V2ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
@Test public void getWebAppName() throws AzureExecutionException { doReturn("appName").when(mojo).getAppName(); assertEquals("appName", parser.getAppName()); doReturn("-invalidAppName").when(mojo).getAppName(); try { parser.getAppName(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The <appName> only allow alphanumeric characters, " + "hyphens and cannot start or end in a hyphen."); } doReturn(null).when(mojo).getAppName(); try { parser.getAppName(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Please config the <appName> in pom.xml."); } }
protected String getAppName() throws AzureExecutionException { validate(validator.validateAppName()); return mojo.getAppName(); }
ConfigurationParser { protected String getAppName() throws AzureExecutionException { validate(validator.validateAppName()); return mojo.getAppName(); } }
ConfigurationParser { protected String getAppName() throws AzureExecutionException { validate(validator.validateAppName()); return mojo.getAppName(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); }
ConfigurationParser { protected String getAppName() throws AzureExecutionException { validate(validator.validateAppName()); return mojo.getAppName(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); WebAppConfiguration getWebAppConfiguration(); }
ConfigurationParser { protected String getAppName() throws AzureExecutionException { validate(validator.validateAppName()); return mojo.getAppName(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); WebAppConfiguration getWebAppConfiguration(); }
@Test public void getResourceGroup() throws AzureExecutionException { doReturn("resourceGroupName").when(mojo).getResourceGroup(); assertEquals("resourceGroupName", parser.getResourceGroup()); doReturn("invalid**ResourceGroupName").when(mojo).getResourceGroup(); try { parser.getResourceGroup(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The <resourceGroup> only allow alphanumeric characters, periods, " + "underscores, hyphens and parenthesis and cannot end in a period."); } doReturn(null).when(mojo).getResourceGroup(); try { parser.getResourceGroup(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Please config the <resourceGroup> in pom.xml."); } }
protected String getResourceGroup() throws AzureExecutionException { validate(validator.validateResourceGroup()); return mojo.getResourceGroup(); }
ConfigurationParser { protected String getResourceGroup() throws AzureExecutionException { validate(validator.validateResourceGroup()); return mojo.getResourceGroup(); } }
ConfigurationParser { protected String getResourceGroup() throws AzureExecutionException { validate(validator.validateResourceGroup()); return mojo.getResourceGroup(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); }
ConfigurationParser { protected String getResourceGroup() throws AzureExecutionException { validate(validator.validateResourceGroup()); return mojo.getResourceGroup(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); WebAppConfiguration getWebAppConfiguration(); }
ConfigurationParser { protected String getResourceGroup() throws AzureExecutionException { validate(validator.validateResourceGroup()); return mojo.getResourceGroup(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); WebAppConfiguration getWebAppConfiguration(); }
@Test public void getWebAppConfiguration() throws AzureExecutionException { final ConfigurationParser parserSpy = spy(parser); doReturn("appName").when(parserSpy).getAppName(); doReturn("resourceGroupName").when(parserSpy).getResourceGroup(); final MavenProject project = mock(MavenProject.class); final MavenResourcesFiltering filtering = mock(MavenResourcesFiltering.class); final MavenSession session = mock(MavenSession.class); doReturn(project).when(mojo).getProject(); doReturn(filtering).when(mojo).getMavenResourcesFiltering(); doReturn(session).when(mojo).getSession(); doReturn("test-staging-path").when(mojo).getDeploymentStagingDirectoryPath(); doReturn("test-build-directory-path").when(mojo).getBuildDirectoryAbsolutePath(); doReturn("p1v2").when(mojo).getPricingTier(); doReturn(OperatingSystemEnum.Windows).when(parserSpy).getOs(); WebAppConfiguration webAppConfiguration = parserSpy.getWebAppConfiguration(); assertEquals("appName", webAppConfiguration.getAppName()); assertEquals("resourceGroupName", webAppConfiguration.getResourceGroup()); assertEquals(Region.EUROPE_WEST, webAppConfiguration.getRegion()); assertEquals(new PricingTier("PremiumV2", "P1v2"), webAppConfiguration.getPricingTier()); assertEquals(null, webAppConfiguration.getServicePlanName()); assertEquals(null, webAppConfiguration.getServicePlanResourceGroup()); assertEquals(OperatingSystemEnum.Windows, webAppConfiguration.getOs()); assertEquals(null, webAppConfiguration.getMavenSettings()); assertEquals(project, webAppConfiguration.getProject()); assertEquals(session, webAppConfiguration.getSession()); assertEquals(filtering, webAppConfiguration.getFiltering()); assertEquals("test-staging-path", webAppConfiguration.getStagingDirectoryPath()); assertEquals("test-build-directory-path", webAppConfiguration.getBuildDirectoryAbsolutePath()); assertEquals(JavaVersion.JAVA_8_NEWEST, webAppConfiguration.getJavaVersion()); assertEquals(WebContainer.TOMCAT_8_5_NEWEST, webAppConfiguration.getWebContainer()); doReturn(OperatingSystemEnum.Linux).when(parserSpy).getOs(); webAppConfiguration = parserSpy.getWebAppConfiguration(); assertEquals(RuntimeStack.TOMCAT_8_5_JRE8, webAppConfiguration.getRuntimeStack()); doReturn(OperatingSystemEnum.Docker).when(parserSpy).getOs(); webAppConfiguration = parserSpy.getWebAppConfiguration(); assertEquals("image", webAppConfiguration.getImage()); assertEquals(null, webAppConfiguration.getServerId()); assertEquals(null, webAppConfiguration.getRegistryUrl()); }
public WebAppConfiguration getWebAppConfiguration() throws AzureExecutionException { WebAppConfiguration.Builder builder = new WebAppConfiguration.Builder(); final OperatingSystemEnum os = getOs(); if (os == null) { Log.debug("No runtime related config is specified. " + "It will cause error if creating a new web app."); } else { switch (os) { case Windows: builder = builder.javaVersion(getJavaVersion()).webContainer(getWebContainer()); break; case Linux: builder = builder.runtimeStack(getRuntimeStack()); break; case Docker: builder = builder.image(getImage()).serverId(getServerId()).registryUrl(getRegistryUrl()); break; default: throw new AzureExecutionException("Invalid operating system from the configuration."); } } return builder.appName(getAppName()) .resourceGroup(getResourceGroup()) .region(getRegion()) .pricingTier(getPricingTier()) .servicePlanName(mojo.getAppServicePlanName()) .servicePlanResourceGroup(mojo.getAppServicePlanResourceGroup()) .deploymentSlotSetting(getDeploymentSlotSetting()) .os(os) .mavenSettings(mojo.getSettings()) .resources(getResources()) .stagingDirectoryPath(mojo.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(mojo.getBuildDirectoryAbsolutePath()) .project(mojo.getProject()) .session(mojo.getSession()) .filtering(mojo.getMavenResourcesFiltering()) .schemaVersion(getSchemaVersion()) .build(); }
ConfigurationParser { public WebAppConfiguration getWebAppConfiguration() throws AzureExecutionException { WebAppConfiguration.Builder builder = new WebAppConfiguration.Builder(); final OperatingSystemEnum os = getOs(); if (os == null) { Log.debug("No runtime related config is specified. " + "It will cause error if creating a new web app."); } else { switch (os) { case Windows: builder = builder.javaVersion(getJavaVersion()).webContainer(getWebContainer()); break; case Linux: builder = builder.runtimeStack(getRuntimeStack()); break; case Docker: builder = builder.image(getImage()).serverId(getServerId()).registryUrl(getRegistryUrl()); break; default: throw new AzureExecutionException("Invalid operating system from the configuration."); } } return builder.appName(getAppName()) .resourceGroup(getResourceGroup()) .region(getRegion()) .pricingTier(getPricingTier()) .servicePlanName(mojo.getAppServicePlanName()) .servicePlanResourceGroup(mojo.getAppServicePlanResourceGroup()) .deploymentSlotSetting(getDeploymentSlotSetting()) .os(os) .mavenSettings(mojo.getSettings()) .resources(getResources()) .stagingDirectoryPath(mojo.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(mojo.getBuildDirectoryAbsolutePath()) .project(mojo.getProject()) .session(mojo.getSession()) .filtering(mojo.getMavenResourcesFiltering()) .schemaVersion(getSchemaVersion()) .build(); } }
ConfigurationParser { public WebAppConfiguration getWebAppConfiguration() throws AzureExecutionException { WebAppConfiguration.Builder builder = new WebAppConfiguration.Builder(); final OperatingSystemEnum os = getOs(); if (os == null) { Log.debug("No runtime related config is specified. " + "It will cause error if creating a new web app."); } else { switch (os) { case Windows: builder = builder.javaVersion(getJavaVersion()).webContainer(getWebContainer()); break; case Linux: builder = builder.runtimeStack(getRuntimeStack()); break; case Docker: builder = builder.image(getImage()).serverId(getServerId()).registryUrl(getRegistryUrl()); break; default: throw new AzureExecutionException("Invalid operating system from the configuration."); } } return builder.appName(getAppName()) .resourceGroup(getResourceGroup()) .region(getRegion()) .pricingTier(getPricingTier()) .servicePlanName(mojo.getAppServicePlanName()) .servicePlanResourceGroup(mojo.getAppServicePlanResourceGroup()) .deploymentSlotSetting(getDeploymentSlotSetting()) .os(os) .mavenSettings(mojo.getSettings()) .resources(getResources()) .stagingDirectoryPath(mojo.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(mojo.getBuildDirectoryAbsolutePath()) .project(mojo.getProject()) .session(mojo.getSession()) .filtering(mojo.getMavenResourcesFiltering()) .schemaVersion(getSchemaVersion()) .build(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); }
ConfigurationParser { public WebAppConfiguration getWebAppConfiguration() throws AzureExecutionException { WebAppConfiguration.Builder builder = new WebAppConfiguration.Builder(); final OperatingSystemEnum os = getOs(); if (os == null) { Log.debug("No runtime related config is specified. " + "It will cause error if creating a new web app."); } else { switch (os) { case Windows: builder = builder.javaVersion(getJavaVersion()).webContainer(getWebContainer()); break; case Linux: builder = builder.runtimeStack(getRuntimeStack()); break; case Docker: builder = builder.image(getImage()).serverId(getServerId()).registryUrl(getRegistryUrl()); break; default: throw new AzureExecutionException("Invalid operating system from the configuration."); } } return builder.appName(getAppName()) .resourceGroup(getResourceGroup()) .region(getRegion()) .pricingTier(getPricingTier()) .servicePlanName(mojo.getAppServicePlanName()) .servicePlanResourceGroup(mojo.getAppServicePlanResourceGroup()) .deploymentSlotSetting(getDeploymentSlotSetting()) .os(os) .mavenSettings(mojo.getSettings()) .resources(getResources()) .stagingDirectoryPath(mojo.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(mojo.getBuildDirectoryAbsolutePath()) .project(mojo.getProject()) .session(mojo.getSession()) .filtering(mojo.getMavenResourcesFiltering()) .schemaVersion(getSchemaVersion()) .build(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); WebAppConfiguration getWebAppConfiguration(); }
ConfigurationParser { public WebAppConfiguration getWebAppConfiguration() throws AzureExecutionException { WebAppConfiguration.Builder builder = new WebAppConfiguration.Builder(); final OperatingSystemEnum os = getOs(); if (os == null) { Log.debug("No runtime related config is specified. " + "It will cause error if creating a new web app."); } else { switch (os) { case Windows: builder = builder.javaVersion(getJavaVersion()).webContainer(getWebContainer()); break; case Linux: builder = builder.runtimeStack(getRuntimeStack()); break; case Docker: builder = builder.image(getImage()).serverId(getServerId()).registryUrl(getRegistryUrl()); break; default: throw new AzureExecutionException("Invalid operating system from the configuration."); } } return builder.appName(getAppName()) .resourceGroup(getResourceGroup()) .region(getRegion()) .pricingTier(getPricingTier()) .servicePlanName(mojo.getAppServicePlanName()) .servicePlanResourceGroup(mojo.getAppServicePlanResourceGroup()) .deploymentSlotSetting(getDeploymentSlotSetting()) .os(os) .mavenSettings(mojo.getSettings()) .resources(getResources()) .stagingDirectoryPath(mojo.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(mojo.getBuildDirectoryAbsolutePath()) .project(mojo.getProject()) .session(mojo.getSession()) .filtering(mojo.getMavenResourcesFiltering()) .schemaVersion(getSchemaVersion()) .build(); } protected ConfigurationParser(final AbstractWebAppMojo mojo, final AbstractConfigurationValidator validator); WebAppConfiguration getWebAppConfiguration(); }
@Test public void getOs() throws AzureExecutionException { assertNull(parser.getOs()); doReturn("1.8").when(mojo).getJavaVersion(); assertEquals(OperatingSystemEnum.Windows, parser.getOs()); doReturn(null).when(mojo).getJavaVersion(); doReturn("linuxRuntime").when(mojo).getLinuxRuntime(); assertEquals(OperatingSystemEnum.Linux, parser.getOs()); doReturn(null).when(mojo).getJavaVersion(); doReturn(null).when(mojo).getLinuxRuntime(); doReturn(mock(ContainerSetting.class)).when(mojo).getContainerSettings(); assertEquals(OperatingSystemEnum.Docker, parser.getOs()); doReturn("linuxRuntime").when(mojo).getLinuxRuntime(); doReturn("1.8").when(mojo).getJavaVersion(); try { parser.getOs(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Conflict settings found. <javaVersion>, <linuxRuntime>" + "and <containerSettings> should not be set at the same time."); } }
@Override public OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final String linuxRuntime = mojo.getLinuxRuntime(); final String javaVersion = mojo.getJavaVersion(); final ContainerSetting containerSetting = mojo.getContainerSettings(); final boolean isContainerSettingEmpty = containerSetting == null || containerSetting.isEmpty(); final List<OperatingSystemEnum> osList = new ArrayList<>(); if (javaVersion != null) { osList.add(OperatingSystemEnum.Windows); } if (linuxRuntime != null) { osList.add(OperatingSystemEnum.Linux); } if (!isContainerSettingEmpty) { osList.add(OperatingSystemEnum.Docker); } return osList.size() > 0 ? osList.get(0) : null; }
V1ConfigurationParser extends ConfigurationParser { @Override public OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final String linuxRuntime = mojo.getLinuxRuntime(); final String javaVersion = mojo.getJavaVersion(); final ContainerSetting containerSetting = mojo.getContainerSettings(); final boolean isContainerSettingEmpty = containerSetting == null || containerSetting.isEmpty(); final List<OperatingSystemEnum> osList = new ArrayList<>(); if (javaVersion != null) { osList.add(OperatingSystemEnum.Windows); } if (linuxRuntime != null) { osList.add(OperatingSystemEnum.Linux); } if (!isContainerSettingEmpty) { osList.add(OperatingSystemEnum.Docker); } return osList.size() > 0 ? osList.get(0) : null; } }
V1ConfigurationParser extends ConfigurationParser { @Override public OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final String linuxRuntime = mojo.getLinuxRuntime(); final String javaVersion = mojo.getJavaVersion(); final ContainerSetting containerSetting = mojo.getContainerSettings(); final boolean isContainerSettingEmpty = containerSetting == null || containerSetting.isEmpty(); final List<OperatingSystemEnum> osList = new ArrayList<>(); if (javaVersion != null) { osList.add(OperatingSystemEnum.Windows); } if (linuxRuntime != null) { osList.add(OperatingSystemEnum.Linux); } if (!isContainerSettingEmpty) { osList.add(OperatingSystemEnum.Docker); } return osList.size() > 0 ? osList.get(0) : null; } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V1ConfigurationParser extends ConfigurationParser { @Override public OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final String linuxRuntime = mojo.getLinuxRuntime(); final String javaVersion = mojo.getJavaVersion(); final ContainerSetting containerSetting = mojo.getContainerSettings(); final boolean isContainerSettingEmpty = containerSetting == null || containerSetting.isEmpty(); final List<OperatingSystemEnum> osList = new ArrayList<>(); if (javaVersion != null) { osList.add(OperatingSystemEnum.Windows); } if (linuxRuntime != null) { osList.add(OperatingSystemEnum.Linux); } if (!isContainerSettingEmpty) { osList.add(OperatingSystemEnum.Docker); } return osList.size() > 0 ? osList.get(0) : null; } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
V1ConfigurationParser extends ConfigurationParser { @Override public OperatingSystemEnum getOs() throws AzureExecutionException { validate(validator.validateOs()); final String linuxRuntime = mojo.getLinuxRuntime(); final String javaVersion = mojo.getJavaVersion(); final ContainerSetting containerSetting = mojo.getContainerSettings(); final boolean isContainerSettingEmpty = containerSetting == null || containerSetting.isEmpty(); final List<OperatingSystemEnum> osList = new ArrayList<>(); if (javaVersion != null) { osList.add(OperatingSystemEnum.Windows); } if (linuxRuntime != null) { osList.add(OperatingSystemEnum.Linux); } if (!isContainerSettingEmpty) { osList.add(OperatingSystemEnum.Docker); } return osList.size() > 0 ? osList.get(0) : null; } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
@Test public void getRegion() throws AzureExecutionException { assertEquals(Region.EUROPE_WEST, parser.getRegion()); doReturn("unknown-region").when(mojo).getRegion(); try { parser.getRegion(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The value of <region> is not correct, please correct it in pom.xml."); } doReturn(Region.US_WEST.name()).when(mojo).getRegion(); assertEquals(Region.US_WEST, parser.getRegion()); }
@Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); if (StringUtils.isEmpty(mojo.getRegion())) { return Region.EUROPE_WEST; } return Region.fromName(mojo.getRegion()); }
V1ConfigurationParser extends ConfigurationParser { @Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); if (StringUtils.isEmpty(mojo.getRegion())) { return Region.EUROPE_WEST; } return Region.fromName(mojo.getRegion()); } }
V1ConfigurationParser extends ConfigurationParser { @Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); if (StringUtils.isEmpty(mojo.getRegion())) { return Region.EUROPE_WEST; } return Region.fromName(mojo.getRegion()); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V1ConfigurationParser extends ConfigurationParser { @Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); if (StringUtils.isEmpty(mojo.getRegion())) { return Region.EUROPE_WEST; } return Region.fromName(mojo.getRegion()); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
V1ConfigurationParser extends ConfigurationParser { @Override protected Region getRegion() throws AzureExecutionException { validate(validator.validateRegion()); if (StringUtils.isEmpty(mojo.getRegion())) { return Region.EUROPE_WEST; } return Region.fromName(mojo.getRegion()); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
@Test public void getRuntimeStack() throws AzureExecutionException { try { parser.getRuntimeStack(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Please configure the <linuxRuntime> in pom.xml."); } doReturn("tomcat 8.5-jre8").when(mojo).getLinuxRuntime(); assertEquals(RuntimeStack.TOMCAT_8_5_JRE8, parser.getRuntimeStack()); doReturn("tomcat 9.0-jre8").when(mojo).getLinuxRuntime(); assertEquals(RuntimeStack.TOMCAT_9_0_JRE8, parser.getRuntimeStack()); doReturn("jre8").when(mojo).getLinuxRuntime(); assertEquals(RuntimeStack.JAVA_8_JRE8, parser.getRuntimeStack()); doReturn("tomcat 8.5-java11").when(mojo).getLinuxRuntime(); assertEquals(RuntimeStack.TOMCAT_8_5_JAVA11, parser.getRuntimeStack()); doReturn("tomcat 9.0-java11").when(mojo).getLinuxRuntime(); assertEquals(RuntimeStack.TOMCAT_9_0_JAVA11, parser.getRuntimeStack()); doReturn("java11").when(mojo).getLinuxRuntime(); assertEquals(RuntimeStack.JAVA_11_JAVA11, parser.getRuntimeStack()); doReturn("unknown-value").when(mojo).getLinuxRuntime(); try { parser.getRuntimeStack(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The configuration of <linuxRuntime> in pom.xml is not correct. " + "Please refer https: } }
@Override public RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final String linuxRuntime = mojo.getLinuxRuntime(); final RuntimeStack javaSERuntimeStack = RuntimeStackUtils.getRuntimeStack(linuxRuntime); if (javaSERuntimeStack != null) { return javaSERuntimeStack; } final List<RuntimeStack> runtimeStacks = RuntimeStackUtils.getValidRuntimeStacks(); for (final RuntimeStack runtimeStack : runtimeStacks) { if (runtimeStack.toString().equalsIgnoreCase(mojo.getLinuxRuntime())) { return runtimeStack; } } throw new AzureExecutionException(RUNTIME_NOT_EXIST); }
V1ConfigurationParser extends ConfigurationParser { @Override public RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final String linuxRuntime = mojo.getLinuxRuntime(); final RuntimeStack javaSERuntimeStack = RuntimeStackUtils.getRuntimeStack(linuxRuntime); if (javaSERuntimeStack != null) { return javaSERuntimeStack; } final List<RuntimeStack> runtimeStacks = RuntimeStackUtils.getValidRuntimeStacks(); for (final RuntimeStack runtimeStack : runtimeStacks) { if (runtimeStack.toString().equalsIgnoreCase(mojo.getLinuxRuntime())) { return runtimeStack; } } throw new AzureExecutionException(RUNTIME_NOT_EXIST); } }
V1ConfigurationParser extends ConfigurationParser { @Override public RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final String linuxRuntime = mojo.getLinuxRuntime(); final RuntimeStack javaSERuntimeStack = RuntimeStackUtils.getRuntimeStack(linuxRuntime); if (javaSERuntimeStack != null) { return javaSERuntimeStack; } final List<RuntimeStack> runtimeStacks = RuntimeStackUtils.getValidRuntimeStacks(); for (final RuntimeStack runtimeStack : runtimeStacks) { if (runtimeStack.toString().equalsIgnoreCase(mojo.getLinuxRuntime())) { return runtimeStack; } } throw new AzureExecutionException(RUNTIME_NOT_EXIST); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V1ConfigurationParser extends ConfigurationParser { @Override public RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final String linuxRuntime = mojo.getLinuxRuntime(); final RuntimeStack javaSERuntimeStack = RuntimeStackUtils.getRuntimeStack(linuxRuntime); if (javaSERuntimeStack != null) { return javaSERuntimeStack; } final List<RuntimeStack> runtimeStacks = RuntimeStackUtils.getValidRuntimeStacks(); for (final RuntimeStack runtimeStack : runtimeStacks) { if (runtimeStack.toString().equalsIgnoreCase(mojo.getLinuxRuntime())) { return runtimeStack; } } throw new AzureExecutionException(RUNTIME_NOT_EXIST); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
V1ConfigurationParser extends ConfigurationParser { @Override public RuntimeStack getRuntimeStack() throws AzureExecutionException { validate(validator.validateRuntimeStack()); final String linuxRuntime = mojo.getLinuxRuntime(); final RuntimeStack javaSERuntimeStack = RuntimeStackUtils.getRuntimeStack(linuxRuntime); if (javaSERuntimeStack != null) { return javaSERuntimeStack; } final List<RuntimeStack> runtimeStacks = RuntimeStackUtils.getValidRuntimeStacks(); for (final RuntimeStack runtimeStack : runtimeStacks) { if (runtimeStack.toString().equalsIgnoreCase(mojo.getLinuxRuntime())) { return runtimeStack; } } throw new AzureExecutionException(RUNTIME_NOT_EXIST); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
@Test public void getImage() throws AzureExecutionException { try { parser.getImage(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Please config the <containerSettings> in pom.xml."); } final ContainerSetting containerSetting = mock(ContainerSetting.class); doReturn(containerSetting).when(mojo).getContainerSettings(); doReturn("imageName").when(containerSetting).getImageName(); assertEquals("imageName", parser.getImage()); doReturn("").when(containerSetting).getImageName(); try { parser.getImage(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Please config the <imageName> of <containerSettings> in pom.xml."); } }
@Override public String getImage() throws AzureExecutionException { validate(validator.validateImage()); final ContainerSetting containerSetting = mojo.getContainerSettings(); return containerSetting.getImageName(); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getImage() throws AzureExecutionException { validate(validator.validateImage()); final ContainerSetting containerSetting = mojo.getContainerSettings(); return containerSetting.getImageName(); } }
V1ConfigurationParser extends ConfigurationParser { @Override public String getImage() throws AzureExecutionException { validate(validator.validateImage()); final ContainerSetting containerSetting = mojo.getContainerSettings(); return containerSetting.getImageName(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getImage() throws AzureExecutionException { validate(validator.validateImage()); final ContainerSetting containerSetting = mojo.getContainerSettings(); return containerSetting.getImageName(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getImage() throws AzureExecutionException { validate(validator.validateImage()); final ContainerSetting containerSetting = mojo.getContainerSettings(); return containerSetting.getImageName(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
@Test public void getServerId() { assertNull(parser.getServerId()); final ContainerSetting containerSetting = mock(ContainerSetting.class); doReturn(containerSetting).when(mojo).getContainerSettings(); doReturn("serverId").when(containerSetting).getServerId(); assertEquals("serverId", parser.getServerId()); }
@Override public String getServerId() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getServerId(); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getServerId() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getServerId(); } }
V1ConfigurationParser extends ConfigurationParser { @Override public String getServerId() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getServerId(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getServerId() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getServerId(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getServerId() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getServerId(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
@Test public void getRegistryUrl() { assertNull(parser.getRegistryUrl()); final ContainerSetting containerSetting = mock(ContainerSetting.class); doReturn(containerSetting).when(mojo).getContainerSettings(); doReturn("registryUrl").when(containerSetting).getRegistryUrl(); assertEquals("registryUrl", parser.getRegistryUrl()); }
@Override public String getRegistryUrl() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getRegistryUrl(); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getRegistryUrl() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getRegistryUrl(); } }
V1ConfigurationParser extends ConfigurationParser { @Override public String getRegistryUrl() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getRegistryUrl(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getRegistryUrl() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getRegistryUrl(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
V1ConfigurationParser extends ConfigurationParser { @Override public String getRegistryUrl() { final ContainerSetting containerSetting = mojo.getContainerSettings(); if (containerSetting == null) { return null; } return containerSetting.getRegistryUrl(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
@Test public void testGetSPCredentials() throws Exception { final File testConfigDir = new File(this.getClass().getResource("/azure-cli/sp/azureProfile.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); final AzureTokenCredentials cred = AzureServicePrincipleAuthHelper.getCredentialFromAzureCliWithServicePrincipal(); assertEquals("00000000-0000-0000-0000-000000000002", ((ApplicationTokenCredentials) cred).clientId()); assertEquals("https: assertEquals("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", TestHelper.readField(cred, "clientSecret")); }
static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
@Test public void getWebContainer() throws AzureExecutionException { try { parser.getWebContainer(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "The configuration of <javaWebContainer> in pom.xml is not correct."); } doReturn(WebContainer.TOMCAT_8_5_NEWEST).when(mojo).getJavaWebContainer(); assertEquals(WebContainer.TOMCAT_8_5_NEWEST, parser.getWebContainer()); }
@Override public WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); return mojo.getJavaWebContainer(); }
V1ConfigurationParser extends ConfigurationParser { @Override public WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); return mojo.getJavaWebContainer(); } }
V1ConfigurationParser extends ConfigurationParser { @Override public WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); return mojo.getJavaWebContainer(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V1ConfigurationParser extends ConfigurationParser { @Override public WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); return mojo.getJavaWebContainer(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
V1ConfigurationParser extends ConfigurationParser { @Override public WebContainer getWebContainer() throws AzureExecutionException { validate(validator.validateWebContainer()); return mojo.getJavaWebContainer(); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
@Test public void getJavaVersion() throws AzureExecutionException { try { parser.getJavaVersion(); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Please config the <javaVersion> in pom.xml."); } doReturn("1.8").when(mojo).getJavaVersion(); assertEquals(JavaVersion.JAVA_8_NEWEST, parser.getJavaVersion()); }
@Override public JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); return JavaVersion.fromString(mojo.getJavaVersion()); }
V1ConfigurationParser extends ConfigurationParser { @Override public JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); return JavaVersion.fromString(mojo.getJavaVersion()); } }
V1ConfigurationParser extends ConfigurationParser { @Override public JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); return JavaVersion.fromString(mojo.getJavaVersion()); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); }
V1ConfigurationParser extends ConfigurationParser { @Override public JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); return JavaVersion.fromString(mojo.getJavaVersion()); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
V1ConfigurationParser extends ConfigurationParser { @Override public JavaVersion getJavaVersion() throws AzureExecutionException { validate(validator.validateJavaVersion()); return JavaVersion.fromString(mojo.getJavaVersion()); } V1ConfigurationParser(AbstractWebAppMojo mojo, AbstractConfigurationValidator validator); @Override OperatingSystemEnum getOs(); @Override RuntimeStack getRuntimeStack(); @Override String getImage(); @Override String getServerId(); @Override String getRegistryUrl(); @Override WebContainer getWebContainer(); @Override JavaVersion getJavaVersion(); @Override List<Resource> getResources(); }
@Test public void deployArtifactsWithNoResources() throws Exception { final DeployMojo mojo = getMojoFromPom("/pom-linux.xml"); final DeployMojo mojoSpy = spy(mojo); final WebApp app = mock(WebApp.class); doReturn("target/classes").when(mojoSpy).getDeploymentStagingDirectoryPath(); doReturn(app).when(mojoSpy).getWebApp(); doReturn(false).when(mojoSpy).isDeployToDeploymentSlot(); final MavenResourcesFiltering filtering = mock(MavenResourcesFiltering.class); doNothing().when(filtering).filterResources(any()); doReturn(filtering).when(mojoSpy).getMavenResourcesFiltering(); final MavenSession session = mock(MavenSession.class); doReturn(session).when(mojoSpy).getSession(); final MavenProject project = mock(MavenProject.class); doReturn(new File("target/..")).when(project).getBasedir(); doReturn(project).when(mojoSpy).getProject(); mojoSpy.deployArtifacts(mojoSpy.getWebAppConfiguration()); }
protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } static final String WEBAPP_NOT_EXIST; static final String WEBAPP_CREATED; static final String CREATE_DEPLOYMENT_SLOT; static final String CREATE_DEPLOYMENT_SLOT_DONE; static final String UPDATE_WEBAPP; static final String UPDATE_WEBAPP_SKIP; static final String UPDATE_WEBAPP_DONE; static final String STOP_APP; static final String START_APP; static final String STOP_APP_DONE; static final String START_APP_DONE; static final String WEBAPP_NOT_EXIST_FOR_SLOT; static final String SLOT_SHOULD_EXIST_NOW; }
@Test public void deployArtifactsWithResources() throws Exception { final DeployMojo mojo = getMojoFromPom("/pom-linux.xml"); final DeployMojo mojoSpy = spy(mojo); final WebApp app = mock(WebApp.class); doReturn(app).when(mojoSpy).getWebApp(); doReturn(false).when(mojoSpy).isDeployToDeploymentSlot(); doReturn("target/classes").when(mojoSpy).getDeploymentStagingDirectoryPath(); final MavenResourcesFiltering filtering = mock(MavenResourcesFiltering.class); doNothing().when(filtering).filterResources(any()); doReturn(filtering).when(mojoSpy).getMavenResourcesFiltering(); final MavenSession session = mock(MavenSession.class); doReturn(session).when(mojoSpy).getSession(); final MavenProject project = mock(MavenProject.class); doReturn(new File("target/..")).when(project).getBasedir(); doReturn(project).when(mojoSpy).getProject(); final DeployTarget deployTarget = new WebAppDeployTarget(app); mojoSpy.deployArtifacts(mojoSpy.getWebAppConfiguration()); verify(artifactHandler, times(1)).publish(refEq(deployTarget)); verifyNoMoreInteractions(artifactHandler); }
protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } static final String WEBAPP_NOT_EXIST; static final String WEBAPP_CREATED; static final String CREATE_DEPLOYMENT_SLOT; static final String CREATE_DEPLOYMENT_SLOT_DONE; static final String UPDATE_WEBAPP; static final String UPDATE_WEBAPP_SKIP; static final String UPDATE_WEBAPP_DONE; static final String STOP_APP; static final String START_APP; static final String STOP_APP_DONE; static final String START_APP_DONE; static final String WEBAPP_NOT_EXIST_FOR_SLOT; static final String SLOT_SHOULD_EXIST_NOW; }
@Test public void deployToDeploymentSlot() throws Exception { final DeployMojo mojo = getMojoFromPom("/pom-slot.xml"); final DeployMojo mojoSpy = spy(mojo); final DeploymentSlot slot = mock(DeploymentSlot.class); final WebApp app = mock(WebApp.class); final DeploymentSlotSetting slotSetting = mock(DeploymentSlotSetting.class); doReturn(app).when(mojoSpy).getWebApp(); doReturn(slotSetting).when(mojoSpy).getDeploymentSlotSetting(); doReturn("test").when(slotSetting).getName(); doReturn(slot).when(mojoSpy).getDeploymentSlot(app, "test"); doReturn("target/classes").when(mojoSpy).getDeploymentStagingDirectoryPath(); doReturn("target").when(mojoSpy).getBuildDirectoryAbsolutePath(); final MavenResourcesFiltering filtering = mock(MavenResourcesFiltering.class); doNothing().when(filtering).filterResources(any()); doReturn(filtering).when(mojoSpy).getMavenResourcesFiltering(); final MavenSession session = mock(MavenSession.class); doReturn(session).when(mojoSpy).getSession(); final MavenProject project = mock(MavenProject.class); doReturn(new File("target/..")).when(project).getBasedir(); doReturn(project).when(mojoSpy).getProject(); final DeployTarget deployTarget = new DeploymentSlotDeployTarget(slot); mojoSpy.deployArtifacts(mojoSpy.getWebAppConfiguration()); verify(artifactHandler, times(1)).publish(refEq(deployTarget)); verifyNoMoreInteractions(artifactHandler); }
protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } }
DeployMojo extends AbstractWebAppMojo { protected void deployArtifacts(WebAppConfiguration webAppConfiguration) throws AzureAuthFailureException, InterruptedException, AzureExecutionException, IOException { try { util.beforeDeployArtifacts(); final WebApp app = getWebApp(); final DeployTarget target; if (this.isDeployToDeploymentSlot()) { final String slotName = getDeploymentSlotSetting().getName(); final DeploymentSlot slot = getDeploymentSlot(app, slotName); if (slot == null) { throw new AzureExecutionException(SLOT_SHOULD_EXIST_NOW); } target = new DeploymentSlotDeployTarget(slot); } else { target = new WebAppDeployTarget(app); } final ArtifactHandler artifactHandler = getFactory().getArtifactHandler(this); final boolean isV1Schema = SchemaVersion.fromString(this.getSchemaVersion()) == SchemaVersion.V1; if (isV1Schema) { handleV1Artifact(target, this.resources, artifactHandler); } else { final List<Resource> v2Resources = this.deployment == null ? null : this.deployment.getResources(); handleV2Artifact(target, v2Resources, artifactHandler); } } finally { util.afterDeployArtifacts(); } } static final String WEBAPP_NOT_EXIST; static final String WEBAPP_CREATED; static final String CREATE_DEPLOYMENT_SLOT; static final String CREATE_DEPLOYMENT_SLOT_DONE; static final String UPDATE_WEBAPP; static final String UPDATE_WEBAPP_SKIP; static final String UPDATE_WEBAPP_DONE; static final String STOP_APP; static final String START_APP; static final String STOP_APP_DONE; static final String START_APP_DONE; static final String WEBAPP_NOT_EXIST_FOR_SLOT; static final String SLOT_SHOULD_EXIST_NOW; }
@Test public void testGetSPCredentialsNoSubscription() throws Exception { final File testConfigDir = new File(this.getClass().getResource("/azure-cli/no-subscription/azureProfile.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); try { AzureServicePrincipleAuthHelper.getCredentialFromAzureCliWithServicePrincipal(); } catch (InvalidConfigurationException ex) { } }
static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
@Test public void testGetSPCredentialsNoTokens() throws Exception { final File testConfigDir = new File(this.getClass().getResource("/azure-cli/no-tokens/azureProfile.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); try { AzureServicePrincipleAuthHelper.getCredentialFromAzureCliWithServicePrincipal(); } catch (InvalidConfigurationException ex) { } }
static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
@Test public void testGetCredentialsFromCliNotSP() throws Exception { final File testConfigDir = new File(this.getClass().getResource("/azure-cli/default/azureProfile.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); final AzureTokenCredentials cred = AzureServicePrincipleAuthHelper.getCredentialFromAzureCliWithServicePrincipal(); assertNull(cred); }
static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
AzureServicePrincipleAuthHelper { static AzureTokenCredentials getCredentialFromAzureCliWithServicePrincipal() throws InvalidConfigurationException, IOException { final JsonObject subscription = getDefaultSubscriptionObject(); final String servicePrincipalName = subscription == null ? null : subscription.get("user").getAsJsonObject().get("name").getAsString(); if (servicePrincipalName == null) { throw new InvalidConfigurationException(AZURE_CLI_GET_SUBSCRIPTION_FAIL); } final JsonArray tokens = getAzureCliTokenList(); if (tokens == null) { throw new InvalidConfigurationException(AZURE_CLI_LOAD_TOKEN_FAIL); } for (final JsonElement token : tokens) { final JsonObject tokenObject = (JsonObject) token; if (servicePrincipalName.equals(getStringFromJsonObject(tokenObject, "servicePrincipalId"))) { final String tenantId = getStringFromJsonObject(tokenObject, "servicePrincipalTenant"); final String key = getStringFromJsonObject(tokenObject, "accessToken"); final String certificateFile = getStringFromJsonObject(tokenObject, "certificateFile"); final String env = getStringFromJsonObject(subscription, "environmentName"); final String subscriptionId = getStringFromJsonObject(subscription, "id"); if (StringUtils.isNotBlank(key)) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, key, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } if (StringUtils.isNotBlank(certificateFile) && new File(certificateFile).exists()) { return new ApplicationTokenCredentials(servicePrincipalName, tenantId, FileUtils.readFileToByteArray(new File(certificateFile)), null, AzureAuthHelper.getAzureEnvironment(env)) .withDefaultSubscriptionId(subscriptionId); } } } return null; } private AzureServicePrincipleAuthHelper(); }
@Test public void testNoPluginConfigurationFromBuild() throws Exception { final File pom = new File(this.getClass().getClassLoader().getResource("pom-3.xml").getFile()); final Model model = TestHelper.readMavenModel(pom); final MavenProject project = Mockito.mock(MavenProject.class); Mockito.when(project.getModel()).thenReturn(model); final Xpp3Dom config = MavenUtils.getPluginConfiguration(project, "com.microsoft.azure:azure-spring-cloud-maven-plugin"); assertNull(config); }
public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); }
MavenUtils { public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } }
MavenUtils { public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } private MavenUtils(); }
MavenUtils { public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } private MavenUtils(); static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey); }
MavenUtils { public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } private MavenUtils(); static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey); }
@Test public void testValidate() { AuthConfiguration auth = new AuthConfiguration(); auth.setClient("client1"); assertTrue(auth.validate().size() == 2); auth.setTenant("tenant1"); assertTrue(auth.validate().size() == 1); auth.setKey("key1"); assertTrue(auth.validate().size() == 0); auth.setCertificate("certificate1"); assertTrue(auth.validate().size() == 1); auth.setKey(""); assertTrue(auth.validate().size() == 0); auth = new AuthConfiguration(); auth.setTenant("tenant1"); assertTrue(auth.validate().size() == 2); auth.setClient("client1"); auth.setKey("key1"); assertTrue(auth.validate().size() == 0); auth.setEnvironment("hello"); assertTrue(auth.validate().size() == 1); auth.setEnvironment("azure"); assertTrue(auth.validate().size() == 0); auth.setHttpProxyPort("port"); assertTrue(auth.validate().size() == 2); auth.setHttpProxyHost("localhost"); assertTrue(auth.validate().size() == 1); auth.setHttpProxyPort("10000000"); assertTrue(auth.validate().size() == 1); auth.setHttpProxyPort("0"); assertTrue(auth.validate().size() == 1); auth.setHttpProxyPort("1000"); assertTrue(auth.validate().size() == 0); }
public List<ConfigurationProblem> validate() { final List<ConfigurationProblem> results = new ArrayList<>(); final String errorMessagePostfix = StringUtils.isNotBlank(serverId) ? "server: " + serverId + " in settings.xml." : "<auth> configuration."; if (StringUtils.isBlank(tenant)) { results.add(new ConfigurationProblem("tenant", tenant, "Cannot find 'tenant' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(client)) { results.add(new ConfigurationProblem("client", client, "Cannot find 'client' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(key) && StringUtils.isBlank(certificate)) { results.add(new ConfigurationProblem("key", null, "Cannot find either 'key' or 'certificate' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(certificate)) { results.add(new ConfigurationProblem(null, null, "It is illegal to specify both 'key' and 'certificate' in " + errorMessagePostfix, WARNING)); } if (StringUtils.isNotBlank(environment) && !AzureAuthHelper.validateEnvironment(environment)) { results.add(new ConfigurationProblem("environment", environment, String.format("Invalid environment string '%s' in " + errorMessagePostfix, environment), ERROR)); } if ((StringUtils.isNotBlank(httpProxyHost) && StringUtils.isBlank(httpProxyPort)) || (StringUtils.isBlank(httpProxyHost) && StringUtils.isNotBlank(httpProxyPort))) { results.add(new ConfigurationProblem(null, null, "'httpProxyHost' and 'httpProxyPort' must both be set if you want to use proxy.", ERROR)); } if (StringUtils.isNotBlank(httpProxyPort)) { if (!StringUtils.isNumeric(httpProxyPort)) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid integer number for httpProxyPort: '%s'.", httpProxyPort), ERROR)); } else if (NumberUtils.toInt(httpProxyPort) <= 0 || NumberUtils.toInt(httpProxyPort) > 65535) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid range of httpProxyPort: '%s', it should be a number between %d and %d", httpProxyPort, 1, 65535), ERROR)); } } return results; }
AuthConfiguration { public List<ConfigurationProblem> validate() { final List<ConfigurationProblem> results = new ArrayList<>(); final String errorMessagePostfix = StringUtils.isNotBlank(serverId) ? "server: " + serverId + " in settings.xml." : "<auth> configuration."; if (StringUtils.isBlank(tenant)) { results.add(new ConfigurationProblem("tenant", tenant, "Cannot find 'tenant' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(client)) { results.add(new ConfigurationProblem("client", client, "Cannot find 'client' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(key) && StringUtils.isBlank(certificate)) { results.add(new ConfigurationProblem("key", null, "Cannot find either 'key' or 'certificate' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(certificate)) { results.add(new ConfigurationProblem(null, null, "It is illegal to specify both 'key' and 'certificate' in " + errorMessagePostfix, WARNING)); } if (StringUtils.isNotBlank(environment) && !AzureAuthHelper.validateEnvironment(environment)) { results.add(new ConfigurationProblem("environment", environment, String.format("Invalid environment string '%s' in " + errorMessagePostfix, environment), ERROR)); } if ((StringUtils.isNotBlank(httpProxyHost) && StringUtils.isBlank(httpProxyPort)) || (StringUtils.isBlank(httpProxyHost) && StringUtils.isNotBlank(httpProxyPort))) { results.add(new ConfigurationProblem(null, null, "'httpProxyHost' and 'httpProxyPort' must both be set if you want to use proxy.", ERROR)); } if (StringUtils.isNotBlank(httpProxyPort)) { if (!StringUtils.isNumeric(httpProxyPort)) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid integer number for httpProxyPort: '%s'.", httpProxyPort), ERROR)); } else if (NumberUtils.toInt(httpProxyPort) <= 0 || NumberUtils.toInt(httpProxyPort) > 65535) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid range of httpProxyPort: '%s', it should be a number between %d and %d", httpProxyPort, 1, 65535), ERROR)); } } return results; } }
AuthConfiguration { public List<ConfigurationProblem> validate() { final List<ConfigurationProblem> results = new ArrayList<>(); final String errorMessagePostfix = StringUtils.isNotBlank(serverId) ? "server: " + serverId + " in settings.xml." : "<auth> configuration."; if (StringUtils.isBlank(tenant)) { results.add(new ConfigurationProblem("tenant", tenant, "Cannot find 'tenant' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(client)) { results.add(new ConfigurationProblem("client", client, "Cannot find 'client' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(key) && StringUtils.isBlank(certificate)) { results.add(new ConfigurationProblem("key", null, "Cannot find either 'key' or 'certificate' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(certificate)) { results.add(new ConfigurationProblem(null, null, "It is illegal to specify both 'key' and 'certificate' in " + errorMessagePostfix, WARNING)); } if (StringUtils.isNotBlank(environment) && !AzureAuthHelper.validateEnvironment(environment)) { results.add(new ConfigurationProblem("environment", environment, String.format("Invalid environment string '%s' in " + errorMessagePostfix, environment), ERROR)); } if ((StringUtils.isNotBlank(httpProxyHost) && StringUtils.isBlank(httpProxyPort)) || (StringUtils.isBlank(httpProxyHost) && StringUtils.isNotBlank(httpProxyPort))) { results.add(new ConfigurationProblem(null, null, "'httpProxyHost' and 'httpProxyPort' must both be set if you want to use proxy.", ERROR)); } if (StringUtils.isNotBlank(httpProxyPort)) { if (!StringUtils.isNumeric(httpProxyPort)) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid integer number for httpProxyPort: '%s'.", httpProxyPort), ERROR)); } else if (NumberUtils.toInt(httpProxyPort) <= 0 || NumberUtils.toInt(httpProxyPort) > 65535) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid range of httpProxyPort: '%s', it should be a number between %d and %d", httpProxyPort, 1, 65535), ERROR)); } } return results; } }
AuthConfiguration { public List<ConfigurationProblem> validate() { final List<ConfigurationProblem> results = new ArrayList<>(); final String errorMessagePostfix = StringUtils.isNotBlank(serverId) ? "server: " + serverId + " in settings.xml." : "<auth> configuration."; if (StringUtils.isBlank(tenant)) { results.add(new ConfigurationProblem("tenant", tenant, "Cannot find 'tenant' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(client)) { results.add(new ConfigurationProblem("client", client, "Cannot find 'client' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(key) && StringUtils.isBlank(certificate)) { results.add(new ConfigurationProblem("key", null, "Cannot find either 'key' or 'certificate' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(certificate)) { results.add(new ConfigurationProblem(null, null, "It is illegal to specify both 'key' and 'certificate' in " + errorMessagePostfix, WARNING)); } if (StringUtils.isNotBlank(environment) && !AzureAuthHelper.validateEnvironment(environment)) { results.add(new ConfigurationProblem("environment", environment, String.format("Invalid environment string '%s' in " + errorMessagePostfix, environment), ERROR)); } if ((StringUtils.isNotBlank(httpProxyHost) && StringUtils.isBlank(httpProxyPort)) || (StringUtils.isBlank(httpProxyHost) && StringUtils.isNotBlank(httpProxyPort))) { results.add(new ConfigurationProblem(null, null, "'httpProxyHost' and 'httpProxyPort' must both be set if you want to use proxy.", ERROR)); } if (StringUtils.isNotBlank(httpProxyPort)) { if (!StringUtils.isNumeric(httpProxyPort)) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid integer number for httpProxyPort: '%s'.", httpProxyPort), ERROR)); } else if (NumberUtils.toInt(httpProxyPort) <= 0 || NumberUtils.toInt(httpProxyPort) > 65535) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid range of httpProxyPort: '%s', it should be a number between %d and %d", httpProxyPort, 1, 65535), ERROR)); } } return results; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public List<ConfigurationProblem> validate() { final List<ConfigurationProblem> results = new ArrayList<>(); final String errorMessagePostfix = StringUtils.isNotBlank(serverId) ? "server: " + serverId + " in settings.xml." : "<auth> configuration."; if (StringUtils.isBlank(tenant)) { results.add(new ConfigurationProblem("tenant", tenant, "Cannot find 'tenant' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(client)) { results.add(new ConfigurationProblem("client", client, "Cannot find 'client' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isBlank(key) && StringUtils.isBlank(certificate)) { results.add(new ConfigurationProblem("key", null, "Cannot find either 'key' or 'certificate' in " + errorMessagePostfix, ERROR)); } if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(certificate)) { results.add(new ConfigurationProblem(null, null, "It is illegal to specify both 'key' and 'certificate' in " + errorMessagePostfix, WARNING)); } if (StringUtils.isNotBlank(environment) && !AzureAuthHelper.validateEnvironment(environment)) { results.add(new ConfigurationProblem("environment", environment, String.format("Invalid environment string '%s' in " + errorMessagePostfix, environment), ERROR)); } if ((StringUtils.isNotBlank(httpProxyHost) && StringUtils.isBlank(httpProxyPort)) || (StringUtils.isBlank(httpProxyHost) && StringUtils.isNotBlank(httpProxyPort))) { results.add(new ConfigurationProblem(null, null, "'httpProxyHost' and 'httpProxyPort' must both be set if you want to use proxy.", ERROR)); } if (StringUtils.isNotBlank(httpProxyPort)) { if (!StringUtils.isNumeric(httpProxyPort)) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid integer number for httpProxyPort: '%s'.", httpProxyPort), ERROR)); } else if (NumberUtils.toInt(httpProxyPort) <= 0 || NumberUtils.toInt(httpProxyPort) > 65535) { results.add(new ConfigurationProblem("httpProxyPort", httpProxyPort, String.format("Invalid range of httpProxyPort: '%s', it should be a number between %d and %d", httpProxyPort, 1, 65535), ERROR)); } } return results; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetClient() { final AuthConfiguration auth = new AuthConfiguration(); auth.setClient("client1"); assertEquals("client1", auth.getClient()); }
public void setClient(String client) { this.client = client; }
AuthConfiguration { public void setClient(String client) { this.client = client; } }
AuthConfiguration { public void setClient(String client) { this.client = client; } }
AuthConfiguration { public void setClient(String client) { this.client = client; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setClient(String client) { this.client = client; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetTenant() { final AuthConfiguration auth = new AuthConfiguration(); auth.setTenant("tenant1"); assertEquals("tenant1", auth.getTenant()); }
public void setTenant(String tenant) { this.tenant = tenant; }
AuthConfiguration { public void setTenant(String tenant) { this.tenant = tenant; } }
AuthConfiguration { public void setTenant(String tenant) { this.tenant = tenant; } }
AuthConfiguration { public void setTenant(String tenant) { this.tenant = tenant; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setTenant(String tenant) { this.tenant = tenant; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetKey() { final AuthConfiguration auth = new AuthConfiguration(); auth.setKey("key1"); assertEquals("key1", auth.getKey()); }
public void setKey(String key) { this.key = key; }
AuthConfiguration { public void setKey(String key) { this.key = key; } }
AuthConfiguration { public void setKey(String key) { this.key = key; } }
AuthConfiguration { public void setKey(String key) { this.key = key; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setKey(String key) { this.key = key; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetCertificate() { final AuthConfiguration auth = new AuthConfiguration(); auth.setCertificate("certificate1"); assertEquals("certificate1", auth.getCertificate()); }
public void setCertificate(String certificate) { this.certificate = certificate; }
AuthConfiguration { public void setCertificate(String certificate) { this.certificate = certificate; } }
AuthConfiguration { public void setCertificate(String certificate) { this.certificate = certificate; } }
AuthConfiguration { public void setCertificate(String certificate) { this.certificate = certificate; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setCertificate(String certificate) { this.certificate = certificate; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetCertificatePassword() { final AuthConfiguration auth = new AuthConfiguration(); auth.setCertificatePassword("certificatePassword1"); assertEquals("certificatePassword1", auth.getCertificatePassword()); }
public void setCertificatePassword(String certificatePassword) { this.certificatePassword = certificatePassword; }
AuthConfiguration { public void setCertificatePassword(String certificatePassword) { this.certificatePassword = certificatePassword; } }
AuthConfiguration { public void setCertificatePassword(String certificatePassword) { this.certificatePassword = certificatePassword; } }
AuthConfiguration { public void setCertificatePassword(String certificatePassword) { this.certificatePassword = certificatePassword; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setCertificatePassword(String certificatePassword) { this.certificatePassword = certificatePassword; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetEnvironment() { final AuthConfiguration auth = new AuthConfiguration(); auth.setEnvironment("environment1"); assertEquals("environment1", auth.getEnvironment()); }
public void setEnvironment(String environment) { this.environment = environment; }
AuthConfiguration { public void setEnvironment(String environment) { this.environment = environment; } }
AuthConfiguration { public void setEnvironment(String environment) { this.environment = environment; } }
AuthConfiguration { public void setEnvironment(String environment) { this.environment = environment; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setEnvironment(String environment) { this.environment = environment; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetServerId() { final AuthConfiguration auth = new AuthConfiguration(); auth.setServerId("serverId1"); assertEquals("serverId1", auth.getServerId()); }
public void setServerId(String serverId) { this.serverId = serverId; }
AuthConfiguration { public void setServerId(String serverId) { this.serverId = serverId; } }
AuthConfiguration { public void setServerId(String serverId) { this.serverId = serverId; } }
AuthConfiguration { public void setServerId(String serverId) { this.serverId = serverId; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setServerId(String serverId) { this.serverId = serverId; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetHttpProxyHost() { final AuthConfiguration auth = new AuthConfiguration(); auth.setHttpProxyHost("httpProxyHost1"); assertEquals("httpProxyHost1", auth.getHttpProxyHost()); }
public void setHttpProxyHost(String httpProxyHost) { this.httpProxyHost = httpProxyHost; }
AuthConfiguration { public void setHttpProxyHost(String httpProxyHost) { this.httpProxyHost = httpProxyHost; } }
AuthConfiguration { public void setHttpProxyHost(String httpProxyHost) { this.httpProxyHost = httpProxyHost; } }
AuthConfiguration { public void setHttpProxyHost(String httpProxyHost) { this.httpProxyHost = httpProxyHost; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setHttpProxyHost(String httpProxyHost) { this.httpProxyHost = httpProxyHost; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void testSetHttpProxyPort() { final AuthConfiguration auth = new AuthConfiguration(); auth.setHttpProxyPort("8080"); assertEquals("8080", auth.getHttpProxyPort()); }
public void setHttpProxyPort(String httpProxyPort) { this.httpProxyPort = httpProxyPort; }
AuthConfiguration { public void setHttpProxyPort(String httpProxyPort) { this.httpProxyPort = httpProxyPort; } }
AuthConfiguration { public void setHttpProxyPort(String httpProxyPort) { this.httpProxyPort = httpProxyPort; } }
AuthConfiguration { public void setHttpProxyPort(String httpProxyPort) { this.httpProxyPort = httpProxyPort; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
AuthConfiguration { public void setHttpProxyPort(String httpProxyPort) { this.httpProxyPort = httpProxyPort; } String getClient(); void setClient(String client); String getTenant(); void setTenant(String tenant); String getKey(); void setKey(String key); String getCertificate(); void setCertificate(String certificate); String getCertificatePassword(); void setCertificatePassword(String certificatePassword); String getEnvironment(); void setEnvironment(String environment); String getServerId(); void setServerId(String serverId); String getHttpProxyHost(); void setHttpProxyHost(String httpProxyHost); String getHttpProxyPort(); void setHttpProxyPort(String httpProxyPort); List<ConfigurationProblem> validate(); }
@Test public void doExecute() throws Exception { PowerMockito.doNothing().when(Log.class); Log.info(any(String.class)); final PrintStream out = mock(PrintStream.class); System.setOut(out); final ListMojo mojo = new ListMojo(); mojo.doExecute(); verify(out, atLeastOnce()).write(any(byte[].class), any(int.class), any(int.class)); }
@Override protected void doExecute() throws AzureExecutionException { try { Log.info(TEMPLATES_START); printToSystemOut(TEMPLATES_FILE); Log.info(TEMPLATES_END); Log.info(BINDINGS_START); printToSystemOut(BINDINGS_FILE); Log.info(BINDINGS_END); Log.info(RESOURCES_START); printToSystemOut(RESOURCES_FILE); Log.info(RESOURCES_END); } catch (IOException e) { throw new AzureExecutionException("IO errror when printing templates:" + e.getMessage(), e); } }
ListMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { Log.info(TEMPLATES_START); printToSystemOut(TEMPLATES_FILE); Log.info(TEMPLATES_END); Log.info(BINDINGS_START); printToSystemOut(BINDINGS_FILE); Log.info(BINDINGS_END); Log.info(RESOURCES_START); printToSystemOut(RESOURCES_FILE); Log.info(RESOURCES_END); } catch (IOException e) { throw new AzureExecutionException("IO errror when printing templates:" + e.getMessage(), e); } } }
ListMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { Log.info(TEMPLATES_START); printToSystemOut(TEMPLATES_FILE); Log.info(TEMPLATES_END); Log.info(BINDINGS_START); printToSystemOut(BINDINGS_FILE); Log.info(BINDINGS_END); Log.info(RESOURCES_START); printToSystemOut(RESOURCES_FILE); Log.info(RESOURCES_END); } catch (IOException e) { throw new AzureExecutionException("IO errror when printing templates:" + e.getMessage(), e); } } }
ListMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { Log.info(TEMPLATES_START); printToSystemOut(TEMPLATES_FILE); Log.info(TEMPLATES_END); Log.info(BINDINGS_START); printToSystemOut(BINDINGS_FILE); Log.info(BINDINGS_END); Log.info(RESOURCES_START); printToSystemOut(RESOURCES_FILE); Log.info(RESOURCES_END); } catch (IOException e) { throw new AzureExecutionException("IO errror when printing templates:" + e.getMessage(), e); } } }
ListMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { Log.info(TEMPLATES_START); printToSystemOut(TEMPLATES_FILE); Log.info(TEMPLATES_END); Log.info(BINDINGS_START); printToSystemOut(BINDINGS_FILE); Log.info(BINDINGS_END); Log.info(RESOURCES_START); printToSystemOut(RESOURCES_FILE); Log.info(RESOURCES_END); } catch (IOException e) { throw new AzureExecutionException("IO errror when printing templates:" + e.getMessage(), e); } } }
@Test public void testGetAuthConfigurationFromServer() throws Exception { final DefaultPlexusCipher cipher = new DefaultPlexusCipher(); final String encryptedKey = cipher.encryptAndDecorate("hello", "fake_master_key"); final String xml = "<configuration>\n" + " <client>df4d03fa-135b-4b7b-932d-2f2ba6449792</client>\n" + " <tenant>72f988bf-86f1-41af-91ab-2d7cd011db47</tenant>\n" + " <key>%s</key>\n" + " <environment>AZURE</environment>\n" + " </configuration>"; final Xpp3Dom pluginConfiguration = Xpp3DomBuilder.build(new ByteArrayInputStream(String.format(xml, encryptedKey).getBytes()), "UTF-8"); final Server server = Mockito.mock(Server.class); Mockito.when(server.getConfiguration()).thenReturn(pluginConfiguration); final Settings mavenSettings = Mockito.mock(Settings.class); Mockito.when(mavenSettings.getServer("test1")).thenReturn(server); final MavenSession mavenSession = Mockito.mock(MavenSession.class); Mockito.when(mavenSession.getSettings()).thenReturn(mavenSettings); final SettingsDecrypter settingsDecrypter = newSettingsDecrypter(Paths.get("src/test/resources/maven/settings/settings-security.xml")); final AuthConfiguration auth = MavenSettingHelper.getAuthConfigurationFromServer(mavenSession, settingsDecrypter, "test1"); assertEquals("72f988bf-86f1-41af-91ab-2d7cd011db47", auth.getTenant()); assertEquals("df4d03fa-135b-4b7b-932d-2f2ba6449792", auth.getClient()); assertEquals("AZURE", auth.getEnvironment()); assertEquals("hello", auth.getKey()); }
public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; }
MavenSettingHelper { public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; } }
MavenSettingHelper { public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; } private MavenSettingHelper(); }
MavenSettingHelper { public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; } private MavenSettingHelper(); static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId); }
MavenSettingHelper { public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; } private MavenSettingHelper(); static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId); }
@Test public void testBadServerId() throws Exception { final Server server = Mockito.mock(Server.class); final Settings mavenSettings = Mockito.mock(Settings.class); Mockito.when(mavenSettings.getServer("test1")).thenReturn(server); final MavenSession mavenSession = Mockito.mock(MavenSession.class); Mockito.when(mavenSession.getSettings()).thenReturn(mavenSettings); final SettingsDecrypter settingsDecrypter = newSettingsDecrypter(Paths.get("src/test/resources/maven/settings/settings-security.xml")); try { MavenSettingHelper.getAuthConfigurationFromServer(mavenSession, settingsDecrypter, ""); fail("should throw IAE."); } catch (IllegalArgumentException ex) { } try { MavenSettingHelper.getAuthConfigurationFromServer(mavenSession, settingsDecrypter, null); fail("should throw IAE."); } catch (IllegalArgumentException ex) { } assertNull(MavenSettingHelper.getAuthConfigurationFromServer(mavenSession, settingsDecrypter, "test2")); assertNotNull(MavenSettingHelper.getAuthConfigurationFromServer(mavenSession, settingsDecrypter, "test1")); }
public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; }
MavenSettingHelper { public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; } }
MavenSettingHelper { public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; } private MavenSettingHelper(); }
MavenSettingHelper { public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; } private MavenSettingHelper(); static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId); }
MavenSettingHelper { public static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws MavenDecryptException { if (StringUtils.isBlank(serverId)) { throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty."); } final Server server = session.getSettings().getServer(serverId); if (server == null) { return null; } final AuthConfiguration configurationFromServer = new AuthConfiguration(); final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); if (configuration == null) { return configurationFromServer; } configurationFromServer.setTenant(getConfiguration(configuration, "tenant")); configurationFromServer.setClient(getConfiguration(configuration, "client")); final String rawKey = getConfiguration(configuration, "key"); configurationFromServer.setKey(isValueEncrypted(rawKey) ? decryptMavenProtectedValue(settingsDecrypter, "key", rawKey) : rawKey); configurationFromServer.setCertificate(getConfiguration(configuration, "certificate")); final String rawCertificatePassword = getConfiguration(configuration, "certificatePassword"); configurationFromServer.setCertificatePassword(isValueEncrypted(rawCertificatePassword) ? decryptMavenProtectedValue(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword); configurationFromServer.setEnvironment(getConfiguration(configuration, "environment")); configurationFromServer.setHttpProxyHost(getConfiguration(configuration, "httpProxyHost")); configurationFromServer.setHttpProxyPort(getConfiguration(configuration, "httpProxyPort")); configurationFromServer.setServerId(serverId); return configurationFromServer; } private MavenSettingHelper(); static AuthConfiguration getAuthConfigurationFromServer(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId); }
@Test public void testStart() throws IOException { localAuthServer.stop(); try { localAuthServer.start(); } catch (Exception ex) { fail("Should not fail on after start."); } }
public void start() throws IOException { if (jettyServer.isStarted()) { return; } try { jettyServer.start(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } }
LocalAuthServer { public void start() throws IOException { if (jettyServer.isStarted()) { return; } try { jettyServer.start(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } } }
LocalAuthServer { public void start() throws IOException { if (jettyServer.isStarted()) { return; } try { jettyServer.start(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } } LocalAuthServer(); }
LocalAuthServer { public void start() throws IOException { if (jettyServer.isStarted()) { return; } try { jettyServer.start(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } } LocalAuthServer(); URI getURI(); void start(); void stop(); String waitForCode(); }
LocalAuthServer { public void start() throws IOException { if (jettyServer.isStarted()) { return; } try { jettyServer.start(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } } LocalAuthServer(); URI getURI(); void start(); void stop(); String waitForCode(); }
@Test public void testStop() throws IOException { localAuthServer.stop(); localAuthServer.stop(); }
public void stop() throws IOException { semaphore.release(); try { jettyServer.stop(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } }
LocalAuthServer { public void stop() throws IOException { semaphore.release(); try { jettyServer.stop(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } } }
LocalAuthServer { public void stop() throws IOException { semaphore.release(); try { jettyServer.stop(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } } LocalAuthServer(); }
LocalAuthServer { public void stop() throws IOException { semaphore.release(); try { jettyServer.stop(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } } LocalAuthServer(); URI getURI(); void start(); void stop(); String waitForCode(); }
LocalAuthServer { public void stop() throws IOException { semaphore.release(); try { jettyServer.stop(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IOException(e); } } LocalAuthServer(); URI getURI(); void start(); void stop(); String waitForCode(); }
@Test public void testFromNullResult() { try { AzureCredential.fromAuthenticationResult(null); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } }
public static AzureCredential fromAuthenticationResult(AuthenticationResult result) { if (result == null) { throw new IllegalArgumentException("Parameter \"result\" cannot be null"); } final AzureCredential token = new AzureCredential(); token.setAccessTokenType(result.getAccessTokenType()); token.setAccessToken(result.getAccessToken()); token.setRefreshToken(result.getRefreshToken()); token.setIdToken(result.getIdToken()); token.setUserInfo(result.getUserInfo()); token.setMultipleResourceRefreshToken(result.isMultipleResourceRefreshToken()); return token; }
AzureCredential { public static AzureCredential fromAuthenticationResult(AuthenticationResult result) { if (result == null) { throw new IllegalArgumentException("Parameter \"result\" cannot be null"); } final AzureCredential token = new AzureCredential(); token.setAccessTokenType(result.getAccessTokenType()); token.setAccessToken(result.getAccessToken()); token.setRefreshToken(result.getRefreshToken()); token.setIdToken(result.getIdToken()); token.setUserInfo(result.getUserInfo()); token.setMultipleResourceRefreshToken(result.isMultipleResourceRefreshToken()); return token; } }
AzureCredential { public static AzureCredential fromAuthenticationResult(AuthenticationResult result) { if (result == null) { throw new IllegalArgumentException("Parameter \"result\" cannot be null"); } final AzureCredential token = new AzureCredential(); token.setAccessTokenType(result.getAccessTokenType()); token.setAccessToken(result.getAccessToken()); token.setRefreshToken(result.getRefreshToken()); token.setIdToken(result.getIdToken()); token.setUserInfo(result.getUserInfo()); token.setMultipleResourceRefreshToken(result.isMultipleResourceRefreshToken()); return token; } private AzureCredential(); }
AzureCredential { public static AzureCredential fromAuthenticationResult(AuthenticationResult result) { if (result == null) { throw new IllegalArgumentException("Parameter \"result\" cannot be null"); } final AzureCredential token = new AzureCredential(); token.setAccessTokenType(result.getAccessTokenType()); token.setAccessToken(result.getAccessToken()); token.setRefreshToken(result.getRefreshToken()); token.setIdToken(result.getIdToken()); token.setUserInfo(result.getUserInfo()); token.setMultipleResourceRefreshToken(result.isMultipleResourceRefreshToken()); return token; } private AzureCredential(); static AzureCredential fromAuthenticationResult(AuthenticationResult result); String getAccessTokenType(); void setAccessTokenType(String accessTokenType); String getIdToken(); void setIdToken(String idToken); UserInfo getUserInfo(); void setUserInfo(UserInfo userInfo); String getAccessToken(); void setAccessToken(String accessToken); String getRefreshToken(); void setRefreshToken(String refreshToken); boolean isMultipleResourceRefreshToken(); void setMultipleResourceRefreshToken(boolean isMultipleResourceRefreshToken); String getDefaultSubscription(); void setDefaultSubscription(String defaultSubscription); String getEnvironment(); void setEnvironment(String environment); }
AzureCredential { public static AzureCredential fromAuthenticationResult(AuthenticationResult result) { if (result == null) { throw new IllegalArgumentException("Parameter \"result\" cannot be null"); } final AzureCredential token = new AzureCredential(); token.setAccessTokenType(result.getAccessTokenType()); token.setAccessToken(result.getAccessToken()); token.setRefreshToken(result.getRefreshToken()); token.setIdToken(result.getIdToken()); token.setUserInfo(result.getUserInfo()); token.setMultipleResourceRefreshToken(result.isMultipleResourceRefreshToken()); return token; } private AzureCredential(); static AzureCredential fromAuthenticationResult(AuthenticationResult result); String getAccessTokenType(); void setAccessTokenType(String accessTokenType); String getIdToken(); void setIdToken(String idToken); UserInfo getUserInfo(); void setUserInfo(UserInfo userInfo); String getAccessToken(); void setAccessToken(String accessToken); String getRefreshToken(); void setRefreshToken(String refreshToken); boolean isMultipleResourceRefreshToken(); void setMultipleResourceRefreshToken(boolean isMultipleResourceRefreshToken); String getDefaultSubscription(); void setDefaultSubscription(String defaultSubscription); String getEnvironment(); void setEnvironment(String environment); }
@Test public void testExecute() throws Exception { AzureContextExecutor executor = new AzureContextExecutor(AzureLoginHelper.baseURL(AzureEnvironment.AZURE), t -> null); assertNull(executor.execute()); final AuthenticationResult result = TestHelper.createAuthenticationResult(); executor = new AzureContextExecutor(AzureLoginHelper.baseURL(AzureEnvironment.AZURE), t -> result); final AzureCredential cred = executor.execute(); assertNotNull(cred); assertNotNull(cred.getAccessToken()); assertNotNull(cred.getRefreshToken()); assertNull(cred.getEnvironment()); assertNull(cred.getDefaultSubscription()); }
public AzureCredential execute() throws MalformedURLException, InterruptedException, ExecutionException, AzureLoginTimeoutException { final ExecutorService executorService = Executors.newSingleThreadExecutor(); try { final AuthenticationContext authenticationContext = new AuthenticationContext(baseUrl, true, executorService); final AuthenticationResult result = this.acquireTokenFunc.acquire(authenticationContext); if (result == null) { return null; } return AzureCredential.fromAuthenticationResult(result); } finally { executorService.shutdown(); } }
AzureContextExecutor { public AzureCredential execute() throws MalformedURLException, InterruptedException, ExecutionException, AzureLoginTimeoutException { final ExecutorService executorService = Executors.newSingleThreadExecutor(); try { final AuthenticationContext authenticationContext = new AuthenticationContext(baseUrl, true, executorService); final AuthenticationResult result = this.acquireTokenFunc.acquire(authenticationContext); if (result == null) { return null; } return AzureCredential.fromAuthenticationResult(result); } finally { executorService.shutdown(); } } }
AzureContextExecutor { public AzureCredential execute() throws MalformedURLException, InterruptedException, ExecutionException, AzureLoginTimeoutException { final ExecutorService executorService = Executors.newSingleThreadExecutor(); try { final AuthenticationContext authenticationContext = new AuthenticationContext(baseUrl, true, executorService); final AuthenticationResult result = this.acquireTokenFunc.acquire(authenticationContext); if (result == null) { return null; } return AzureCredential.fromAuthenticationResult(result); } finally { executorService.shutdown(); } } AzureContextExecutor(String baseUrl, AcquireTokenFunction acquireTokenFunc); }
AzureContextExecutor { public AzureCredential execute() throws MalformedURLException, InterruptedException, ExecutionException, AzureLoginTimeoutException { final ExecutorService executorService = Executors.newSingleThreadExecutor(); try { final AuthenticationContext authenticationContext = new AuthenticationContext(baseUrl, true, executorService); final AuthenticationResult result = this.acquireTokenFunc.acquire(authenticationContext); if (result == null) { return null; } return AzureCredential.fromAuthenticationResult(result); } finally { executorService.shutdown(); } } AzureContextExecutor(String baseUrl, AcquireTokenFunction acquireTokenFunc); AzureCredential execute(); }
AzureContextExecutor { public AzureCredential execute() throws MalformedURLException, InterruptedException, ExecutionException, AzureLoginTimeoutException { final ExecutorService executorService = Executors.newSingleThreadExecutor(); try { final AuthenticationContext authenticationContext = new AuthenticationContext(baseUrl, true, executorService); final AuthenticationResult result = this.acquireTokenFunc.acquire(authenticationContext); if (result == null) { return null; } return AzureCredential.fromAuthenticationResult(result); } finally { executorService.shutdown(); } } AzureContextExecutor(String baseUrl, AcquireTokenFunction acquireTokenFunc); AzureCredential execute(); }
@Test public void testOauthWithBrowser() throws Exception { PowerMockito.mockStatic(Desktop.class); final URI uri = new URI("http: final Desktop mockDesktop = mock(Desktop.class); PowerMockito.doNothing().when(mockDesktop).browse(uri); PowerMockito.when(mockDesktop.isSupported(Desktop.Action.BROWSE)).thenReturn(true); PowerMockito.when(Desktop.isDesktopSupported()).thenReturn(true); PowerMockito.when(Desktop.getDesktop()).thenReturn(mockDesktop); mockStatic(LocalAuthServer.class); final LocalAuthServer mockServer = mock(LocalAuthServer.class); whenNew(LocalAuthServer.class).withNoArguments().thenReturn(mockServer); PowerMockito.doNothing().when(mockServer).start(); when(mockServer.getURI()).thenReturn(uri); when(mockServer.waitForCode()).thenReturn("test code"); PowerMockito.doNothing().when(mockServer).stop(); final AuthenticationResult authenticationResult = TestHelper.createAuthenticationResult(); final AuthenticationContext ctx = mock(AuthenticationContext.class); final AzureEnvironment env = AzureEnvironment.AZURE; final Future future = mock(Future.class); whenNew(AuthenticationContext.class).withAnyArguments().thenReturn(ctx); when(future.get()).thenReturn(authenticationResult); when(ctx.acquireTokenByAuthorizationCode("test code", env.managementEndpoint(), Constants.CLIENT_ID, uri, null)).thenReturn(future); final AzureCredential credFromOAuth = AzureLoginHelper.oAuthLogin(AzureEnvironment.AZURE); assertEquals("azure", credFromOAuth.getEnvironment()); assertEquals(authenticationResult.getAccessToken(), credFromOAuth.getAccessToken()); assertEquals(authenticationResult.getRefreshToken(), credFromOAuth.getRefreshToken()); }
static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } }
AzureLoginHelper { static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } } }
AzureLoginHelper { static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } } private AzureLoginHelper(); }
AzureLoginHelper { static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } } private AzureLoginHelper(); }
AzureLoginHelper { static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } } private AzureLoginHelper(); }
@Test public void testOAuthLoginNoBrowser() throws Exception { PowerMockito.mockStatic(Desktop.class); PowerMockito.when(Desktop.isDesktopSupported()).thenReturn(false); try { AzureLoginHelper.oAuthLogin(AzureEnvironment.AZURE); fail("Should report desktop not supported."); } catch (DesktopNotSupportedException e) { } }
static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } }
AzureLoginHelper { static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } } }
AzureLoginHelper { static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } } private AzureLoginHelper(); }
AzureLoginHelper { static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } } private AzureLoginHelper(); }
AzureLoginHelper { static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, ExecutionException, DesktopNotSupportedException, InterruptedException { if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { throw new DesktopNotSupportedException("Not able to launch a browser to log you in."); } final LocalAuthServer server = new LocalAuthServer(); try { server.start(); final URI redirectUri = server.getURI(); final String redirectUrl = redirectUri.toString(); final String code; try { final String authorizationUrl = authorizationUrl(env, redirectUrl); Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); code = server.waitForCode(); } catch (InterruptedException e) { throw new AzureLoginFailureException("The OAuth flow is interrupted."); } finally { server.stop(); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), context -> context .acquireTokenByAuthorizationCode(code, env.managementEndpoint(), Constants.CLIENT_ID, redirectUri, null).get()).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } catch (IOException | URISyntaxException e) { throw new AzureLoginFailureException(e.getMessage()); } } private AzureLoginHelper(); }
@Test public void testDeviceLogin() throws Exception { final AuthenticationResult authenticationResult = TestHelper.createAuthenticationResult(); final AuthenticationContext ctx = mock(AuthenticationContext.class); final AzureEnvironment env = AzureEnvironment.AZURE; final Future future = mock(Future.class); final DeviceCode deviceCode = mock(DeviceCode.class); when(deviceCode.getMessage()).thenReturn("Mock message"); when(deviceCode.getExpiresIn()).thenReturn(Long.valueOf(3600)); when(deviceCode.getInterval()).thenReturn(Long.valueOf(1)); whenNew(AuthenticationContext.class).withAnyArguments().thenReturn(ctx); when(future.get()).thenReturn(deviceCode); when(ctx.acquireDeviceCode(Constants.CLIENT_ID, env.managementEndpoint(), null)) .thenReturn(future); final Future future2 = mock(Future.class); when(future2.get()).thenReturn(authenticationResult); when(ctx.acquireTokenByDeviceCode(deviceCode, null)).thenReturn(future2); final AzureCredential credFromDeviceLogin = AzureLoginHelper.deviceLogin(AzureEnvironment.AZURE); assertEquals("azure", credFromDeviceLogin.getEnvironment()); assertEquals(authenticationResult.getAccessToken(), credFromDeviceLogin.getAccessToken()); assertEquals(authenticationResult.getRefreshToken(), credFromDeviceLogin.getRefreshToken()); }
static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { final String currentLogLevelFieldName = "currentLogLevel"; Object logger = null; Object oldLevelValue = null; try { try { logger = LoggerFactory.getLogger(AuthenticationContext.class); if (logger != null) { oldLevelValue = FieldUtils.readField(logger, currentLogLevelFieldName, true); FieldUtils.writeField(logger, currentLogLevelFieldName, LocationAwareLogger.ERROR_INT + 1, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to disable the log of AuthenticationContext, it will continue being noisy."); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), authenticationContext -> { final DeviceCode deviceCode = authenticationContext.acquireDeviceCode(Constants.CLIENT_ID, env.managementEndpoint(), null).get(); System.out.println(TextUtils.yellow(deviceCode.getMessage())); long remaining = deviceCode.getExpiresIn(); final long interval = deviceCode.getInterval(); while (remaining > 0) { try { remaining -= interval; Thread.sleep(Duration.ofSeconds(interval).toMillis()); return authenticationContext.acquireTokenByDeviceCode(deviceCode, null).get(); } catch (ExecutionException e) { if (e.getCause() instanceof AuthenticationException && ((AuthenticationException) e.getCause()).getErrorCode() == AdalErrorCode.AUTHORIZATION_PENDING) { } else { System.out.println(e.getMessage()); break; } } } throw new AzureLoginTimeoutException( String.format("Cannot proceed with device login after waiting for %d minutes.", deviceCode.getExpiresIn() / 60)); }).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } finally { try { if (logger != null) { FieldUtils.writeField(logger, currentLogLevelFieldName, oldLevelValue, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to reset the log level of AuthenticationContext."); } } }
AzureLoginHelper { static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { final String currentLogLevelFieldName = "currentLogLevel"; Object logger = null; Object oldLevelValue = null; try { try { logger = LoggerFactory.getLogger(AuthenticationContext.class); if (logger != null) { oldLevelValue = FieldUtils.readField(logger, currentLogLevelFieldName, true); FieldUtils.writeField(logger, currentLogLevelFieldName, LocationAwareLogger.ERROR_INT + 1, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to disable the log of AuthenticationContext, it will continue being noisy."); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), authenticationContext -> { final DeviceCode deviceCode = authenticationContext.acquireDeviceCode(Constants.CLIENT_ID, env.managementEndpoint(), null).get(); System.out.println(TextUtils.yellow(deviceCode.getMessage())); long remaining = deviceCode.getExpiresIn(); final long interval = deviceCode.getInterval(); while (remaining > 0) { try { remaining -= interval; Thread.sleep(Duration.ofSeconds(interval).toMillis()); return authenticationContext.acquireTokenByDeviceCode(deviceCode, null).get(); } catch (ExecutionException e) { if (e.getCause() instanceof AuthenticationException && ((AuthenticationException) e.getCause()).getErrorCode() == AdalErrorCode.AUTHORIZATION_PENDING) { } else { System.out.println(e.getMessage()); break; } } } throw new AzureLoginTimeoutException( String.format("Cannot proceed with device login after waiting for %d minutes.", deviceCode.getExpiresIn() / 60)); }).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } finally { try { if (logger != null) { FieldUtils.writeField(logger, currentLogLevelFieldName, oldLevelValue, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to reset the log level of AuthenticationContext."); } } } }
AzureLoginHelper { static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { final String currentLogLevelFieldName = "currentLogLevel"; Object logger = null; Object oldLevelValue = null; try { try { logger = LoggerFactory.getLogger(AuthenticationContext.class); if (logger != null) { oldLevelValue = FieldUtils.readField(logger, currentLogLevelFieldName, true); FieldUtils.writeField(logger, currentLogLevelFieldName, LocationAwareLogger.ERROR_INT + 1, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to disable the log of AuthenticationContext, it will continue being noisy."); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), authenticationContext -> { final DeviceCode deviceCode = authenticationContext.acquireDeviceCode(Constants.CLIENT_ID, env.managementEndpoint(), null).get(); System.out.println(TextUtils.yellow(deviceCode.getMessage())); long remaining = deviceCode.getExpiresIn(); final long interval = deviceCode.getInterval(); while (remaining > 0) { try { remaining -= interval; Thread.sleep(Duration.ofSeconds(interval).toMillis()); return authenticationContext.acquireTokenByDeviceCode(deviceCode, null).get(); } catch (ExecutionException e) { if (e.getCause() instanceof AuthenticationException && ((AuthenticationException) e.getCause()).getErrorCode() == AdalErrorCode.AUTHORIZATION_PENDING) { } else { System.out.println(e.getMessage()); break; } } } throw new AzureLoginTimeoutException( String.format("Cannot proceed with device login after waiting for %d minutes.", deviceCode.getExpiresIn() / 60)); }).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } finally { try { if (logger != null) { FieldUtils.writeField(logger, currentLogLevelFieldName, oldLevelValue, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to reset the log level of AuthenticationContext."); } } } private AzureLoginHelper(); }
AzureLoginHelper { static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { final String currentLogLevelFieldName = "currentLogLevel"; Object logger = null; Object oldLevelValue = null; try { try { logger = LoggerFactory.getLogger(AuthenticationContext.class); if (logger != null) { oldLevelValue = FieldUtils.readField(logger, currentLogLevelFieldName, true); FieldUtils.writeField(logger, currentLogLevelFieldName, LocationAwareLogger.ERROR_INT + 1, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to disable the log of AuthenticationContext, it will continue being noisy."); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), authenticationContext -> { final DeviceCode deviceCode = authenticationContext.acquireDeviceCode(Constants.CLIENT_ID, env.managementEndpoint(), null).get(); System.out.println(TextUtils.yellow(deviceCode.getMessage())); long remaining = deviceCode.getExpiresIn(); final long interval = deviceCode.getInterval(); while (remaining > 0) { try { remaining -= interval; Thread.sleep(Duration.ofSeconds(interval).toMillis()); return authenticationContext.acquireTokenByDeviceCode(deviceCode, null).get(); } catch (ExecutionException e) { if (e.getCause() instanceof AuthenticationException && ((AuthenticationException) e.getCause()).getErrorCode() == AdalErrorCode.AUTHORIZATION_PENDING) { } else { System.out.println(e.getMessage()); break; } } } throw new AzureLoginTimeoutException( String.format("Cannot proceed with device login after waiting for %d minutes.", deviceCode.getExpiresIn() / 60)); }).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } finally { try { if (logger != null) { FieldUtils.writeField(logger, currentLogLevelFieldName, oldLevelValue, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to reset the log level of AuthenticationContext."); } } } private AzureLoginHelper(); }
AzureLoginHelper { static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { final String currentLogLevelFieldName = "currentLogLevel"; Object logger = null; Object oldLevelValue = null; try { try { logger = LoggerFactory.getLogger(AuthenticationContext.class); if (logger != null) { oldLevelValue = FieldUtils.readField(logger, currentLogLevelFieldName, true); FieldUtils.writeField(logger, currentLogLevelFieldName, LocationAwareLogger.ERROR_INT + 1, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to disable the log of AuthenticationContext, it will continue being noisy."); } final AzureCredential cred = new AzureContextExecutor(baseURL(env), authenticationContext -> { final DeviceCode deviceCode = authenticationContext.acquireDeviceCode(Constants.CLIENT_ID, env.managementEndpoint(), null).get(); System.out.println(TextUtils.yellow(deviceCode.getMessage())); long remaining = deviceCode.getExpiresIn(); final long interval = deviceCode.getInterval(); while (remaining > 0) { try { remaining -= interval; Thread.sleep(Duration.ofSeconds(interval).toMillis()); return authenticationContext.acquireTokenByDeviceCode(deviceCode, null).get(); } catch (ExecutionException e) { if (e.getCause() instanceof AuthenticationException && ((AuthenticationException) e.getCause()).getErrorCode() == AdalErrorCode.AUTHORIZATION_PENDING) { } else { System.out.println(e.getMessage()); break; } } } throw new AzureLoginTimeoutException( String.format("Cannot proceed with device login after waiting for %d minutes.", deviceCode.getExpiresIn() / 60)); }).execute(); cred.setEnvironment(getShortNameForAzureEnvironment(env)); return cred; } finally { try { if (logger != null) { FieldUtils.writeField(logger, currentLogLevelFieldName, oldLevelValue, true); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Failed to reset the log level of AuthenticationContext."); } } } private AzureLoginHelper(); }
@Test public void testRefreshToken() throws Exception { final AuthenticationResult authenticationResult = TestHelper.createAuthenticationResult(); final AuthenticationContext ctx = mock(AuthenticationContext.class); final AzureEnvironment env = AzureEnvironment.AZURE; final Future future = mock(Future.class); whenNew(AuthenticationContext.class).withAnyArguments().thenReturn(ctx); when(future.get()).thenReturn(authenticationResult); when(ctx.acquireTokenByRefreshToken("token for power mock", Constants.CLIENT_ID, env.managementEndpoint(), null)) .thenReturn(future); final Map<String, Object> map = TestHelper.getAuthenticationMap(); final AzureCredential cred = AzureLoginHelper.refreshToken(env, "token for power mock"); assertNotNull(cred); assertEquals(map.get("accessTokenType"), cred.getAccessTokenType()); assertEquals(map.get("accessToken"), cred.getAccessToken()); assertEquals(map.get("refreshToken"), cred.getRefreshToken()); assertEquals(map.get("idToken"), cred.getIdToken()); assertEquals(map.get("isMultipleResourceRefreshToken"), cred.isMultipleResourceRefreshToken()); }
static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(refreshToken)) { throw new IllegalArgumentException("Parameter 'refreshToken' cannot be empty."); } try { return new AzureContextExecutor(baseURL(env), authenticationContext -> authenticationContext .acquireTokenByRefreshToken(refreshToken, Constants.CLIENT_ID, env.managementEndpoint(), null).get()).execute(); } catch (AzureLoginTimeoutException e) { return null; } }
AzureLoginHelper { static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(refreshToken)) { throw new IllegalArgumentException("Parameter 'refreshToken' cannot be empty."); } try { return new AzureContextExecutor(baseURL(env), authenticationContext -> authenticationContext .acquireTokenByRefreshToken(refreshToken, Constants.CLIENT_ID, env.managementEndpoint(), null).get()).execute(); } catch (AzureLoginTimeoutException e) { return null; } } }
AzureLoginHelper { static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(refreshToken)) { throw new IllegalArgumentException("Parameter 'refreshToken' cannot be empty."); } try { return new AzureContextExecutor(baseURL(env), authenticationContext -> authenticationContext .acquireTokenByRefreshToken(refreshToken, Constants.CLIENT_ID, env.managementEndpoint(), null).get()).execute(); } catch (AzureLoginTimeoutException e) { return null; } } private AzureLoginHelper(); }
AzureLoginHelper { static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(refreshToken)) { throw new IllegalArgumentException("Parameter 'refreshToken' cannot be empty."); } try { return new AzureContextExecutor(baseURL(env), authenticationContext -> authenticationContext .acquireTokenByRefreshToken(refreshToken, Constants.CLIENT_ID, env.managementEndpoint(), null).get()).execute(); } catch (AzureLoginTimeoutException e) { return null; } } private AzureLoginHelper(); }
AzureLoginHelper { static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(refreshToken)) { throw new IllegalArgumentException("Parameter 'refreshToken' cannot be empty."); } try { return new AzureContextExecutor(baseURL(env), authenticationContext -> authenticationContext .acquireTokenByRefreshToken(refreshToken, Constants.CLIENT_ID, env.managementEndpoint(), null).get()).execute(); } catch (AzureLoginTimeoutException e) { return null; } } private AzureLoginHelper(); }
@Test public void doExecute() throws Exception { final AddMojo mojo = getMojoFromPom(); final Settings settings = new Settings(); settings.setInteractiveMode(false); ReflectionUtils.setVariableValueInObject(mojo, "basedir", new File("target/test")); ReflectionUtils.setVariableValueInObject(mojo, "settings", settings); mojo.setFunctionTemplate("HttpTrigger"); mojo.setFunctionName("New-Function"); mojo.setFunctionPackageName("com.microsoft.azure"); final File newFunctionFile = new File("target/test/src/main/java/com/microsoft/azure/New_Function.java"); newFunctionFile.delete(); mojo.doExecute(); assertTrue(newFunctionFile.exists()); }
@Override protected void doExecute() throws AzureExecutionException { try { final List<FunctionTemplate> templates = loadAllFunctionTemplates(); final FunctionTemplate template = getFunctionTemplate(templates); final BindingTemplate bindingTemplate = FunctionUtils.loadBindingTemplate(template.getTriggerType()); final Map params = prepareRequiredParameters(template, bindingTemplate); final String newFunctionClass = substituteParametersInTemplate(template, params); saveNewFunctionToFile(newFunctionClass); } catch (MojoFailureException | IOException e) { throw new AzureExecutionException("Cannot add new java functions.", e); } }
AddMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { final List<FunctionTemplate> templates = loadAllFunctionTemplates(); final FunctionTemplate template = getFunctionTemplate(templates); final BindingTemplate bindingTemplate = FunctionUtils.loadBindingTemplate(template.getTriggerType()); final Map params = prepareRequiredParameters(template, bindingTemplate); final String newFunctionClass = substituteParametersInTemplate(template, params); saveNewFunctionToFile(newFunctionClass); } catch (MojoFailureException | IOException e) { throw new AzureExecutionException("Cannot add new java functions.", e); } } }
AddMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { final List<FunctionTemplate> templates = loadAllFunctionTemplates(); final FunctionTemplate template = getFunctionTemplate(templates); final BindingTemplate bindingTemplate = FunctionUtils.loadBindingTemplate(template.getTriggerType()); final Map params = prepareRequiredParameters(template, bindingTemplate); final String newFunctionClass = substituteParametersInTemplate(template, params); saveNewFunctionToFile(newFunctionClass); } catch (MojoFailureException | IOException e) { throw new AzureExecutionException("Cannot add new java functions.", e); } } }
AddMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { final List<FunctionTemplate> templates = loadAllFunctionTemplates(); final FunctionTemplate template = getFunctionTemplate(templates); final BindingTemplate bindingTemplate = FunctionUtils.loadBindingTemplate(template.getTriggerType()); final Map params = prepareRequiredParameters(template, bindingTemplate); final String newFunctionClass = substituteParametersInTemplate(template, params); saveNewFunctionToFile(newFunctionClass); } catch (MojoFailureException | IOException e) { throw new AzureExecutionException("Cannot add new java functions.", e); } } String getFunctionPackageName(); String getFunctionName(); String getClassName(); String getFunctionTemplate(); }
AddMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { final List<FunctionTemplate> templates = loadAllFunctionTemplates(); final FunctionTemplate template = getFunctionTemplate(templates); final BindingTemplate bindingTemplate = FunctionUtils.loadBindingTemplate(template.getTriggerType()); final Map params = prepareRequiredParameters(template, bindingTemplate); final String newFunctionClass = substituteParametersInTemplate(template, params); saveNewFunctionToFile(newFunctionClass); } catch (MojoFailureException | IOException e) { throw new AzureExecutionException("Cannot add new java functions.", e); } } String getFunctionPackageName(); String getFunctionName(); String getClassName(); String getFunctionTemplate(); }
@Test public void testAuthorizationUrl() throws Exception { String url = AzureLoginHelper.authorizationUrl(AzureEnvironment.AZURE, "http: Map<String, String> queryMap = splitQuery(url); assertEquals(Constants.CLIENT_ID, queryMap.get("client_id")); assertEquals("http: assertEquals("code", queryMap.get("response_type")); assertEquals("select_account", queryMap.get("prompt")); assertEquals(AzureEnvironment.AZURE.activeDirectoryResourceId(), queryMap.get("resource")); url = AzureLoginHelper.authorizationUrl(AzureEnvironment.AZURE_CHINA, "http: queryMap = splitQuery(url); assertEquals(Constants.CLIENT_ID, queryMap.get("client_id")); assertEquals("http: assertEquals("code", queryMap.get("response_type")); assertEquals("select_account", queryMap.get("prompt")); assertEquals(AzureEnvironment.AZURE_CHINA.activeDirectoryResourceId(), queryMap.get("resource")); }
static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); }
AzureLoginHelper { static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); } }
AzureLoginHelper { static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); } private AzureLoginHelper(); }
AzureLoginHelper { static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); } private AzureLoginHelper(); }
AzureLoginHelper { static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); } private AzureLoginHelper(); }
@Test public void tesAuthorizationUrlInvalidParameter() throws Exception { try { AzureLoginHelper.authorizationUrl(null, "http: fail("Should throw IAE when env is null."); } catch (IllegalArgumentException e) { } try { AzureLoginHelper.authorizationUrl(AzureEnvironment.AZURE_CHINA, ""); fail("Should throw IAE when redirectUrl is empty."); } catch (IllegalArgumentException e) { } }
static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); }
AzureLoginHelper { static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); } }
AzureLoginHelper { static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); } private AzureLoginHelper(); }
AzureLoginHelper { static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); } private AzureLoginHelper(); }
AzureLoginHelper { static String authorizationUrl(AzureEnvironment env, String redirectUrl) throws URISyntaxException, MalformedURLException { if (env == null) { throw new IllegalArgumentException("Parameter 'env' cannot be null."); } if (StringUtils.isBlank(redirectUrl)) { throw new IllegalArgumentException("Parameter 'redirectUrl' cannot be empty."); } final URIBuilder builder = new URIBuilder(baseURL(env)); builder.setPath(String.format("%s/oauth2/authorize", builder.getPath())) .setParameter("client_id", Constants.CLIENT_ID) .setParameter("response_type", "code") .setParameter("redirect_uri", redirectUrl) .setParameter("prompt", "select_account") .setParameter("resource", env.managementEndpoint()); return builder.build().toURL().toString(); } private AzureLoginHelper(); }
@Test public void testBaseURL() { String baseUrl = AzureLoginHelper.baseURL(AzureEnvironment.AZURE); assertEquals("https: baseUrl = AzureLoginHelper.baseURL(AzureEnvironment.AZURE_US_GOVERNMENT); assertEquals("https: }
static String baseURL(AzureEnvironment env) { return env.activeDirectoryEndpoint() + Constants.COMMON_TENANT; }
AzureLoginHelper { static String baseURL(AzureEnvironment env) { return env.activeDirectoryEndpoint() + Constants.COMMON_TENANT; } }
AzureLoginHelper { static String baseURL(AzureEnvironment env) { return env.activeDirectoryEndpoint() + Constants.COMMON_TENANT; } private AzureLoginHelper(); }
AzureLoginHelper { static String baseURL(AzureEnvironment env) { return env.activeDirectoryEndpoint() + Constants.COMMON_TENANT; } private AzureLoginHelper(); }
AzureLoginHelper { static String baseURL(AzureEnvironment env) { return env.activeDirectoryEndpoint() + Constants.COMMON_TENANT; } private AzureLoginHelper(); }
@Test public void testAzureEnvironmentShortName() { assertEquals("azure", AzureLoginHelper.getShortNameForAzureEnvironment(AzureEnvironment.AZURE)); assertEquals("azure_china", AzureLoginHelper.getShortNameForAzureEnvironment(AzureEnvironment.AZURE_CHINA)); assertEquals("azure_us_government", AzureLoginHelper.getShortNameForAzureEnvironment(AzureEnvironment.AZURE_US_GOVERNMENT)); assertNull(AzureLoginHelper.getShortNameForAzureEnvironment(null)); }
static String getShortNameForAzureEnvironment(AzureEnvironment env) { return AZURE_ENVIRONMENT_MAP.get(env); }
AzureLoginHelper { static String getShortNameForAzureEnvironment(AzureEnvironment env) { return AZURE_ENVIRONMENT_MAP.get(env); } }
AzureLoginHelper { static String getShortNameForAzureEnvironment(AzureEnvironment env) { return AZURE_ENVIRONMENT_MAP.get(env); } private AzureLoginHelper(); }
AzureLoginHelper { static String getShortNameForAzureEnvironment(AzureEnvironment env) { return AZURE_ENVIRONMENT_MAP.get(env); } private AzureLoginHelper(); }
AzureLoginHelper { static String getShortNameForAzureEnvironment(AzureEnvironment env) { return AZURE_ENVIRONMENT_MAP.get(env); } private AzureLoginHelper(); }
@Test public void testOAuthLogin() throws Exception { final AzureEnvironment env = AzureEnvironment.AZURE; final AzureCredential credExpected = AzureCredential.fromAuthenticationResult(TestHelper.createAuthenticationResult()); mockStatic(AzureLoginHelper.class); when(AzureLoginHelper.oAuthLogin(env)).thenReturn(credExpected); final AzureCredential cred = AzureAuthHelper.oAuthLogin(env); assertEquals(credExpected, cred); }
public static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, DesktopNotSupportedException, InterruptedException, ExecutionException { return AzureLoginHelper.oAuthLogin(env); }
AzureAuthHelper { public static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, DesktopNotSupportedException, InterruptedException, ExecutionException { return AzureLoginHelper.oAuthLogin(env); } }
AzureAuthHelper { public static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, DesktopNotSupportedException, InterruptedException, ExecutionException { return AzureLoginHelper.oAuthLogin(env); } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, DesktopNotSupportedException, InterruptedException, ExecutionException { return AzureLoginHelper.oAuthLogin(env); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureCredential oAuthLogin(AzureEnvironment env) throws AzureLoginFailureException, DesktopNotSupportedException, InterruptedException, ExecutionException { return AzureLoginHelper.oAuthLogin(env); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testDeviceLogin() throws Exception { final AzureEnvironment env = AzureEnvironment.AZURE; final AzureCredential credExpected = AzureCredential.fromAuthenticationResult(TestHelper.createAuthenticationResult()); mockStatic(AzureLoginHelper.class); when(AzureLoginHelper.deviceLogin(env)).thenReturn(credExpected); final AzureCredential cred = AzureAuthHelper.deviceLogin(env); assertEquals(credExpected, cred); }
public static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.deviceLogin(env); }
AzureAuthHelper { public static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.deviceLogin(env); } }
AzureAuthHelper { public static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.deviceLogin(env); } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.deviceLogin(env); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureCredential deviceLogin(AzureEnvironment env) throws AzureLoginFailureException, MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.deviceLogin(env); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testRefreshToken() throws Exception { final AzureEnvironment env = AzureEnvironment.AZURE; final AzureCredential credExpected = AzureCredential.fromAuthenticationResult(TestHelper.createAuthenticationResult()); mockStatic(AzureLoginHelper.class); when(AzureLoginHelper.refreshToken(env, "token for power mock")).thenReturn(credExpected); final AzureCredential cred = AzureAuthHelper.refreshToken(env, "token for power mock"); assertEquals(credExpected, cred); }
public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testRefreshTokenInvalidToken() throws Exception { try { AzureAuthHelper.refreshToken(AzureEnvironment.AZURE, "invalid"); fail("Should throw AzureLoginFailureException when refreshToken is invalid."); } catch (ExecutionException e) { } }
public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testRefreshTokenInvalidParameter() throws Exception { try { AzureAuthHelper.refreshToken(null, "abc"); fail("Should throw IAE when env is null."); } catch (IllegalArgumentException e) { } try { AzureAuthHelper.refreshToken(AzureEnvironment.AZURE_CHINA, ""); fail("Should throw IAE when refreshToken is empty."); } catch (IllegalArgumentException e) { } }
public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureCredential refreshToken(AzureEnvironment env, String refreshToken) throws MalformedURLException, InterruptedException, ExecutionException { return AzureLoginHelper.refreshToken(env, refreshToken); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testGetAzureEnvironment() { assertEquals(AzureEnvironment.AZURE, AzureAuthHelper.getAzureEnvironment(null)); assertEquals(AzureEnvironment.AZURE, AzureAuthHelper.getAzureEnvironment(" ")); assertEquals(AzureEnvironment.AZURE, AzureAuthHelper.getAzureEnvironment("azure")); assertEquals(AzureEnvironment.AZURE, AzureAuthHelper.getAzureEnvironment("aZUre")); assertEquals(AzureEnvironment.AZURE, AzureAuthHelper.getAzureEnvironment("AZURE_CLOUD")); assertEquals(AzureEnvironment.AZURE_GERMANY, AzureAuthHelper.getAzureEnvironment("AZURE_GERMANY")); assertEquals(AzureEnvironment.AZURE_GERMANY, AzureAuthHelper.getAzureEnvironment("AzureGermanCloud")); assertEquals(AzureEnvironment.AZURE_GERMANY, AzureAuthHelper.getAzureEnvironment("AZUREGERMANCLOUD")); assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT, AzureAuthHelper.getAzureEnvironment("AZURE_US_GOVERNMENT")); assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT, AzureAuthHelper.getAzureEnvironment("AZUREUSGOVERNMENT")); assertEquals(AzureEnvironment.AZURE_CHINA, AzureAuthHelper.getAzureEnvironment("AzureChinaCloud")); assertEquals(AzureEnvironment.AZURE_CHINA, AzureAuthHelper.getAzureEnvironment("Azure_China")); assertEquals(AzureEnvironment.AZURE, AzureAuthHelper.getAzureEnvironment("AzureChinaCloud ")); }
public static AzureEnvironment getAzureEnvironment(String environment) { if (StringUtils.isEmpty(environment)) { return AzureEnvironment.AZURE; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": return AzureEnvironment.AZURE_CHINA; case "AZURE_GERMANY": case "AZUREGERMANCLOUD": return AzureEnvironment.AZURE_GERMANY; case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": return AzureEnvironment.AZURE_US_GOVERNMENT; default: return AzureEnvironment.AZURE; } }
AzureAuthHelper { public static AzureEnvironment getAzureEnvironment(String environment) { if (StringUtils.isEmpty(environment)) { return AzureEnvironment.AZURE; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": return AzureEnvironment.AZURE_CHINA; case "AZURE_GERMANY": case "AZUREGERMANCLOUD": return AzureEnvironment.AZURE_GERMANY; case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": return AzureEnvironment.AZURE_US_GOVERNMENT; default: return AzureEnvironment.AZURE; } } }
AzureAuthHelper { public static AzureEnvironment getAzureEnvironment(String environment) { if (StringUtils.isEmpty(environment)) { return AzureEnvironment.AZURE; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": return AzureEnvironment.AZURE_CHINA; case "AZURE_GERMANY": case "AZUREGERMANCLOUD": return AzureEnvironment.AZURE_GERMANY; case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": return AzureEnvironment.AZURE_US_GOVERNMENT; default: return AzureEnvironment.AZURE; } } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureEnvironment getAzureEnvironment(String environment) { if (StringUtils.isEmpty(environment)) { return AzureEnvironment.AZURE; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": return AzureEnvironment.AZURE_CHINA; case "AZURE_GERMANY": case "AZUREGERMANCLOUD": return AzureEnvironment.AZURE_GERMANY; case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": return AzureEnvironment.AZURE_US_GOVERNMENT; default: return AzureEnvironment.AZURE; } } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureEnvironment getAzureEnvironment(String environment) { if (StringUtils.isEmpty(environment)) { return AzureEnvironment.AZURE; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": return AzureEnvironment.AZURE_CHINA; case "AZURE_GERMANY": case "AZUREGERMANCLOUD": return AzureEnvironment.AZURE_GERMANY; case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": return AzureEnvironment.AZURE_US_GOVERNMENT; default: return AzureEnvironment.AZURE; } } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void assureInputFromUser() throws Exception { final AddMojo mojo = getMojoFromPom(); final AddMojo mojoSpy = spy(mojo); final Scanner scanner = mock(Scanner.class); doReturn("2").when(scanner).nextLine(); doReturn(scanner).when(mojoSpy).getScanner(); final Set<String> set = new HashSet<>(); mojoSpy.assureInputFromUser("property", "", Arrays.asList("a0", "a1", "a2"), set::add); assertTrue(set.contains("a2")); }
protected void assureInputFromUser(final String prompt, final String initValue, final List<String> options, final Consumer<String> setter) { final String option = findElementInOptions(options, initValue); if (option != null) { Log.info(FOUND_VALID_VALUE); setter.accept(option); return; } out.printf("Choose from below options as %s %n", prompt); for (int i = 0; i < options.size(); i++) { out.printf("%d. %s%n", i, options.get(i)); } assureInputFromUser("Enter index to use: ", null, str -> { try { final int index = Integer.parseInt(str); return 0 <= index && index < options.size(); } catch (Exception e) { return false; } }, "Invalid index.", str -> { final int index = Integer.parseInt(str); setter.accept(options.get(index)); } ); }
AddMojo extends AbstractFunctionMojo { protected void assureInputFromUser(final String prompt, final String initValue, final List<String> options, final Consumer<String> setter) { final String option = findElementInOptions(options, initValue); if (option != null) { Log.info(FOUND_VALID_VALUE); setter.accept(option); return; } out.printf("Choose from below options as %s %n", prompt); for (int i = 0; i < options.size(); i++) { out.printf("%d. %s%n", i, options.get(i)); } assureInputFromUser("Enter index to use: ", null, str -> { try { final int index = Integer.parseInt(str); return 0 <= index && index < options.size(); } catch (Exception e) { return false; } }, "Invalid index.", str -> { final int index = Integer.parseInt(str); setter.accept(options.get(index)); } ); } }
AddMojo extends AbstractFunctionMojo { protected void assureInputFromUser(final String prompt, final String initValue, final List<String> options, final Consumer<String> setter) { final String option = findElementInOptions(options, initValue); if (option != null) { Log.info(FOUND_VALID_VALUE); setter.accept(option); return; } out.printf("Choose from below options as %s %n", prompt); for (int i = 0; i < options.size(); i++) { out.printf("%d. %s%n", i, options.get(i)); } assureInputFromUser("Enter index to use: ", null, str -> { try { final int index = Integer.parseInt(str); return 0 <= index && index < options.size(); } catch (Exception e) { return false; } }, "Invalid index.", str -> { final int index = Integer.parseInt(str); setter.accept(options.get(index)); } ); } }
AddMojo extends AbstractFunctionMojo { protected void assureInputFromUser(final String prompt, final String initValue, final List<String> options, final Consumer<String> setter) { final String option = findElementInOptions(options, initValue); if (option != null) { Log.info(FOUND_VALID_VALUE); setter.accept(option); return; } out.printf("Choose from below options as %s %n", prompt); for (int i = 0; i < options.size(); i++) { out.printf("%d. %s%n", i, options.get(i)); } assureInputFromUser("Enter index to use: ", null, str -> { try { final int index = Integer.parseInt(str); return 0 <= index && index < options.size(); } catch (Exception e) { return false; } }, "Invalid index.", str -> { final int index = Integer.parseInt(str); setter.accept(options.get(index)); } ); } String getFunctionPackageName(); String getFunctionName(); String getClassName(); String getFunctionTemplate(); }
AddMojo extends AbstractFunctionMojo { protected void assureInputFromUser(final String prompt, final String initValue, final List<String> options, final Consumer<String> setter) { final String option = findElementInOptions(options, initValue); if (option != null) { Log.info(FOUND_VALID_VALUE); setter.accept(option); return; } out.printf("Choose from below options as %s %n", prompt); for (int i = 0; i < options.size(); i++) { out.printf("%d. %s%n", i, options.get(i)); } assureInputFromUser("Enter index to use: ", null, str -> { try { final int index = Integer.parseInt(str); return 0 <= index && index < options.size(); } catch (Exception e) { return false; } }, "Invalid index.", str -> { final int index = Integer.parseInt(str); setter.accept(options.get(index)); } ); } String getFunctionPackageName(); String getFunctionName(); String getClassName(); String getFunctionTemplate(); }
@Test public void testEnvironmentValidation() { assertTrue(AzureAuthHelper.validateEnvironment(null)); assertTrue(AzureAuthHelper.validateEnvironment("")); assertTrue(AzureAuthHelper.validateEnvironment(" ")); assertTrue(AzureAuthHelper.validateEnvironment("azure")); assertFalse(AzureAuthHelper.validateEnvironment("azure ")); assertTrue(AzureAuthHelper.validateEnvironment("azure_cloud")); assertTrue(AzureAuthHelper.validateEnvironment("AZURE_CLOUD")); assertTrue(AzureAuthHelper.validateEnvironment("aZURe")); assertFalse(AzureAuthHelper.validateEnvironment("aZURe ")); assertFalse(AzureAuthHelper.validateEnvironment("foo")); }
public static boolean validateEnvironment(String environment) { if (StringUtils.isBlank(environment)) { return true; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": case "AZURE_GERMANY": case "AZUREGERMANCLOUD": case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": case "AZURE": case "AZURE_CLOUD": return true; default : return false; } }
AzureAuthHelper { public static boolean validateEnvironment(String environment) { if (StringUtils.isBlank(environment)) { return true; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": case "AZURE_GERMANY": case "AZUREGERMANCLOUD": case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": case "AZURE": case "AZURE_CLOUD": return true; default : return false; } } }
AzureAuthHelper { public static boolean validateEnvironment(String environment) { if (StringUtils.isBlank(environment)) { return true; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": case "AZURE_GERMANY": case "AZUREGERMANCLOUD": case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": case "AZURE": case "AZURE_CLOUD": return true; default : return false; } } private AzureAuthHelper(); }
AzureAuthHelper { public static boolean validateEnvironment(String environment) { if (StringUtils.isBlank(environment)) { return true; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": case "AZURE_GERMANY": case "AZUREGERMANCLOUD": case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": case "AZURE": case "AZURE_CLOUD": return true; default : return false; } } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static boolean validateEnvironment(String environment) { if (StringUtils.isBlank(environment)) { return true; } switch (environment.toUpperCase(Locale.ENGLISH)) { case "AZURE_CHINA": case "AZURECHINACLOUD": case "AZURE_GERMANY": case "AZUREGERMANCLOUD": case "AZURE_US_GOVERNMENT": case "AZUREUSGOVERNMENT": case "AZURE": case "AZURE_CLOUD": return true; default : return false; } } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testGetAzureSecretFile() { TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, null); final File azureSecretFile = AzureAuthHelper.getAzureSecretFile(); assertEquals(Paths.get(System.getProperty("user.home"), ".azure", "azure-secret.json").toString(), azureSecretFile.getAbsolutePath()); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, "test_dir"); assertEquals(Paths.get("test_dir", "azure-secret.json").toFile().getAbsolutePath(), AzureAuthHelper.getAzureSecretFile().getAbsolutePath()); }
public static File getAzureSecretFile() { return new File(getAzureConfigFolder(), Constants.AZURE_SECRET_FILE); }
AzureAuthHelper { public static File getAzureSecretFile() { return new File(getAzureConfigFolder(), Constants.AZURE_SECRET_FILE); } }
AzureAuthHelper { public static File getAzureSecretFile() { return new File(getAzureConfigFolder(), Constants.AZURE_SECRET_FILE); } private AzureAuthHelper(); }
AzureAuthHelper { public static File getAzureSecretFile() { return new File(getAzureConfigFolder(), Constants.AZURE_SECRET_FILE); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static File getAzureSecretFile() { return new File(getAzureConfigFolder(), Constants.AZURE_SECRET_FILE); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testGetAzureConfigFolder() { TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, null); final File azureConfigFolder = AzureAuthHelper.getAzureConfigFolder(); assertEquals(Paths.get(System.getProperty("user.home"), ".azure").toString(), azureConfigFolder.getAbsolutePath()); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, "test_dir"); assertEquals(Paths.get("test_dir").toFile().getAbsolutePath(), AzureAuthHelper.getAzureConfigFolder().getAbsolutePath()); }
public static File getAzureConfigFolder() { return StringUtils.isNotBlank(System.getenv(Constants.AZURE_CONFIG_DIR)) ? new File(System.getenv(Constants.AZURE_CONFIG_DIR)) : Paths.get(System.getProperty(Constants.USER_HOME), Constants.AZURE_FOLDER).toFile(); }
AzureAuthHelper { public static File getAzureConfigFolder() { return StringUtils.isNotBlank(System.getenv(Constants.AZURE_CONFIG_DIR)) ? new File(System.getenv(Constants.AZURE_CONFIG_DIR)) : Paths.get(System.getProperty(Constants.USER_HOME), Constants.AZURE_FOLDER).toFile(); } }
AzureAuthHelper { public static File getAzureConfigFolder() { return StringUtils.isNotBlank(System.getenv(Constants.AZURE_CONFIG_DIR)) ? new File(System.getenv(Constants.AZURE_CONFIG_DIR)) : Paths.get(System.getProperty(Constants.USER_HOME), Constants.AZURE_FOLDER).toFile(); } private AzureAuthHelper(); }
AzureAuthHelper { public static File getAzureConfigFolder() { return StringUtils.isNotBlank(System.getenv(Constants.AZURE_CONFIG_DIR)) ? new File(System.getenv(Constants.AZURE_CONFIG_DIR)) : Paths.get(System.getProperty(Constants.USER_HOME), Constants.AZURE_FOLDER).toFile(); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static File getAzureConfigFolder() { return StringUtils.isNotBlank(System.getenv(Constants.AZURE_CONFIG_DIR)) ? new File(System.getenv(Constants.AZURE_CONFIG_DIR)) : Paths.get(System.getProperty(Constants.USER_HOME), Constants.AZURE_FOLDER).toFile(); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testExistsAzureSecretFile() { final File testConfigDir = new File(this.getClass().getResource("/azure-login/azure-secret.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); assertTrue(AzureAuthHelper.existsAzureSecretFile()); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getParentFile().getAbsolutePath()); assertFalse(AzureAuthHelper.existsAzureSecretFile()); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, ""); }
public static boolean existsAzureSecretFile() { final File azureSecretFile = getAzureSecretFile(); return azureSecretFile.exists() && azureSecretFile.isFile() && azureSecretFile.length() > 0; }
AzureAuthHelper { public static boolean existsAzureSecretFile() { final File azureSecretFile = getAzureSecretFile(); return azureSecretFile.exists() && azureSecretFile.isFile() && azureSecretFile.length() > 0; } }
AzureAuthHelper { public static boolean existsAzureSecretFile() { final File azureSecretFile = getAzureSecretFile(); return azureSecretFile.exists() && azureSecretFile.isFile() && azureSecretFile.length() > 0; } private AzureAuthHelper(); }
AzureAuthHelper { public static boolean existsAzureSecretFile() { final File azureSecretFile = getAzureSecretFile(); return azureSecretFile.exists() && azureSecretFile.isFile() && azureSecretFile.length() > 0; } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static boolean existsAzureSecretFile() { final File azureSecretFile = getAzureSecretFile(); return azureSecretFile.exists() && azureSecretFile.isFile() && azureSecretFile.length() > 0; } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testReadAzureCredentials() throws Exception { final File testConfigDir = new File(this.getClass().getResource("/azure-login/azure-secret.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); assertTrue(AzureAuthHelper.existsAzureSecretFile()); assertNotNull(AzureAuthHelper.readAzureCredentials()); try { AzureAuthHelper.readAzureCredentials(null); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } }
public static AzureCredential readAzureCredentials() throws IOException { return readAzureCredentials(getAzureSecretFile()); }
AzureAuthHelper { public static AzureCredential readAzureCredentials() throws IOException { return readAzureCredentials(getAzureSecretFile()); } }
AzureAuthHelper { public static AzureCredential readAzureCredentials() throws IOException { return readAzureCredentials(getAzureSecretFile()); } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureCredential readAzureCredentials() throws IOException { return readAzureCredentials(getAzureSecretFile()); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureCredential readAzureCredentials() throws IOException { return readAzureCredentials(getAzureSecretFile()); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testWriteAzureCredentials() throws Exception { final File testConfigDir = new File(this.getClass().getResource("/azure-login/azure-secret.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); assertTrue(AzureAuthHelper.existsAzureSecretFile()); final AzureCredential cred = AzureAuthHelper.readAzureCredentials(); final File tempFile = new File(tempDirectory, "azure-secret.json"); AzureAuthHelper.writeAzureCredentials(cred, tempFile); final AzureCredential cred2 = AzureAuthHelper.readAzureCredentials(tempFile); assertEquals(cred.getAccessToken(), cred2.getAccessToken()); assertEquals(cred.getAccessTokenType(), cred2.getAccessTokenType()); assertEquals(cred.getRefreshToken(), cred2.getRefreshToken()); assertEquals(cred.getDefaultSubscription(), cred2.getDefaultSubscription()); assertEquals(cred.getEnvironment(), cred2.getEnvironment()); assertEquals(cred.getIdToken(), cred2.getIdToken()); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, tempDirectory.getAbsolutePath()); assertTrue(AzureAuthHelper.existsAzureSecretFile()); AzureAuthHelper.deleteAzureSecretFile(); assertFalse(AzureAuthHelper.existsAzureSecretFile()); assertFalse(AzureAuthHelper.deleteAzureSecretFile()); }
public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); }
AzureAuthHelper { public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); } }
AzureAuthHelper { public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); } private AzureAuthHelper(); }
AzureAuthHelper { public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testWriteAzureCredentialsBadParameter() throws Exception { final File tempFile = File.createTempFile("azure-auth-helper-test", ".json"); try { AzureAuthHelper.writeAzureCredentials(null, tempFile); fail("Should throw IAE here."); } catch (IllegalArgumentException ex) { } try { AzureAuthHelper.writeAzureCredentials(AzureCredential.fromAuthenticationResult(TestHelper.createAuthenticationResult()), null); fail("Should throw IAE here."); } catch (IllegalArgumentException ex) { } }
public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); }
AzureAuthHelper { public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); } }
AzureAuthHelper { public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); } private AzureAuthHelper(); }
AzureAuthHelper { public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static void writeAzureCredentials(AzureCredential cred, File file) throws IOException { if (cred == null) { throw new IllegalArgumentException("Parameter 'cred' cannot be null."); } if (file == null) { throw new IllegalArgumentException("Parameter 'file' cannot be null."); } FileUtils.writeStringToFile(file, JsonUtils.toJson(cred), "utf8"); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testIsInCloudShell() { TestHelper.injectEnvironmentVariable(Constants.CLOUD_SHELL_ENV_KEY, "azure"); assertTrue(AzureAuthHelper.isInCloudShell()); TestHelper.injectEnvironmentVariable(Constants.CLOUD_SHELL_ENV_KEY, null); assertFalse(AzureAuthHelper.isInCloudShell()); }
static boolean isInCloudShell() { return System.getenv(Constants.CLOUD_SHELL_ENV_KEY) != null; }
AzureAuthHelper { static boolean isInCloudShell() { return System.getenv(Constants.CLOUD_SHELL_ENV_KEY) != null; } }
AzureAuthHelper { static boolean isInCloudShell() { return System.getenv(Constants.CLOUD_SHELL_ENV_KEY) != null; } private AzureAuthHelper(); }
AzureAuthHelper { static boolean isInCloudShell() { return System.getenv(Constants.CLOUD_SHELL_ENV_KEY) != null; } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { static boolean isInCloudShell() { return System.getenv(Constants.CLOUD_SHELL_ENV_KEY) != null; } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testGetAzureTokenCredentials() throws Exception { File testConfigDir = new File(this.getClass().getResource("/azure-login/azure-secret.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); AzureTokenCredentials cred = AzureAuthHelper.getAzureTokenCredentials(null); assertNotNull(cred); assertEquals("00000000-0000-0000-0000-000000000001", cred.defaultSubscriptionId()); testConfigDir = new File(this.getClass().getResource("/azure-cli/default/azureProfile.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); cred = AzureAuthHelper.getAzureTokenCredentials(null).getAzureTokenCredentials(); assertNotNull(cred); assertTrue(cred instanceof AzureCliCredentials); final AzureCliCredentials cliCred = (AzureCliCredentials) cred; assertEquals("00000000-0000-0000-0000-000000000001", cliCred.defaultSubscriptionId()); assertEquals("00000000-0000-0000-0000-000000000002", cliCred.clientId()); assertEquals("00000000-0000-0000-0000-000000000003", cliCred.domain()); assertEquals(AzureEnvironment.AZURE_CHINA, cliCred.environment()); testConfigDir = new File(this.getClass().getResource("/azure-cli/sp/azureProfile.json").getFile()).getParentFile(); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, testConfigDir.getAbsolutePath()); cred = AzureAuthHelper.getAzureTokenCredentials(null).getAzureTokenCredentials(); assertNotNull(cred); assertTrue(cred instanceof AzureCliCredentials); final AzureCliCredentials azureCliCredential = (AzureCliCredentials) cred; assertEquals("00000000-0000-0000-0000-000000000001", cred.defaultSubscriptionId()); assertEquals("00000000-0000-0000-0000-000000000002", azureCliCredential.clientId()); assertEquals("00000000-0000-0000-0000-000000000003", cred.domain()); assertEquals(AzureEnvironment.AZURE_CHINA, cliCred.environment()); TestHelper.injectEnvironmentVariable(Constants.CLOUD_SHELL_ENV_KEY, "azure"); assertTrue(AzureAuthHelper.isInCloudShell()); TestHelper.injectEnvironmentVariable(Constants.AZURE_CONFIG_DIR, "non-exist-folder"); cred = AzureAuthHelper.getAzureTokenCredentials(null).getAzureTokenCredentials(); assertNotNull(cred); assertTrue(cred instanceof MSICredentials); TestHelper.injectEnvironmentVariable(Constants.CLOUD_SHELL_ENV_KEY, null); assertNull(AzureAuthHelper.getAzureTokenCredentials(null)); }
public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); }
AzureAuthHelper { public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); } }
AzureAuthHelper { public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test public void testGetAzureTokenCredentialsFromConfiguration() throws Exception { final AuthConfiguration auth = new AuthConfiguration(); auth.setClient("client_id"); auth.setTenant("tenant_id"); auth.setKey("key"); auth.setEnvironment("azure_germany"); final AzureTokenCredentials cred = AzureAuthHelper.getAzureTokenCredentials(auth).getAzureTokenCredentials(); assertNotNull(cred); assertTrue(cred instanceof ApplicationTokenCredentials); assertNull(cred.defaultSubscriptionId()); assertEquals(AzureEnvironment.AZURE_GERMANY, cred.environment()); assertEquals("tenant_id", cred.domain()); assertEquals("client_id", ((ApplicationTokenCredentials) cred).clientId()); }
public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); }
AzureAuthHelper { public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); } }
AzureAuthHelper { public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); } private AzureAuthHelper(); }
AzureAuthHelper { public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
AzureAuthHelper { public static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration) throws InvalidConfigurationException, IOException { if (configuration != null) { return new AzureTokenWrapper(AuthMethod.SERVICE_PRINCIPAL, AzureServicePrincipleAuthHelper.getAzureServicePrincipleCredentials(configuration)); } if (existsAzureSecretFile()) { try { return new AzureTokenWrapper(AuthMethod.AZURE_SECRET_FILE, getMavenAzureLoginCredentials(), getAzureSecretFile()); } catch (IOException ex) { } } if (isInCloudShell()) { return new AzureTokenWrapper(AuthMethod.CLOUD_SHELL, new MSICredentials()); } return getAzureCLICredential(AzureEnvironment.AZURE); } private AzureAuthHelper(); static AzureCredential oAuthLogin(AzureEnvironment env); static AzureCredential deviceLogin(AzureEnvironment env); static AzureCredential refreshToken(AzureEnvironment env, String refreshToken); static AzureEnvironment getAzureEnvironment(String environment); static String getAzureEnvironmentDisplayName(AzureEnvironment azureEnvironment); static boolean validateEnvironment(String environment); static File getAzureSecretFile(); static File getAzureConfigFolder(); static boolean existsAzureSecretFile(); static boolean deleteAzureSecretFile(); static void writeAzureCredentials(AzureCredential cred, File file); static AzureCredential readAzureCredentials(); static AzureCredential readAzureCredentials(File file); static AzureTokenCredentials getMavenAzureLoginCredentials(); static AzureTokenCredentials getMavenAzureLoginCredentials(AzureCredential credentials, AzureEnvironment env); static AzureTokenWrapper getAzureCLICredential(AzureEnvironment environment); static AzureTokenWrapper getServicePrincipalCredential(AuthConfiguration configuration); static AzureTokenWrapper getAzureMavenPluginCredential(AzureEnvironment environment); static AzureTokenWrapper getAzureSecretFileCredential(); static AzureTokenWrapper getAzureTokenCredentials(AuthConfiguration configuration); static AzureTokenWrapper getAzureCredentialByOrder(AuthConfiguration authConfiguration, AzureEnvironment azureEnvironment); }
@Test(expected = MojoFailureException.class) public void assureInputInBatchModeWhenRequired() throws Exception { final AddMojo mojo = getMojoFromPom(); final AddMojo mojoSpy = spy(mojo); final Set<String> set = new HashSet<>(); mojoSpy.assureInputInBatchMode("", StringUtils::isNotEmpty, set::add, true); }
protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } }
AddMojo extends AbstractFunctionMojo { protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } } }
AddMojo extends AbstractFunctionMojo { protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } } }
AddMojo extends AbstractFunctionMojo { protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } } String getFunctionPackageName(); String getFunctionName(); String getClassName(); String getFunctionTemplate(); }
AddMojo extends AbstractFunctionMojo { protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } } String getFunctionPackageName(); String getFunctionName(); String getClassName(); String getFunctionTemplate(); }
@Test public void testWithPath() { final Volume volume = new Volume(); volume.withPath("/home/shared"); assertEquals("/home/shared", volume.getPath()); }
public Volume withPath(String path) { this.path = path; return this; }
Volume { public Volume withPath(String path) { this.path = path; return this; } }
Volume { public Volume withPath(String path) { this.path = path; return this; } }
Volume { public Volume withPath(String path) { this.path = path; return this; } String getPath(); String getSize(); Boolean isPersist(); Volume withPath(String path); Volume withSize(String size); Volume withPersist(Boolean persist); }
Volume { public Volume withPath(String path) { this.path = path; return this; } String getPath(); String getSize(); Boolean isPersist(); Volume withPath(String path); Volume withSize(String size); Volume withPersist(Boolean persist); }
@Test public void testWithSize() { final Volume volume = new Volume(); volume.withSize("10G"); assertEquals("10G", volume.getSize()); }
public Volume withSize(String size) { this.size = size; return this; }
Volume { public Volume withSize(String size) { this.size = size; return this; } }
Volume { public Volume withSize(String size) { this.size = size; return this; } }
Volume { public Volume withSize(String size) { this.size = size; return this; } String getPath(); String getSize(); Boolean isPersist(); Volume withPath(String path); Volume withSize(String size); Volume withPersist(Boolean persist); }
Volume { public Volume withSize(String size) { this.size = size; return this; } String getPath(); String getSize(); Boolean isPersist(); Volume withPath(String path); Volume withSize(String size); Volume withPersist(Boolean persist); }
@Test public void testWithPersist() { final Volume volume = new Volume(); volume.withPersist(true); assertEquals(Boolean.TRUE, volume.isPersist()); }
public Volume withPersist(Boolean persist) { this.persist = persist; return this; }
Volume { public Volume withPersist(Boolean persist) { this.persist = persist; return this; } }
Volume { public Volume withPersist(Boolean persist) { this.persist = persist; return this; } }
Volume { public Volume withPersist(Boolean persist) { this.persist = persist; return this; } String getPath(); String getSize(); Boolean isPersist(); Volume withPath(String path); Volume withSize(String size); Volume withPersist(Boolean persist); }
Volume { public Volume withPersist(Boolean persist) { this.persist = persist; return this; } String getPath(); String getSize(); Boolean isPersist(); Volume withPath(String path); Volume withSize(String size); Volume withPersist(Boolean persist); }
@Test public void testSetCpu() { final DeploymentSettings deploy = new DeploymentSettings(); deploy.setCpu("1"); assertEquals("1", deploy.getCpu()); }
public void setCpu(String cpu) { this.cpu = cpu; }
DeploymentSettings extends BaseSettings { public void setCpu(String cpu) { this.cpu = cpu; } }
DeploymentSettings extends BaseSettings { public void setCpu(String cpu) { this.cpu = cpu; } }
DeploymentSettings extends BaseSettings { public void setCpu(String cpu) { this.cpu = cpu; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
DeploymentSettings extends BaseSettings { public void setCpu(String cpu) { this.cpu = cpu; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
@Test public void testSetMemoryInGB() { final DeploymentSettings deploy = new DeploymentSettings(); deploy.setMemoryInGB("2"); assertEquals("2", deploy.getMemoryInGB()); }
public void setMemoryInGB(String memoryInGB) { this.memoryInGB = memoryInGB; }
DeploymentSettings extends BaseSettings { public void setMemoryInGB(String memoryInGB) { this.memoryInGB = memoryInGB; } }
DeploymentSettings extends BaseSettings { public void setMemoryInGB(String memoryInGB) { this.memoryInGB = memoryInGB; } }
DeploymentSettings extends BaseSettings { public void setMemoryInGB(String memoryInGB) { this.memoryInGB = memoryInGB; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
DeploymentSettings extends BaseSettings { public void setMemoryInGB(String memoryInGB) { this.memoryInGB = memoryInGB; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
@Test public void testSetInstanceCount() { final DeploymentSettings deploy = new DeploymentSettings(); deploy.setInstanceCount("3"); assertEquals("3", deploy.getInstanceCount()); }
public void setInstanceCount(String instanceCount) { this.instanceCount = instanceCount; }
DeploymentSettings extends BaseSettings { public void setInstanceCount(String instanceCount) { this.instanceCount = instanceCount; } }
DeploymentSettings extends BaseSettings { public void setInstanceCount(String instanceCount) { this.instanceCount = instanceCount; } }
DeploymentSettings extends BaseSettings { public void setInstanceCount(String instanceCount) { this.instanceCount = instanceCount; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
DeploymentSettings extends BaseSettings { public void setInstanceCount(String instanceCount) { this.instanceCount = instanceCount; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
@Test public void testSetDeploymentName() { final DeploymentSettings deploy = new DeploymentSettings(); deploy.setDeploymentName("deploymentName1"); assertEquals("deploymentName1", deploy.getDeploymentName()); }
public void setDeploymentName(String deploymentName) { this.deploymentName = deploymentName; }
DeploymentSettings extends BaseSettings { public void setDeploymentName(String deploymentName) { this.deploymentName = deploymentName; } }
DeploymentSettings extends BaseSettings { public void setDeploymentName(String deploymentName) { this.deploymentName = deploymentName; } }
DeploymentSettings extends BaseSettings { public void setDeploymentName(String deploymentName) { this.deploymentName = deploymentName; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
DeploymentSettings extends BaseSettings { public void setDeploymentName(String deploymentName) { this.deploymentName = deploymentName; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
@Test public void testSetJvmOptions() { final DeploymentSettings deploy = new DeploymentSettings(); deploy.setJvmOptions("jvmOptions1"); assertEquals("jvmOptions1", deploy.getJvmOptions()); }
public void setJvmOptions(String jvmOptions) { this.jvmOptions = jvmOptions; }
DeploymentSettings extends BaseSettings { public void setJvmOptions(String jvmOptions) { this.jvmOptions = jvmOptions; } }
DeploymentSettings extends BaseSettings { public void setJvmOptions(String jvmOptions) { this.jvmOptions = jvmOptions; } }
DeploymentSettings extends BaseSettings { public void setJvmOptions(String jvmOptions) { this.jvmOptions = jvmOptions; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
DeploymentSettings extends BaseSettings { public void setJvmOptions(String jvmOptions) { this.jvmOptions = jvmOptions; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
@Test public void testSetRuntimeVersion() { final DeploymentSettings deploy = new DeploymentSettings(); deploy.setRuntimeVersion("8"); assertEquals("8", deploy.getRuntimeVersion()); }
public void setRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; }
DeploymentSettings extends BaseSettings { public void setRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; } }
DeploymentSettings extends BaseSettings { public void setRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; } }
DeploymentSettings extends BaseSettings { public void setRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
DeploymentSettings extends BaseSettings { public void setRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; } String getCpu(); String getMemoryInGB(); String getInstanceCount(); String getDeploymentName(); void setCpu(String cpu); void setMemoryInGB(String memoryInGB); void setInstanceCount(String instanceCount); void setJvmOptions(String jvmOptions); void setDeploymentName(String deploymentName); String getJvmOptions(); String getRuntimeVersion(); void setRuntimeVersion(String runtimeVersion); }
@Test public void testWithSubscriptionId() { final SpringConfiguration config = new SpringConfiguration(); config.withSubscriptionId("subscriptionId1"); assertEquals("subscriptionId1", config.getSubscriptionId()); }
public SpringConfiguration withSubscriptionId(String subscriptionId) { this.subscriptionId = subscriptionId; return this; }
SpringConfiguration { public SpringConfiguration withSubscriptionId(String subscriptionId) { this.subscriptionId = subscriptionId; return this; } }
SpringConfiguration { public SpringConfiguration withSubscriptionId(String subscriptionId) { this.subscriptionId = subscriptionId; return this; } }
SpringConfiguration { public SpringConfiguration withSubscriptionId(String subscriptionId) { this.subscriptionId = subscriptionId; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
SpringConfiguration { public SpringConfiguration withSubscriptionId(String subscriptionId) { this.subscriptionId = subscriptionId; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
@Test public void assureInputInBatchModeWhenNotRequired() throws Exception { final AddMojo mojo = getMojoFromPom(); final AddMojo mojoSpy = spy(mojo); final Set<String> set = new HashSet<>(); mojoSpy.assureInputInBatchMode("a0", StringUtils::isNotEmpty, set::add, true); assertTrue(set.contains("a0")); }
protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } }
AddMojo extends AbstractFunctionMojo { protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } } }
AddMojo extends AbstractFunctionMojo { protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } } }
AddMojo extends AbstractFunctionMojo { protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } } String getFunctionPackageName(); String getFunctionName(); String getClassName(); String getFunctionTemplate(); }
AddMojo extends AbstractFunctionMojo { protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator, final Consumer<String> setter, final boolean required) throws MojoFailureException { if (validator.apply(input)) { Log.info(FOUND_VALID_VALUE); setter.accept(input); return; } if (required) { throw new MojoFailureException(String.format("invalid input: %s", input)); } else { out.printf("The input is invalid. Use empty string.%n"); setter.accept(""); } } String getFunctionPackageName(); String getFunctionName(); String getClassName(); String getFunctionTemplate(); }
@Test public void testWithResourceGroup() { final SpringConfiguration config = new SpringConfiguration(); config.withResourceGroup("resourceGroup1"); assertEquals("resourceGroup1", config.getResourceGroup()); }
public SpringConfiguration withResourceGroup(String resourceGroup) { this.resourceGroup = resourceGroup; return this; }
SpringConfiguration { public SpringConfiguration withResourceGroup(String resourceGroup) { this.resourceGroup = resourceGroup; return this; } }
SpringConfiguration { public SpringConfiguration withResourceGroup(String resourceGroup) { this.resourceGroup = resourceGroup; return this; } }
SpringConfiguration { public SpringConfiguration withResourceGroup(String resourceGroup) { this.resourceGroup = resourceGroup; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
SpringConfiguration { public SpringConfiguration withResourceGroup(String resourceGroup) { this.resourceGroup = resourceGroup; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
@Test public void testWithClusterName() { final SpringConfiguration config = new SpringConfiguration(); config.withClusterName("clusterName1"); assertEquals("clusterName1", config.getClusterName()); }
public SpringConfiguration withClusterName(String clusterName) { this.clusterName = clusterName; return this; }
SpringConfiguration { public SpringConfiguration withClusterName(String clusterName) { this.clusterName = clusterName; return this; } }
SpringConfiguration { public SpringConfiguration withClusterName(String clusterName) { this.clusterName = clusterName; return this; } }
SpringConfiguration { public SpringConfiguration withClusterName(String clusterName) { this.clusterName = clusterName; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
SpringConfiguration { public SpringConfiguration withClusterName(String clusterName) { this.clusterName = clusterName; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
@Test public void testWithAppName() { final SpringConfiguration config = new SpringConfiguration(); config.withAppName("appName1"); assertEquals("appName1", config.getAppName()); }
public SpringConfiguration withAppName(String appName) { this.appName = appName; return this; }
SpringConfiguration { public SpringConfiguration withAppName(String appName) { this.appName = appName; return this; } }
SpringConfiguration { public SpringConfiguration withAppName(String appName) { this.appName = appName; return this; } }
SpringConfiguration { public SpringConfiguration withAppName(String appName) { this.appName = appName; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
SpringConfiguration { public SpringConfiguration withAppName(String appName) { this.appName = appName; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
@Test public void testWithRuntimeVersion() { final SpringConfiguration config = new SpringConfiguration(); config.withRuntimeVersion("runtimeVersion1"); assertEquals("runtimeVersion1", config.getRuntimeVersion()); }
public SpringConfiguration withRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; return this; }
SpringConfiguration { public SpringConfiguration withRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; return this; } }
SpringConfiguration { public SpringConfiguration withRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; return this; } }
SpringConfiguration { public SpringConfiguration withRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
SpringConfiguration { public SpringConfiguration withRuntimeVersion(String runtimeVersion) { this.runtimeVersion = runtimeVersion; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
@Test public void testWithDeployment() { final SpringConfiguration config = new SpringConfiguration(); final Deployment deploy = Mockito.mock(Deployment.class); config.withDeployment(deploy); assertEquals(deploy, config.getDeployment()); }
public SpringConfiguration withDeployment(Deployment deployment) { this.deployment = deployment; return this; }
SpringConfiguration { public SpringConfiguration withDeployment(Deployment deployment) { this.deployment = deployment; return this; } }
SpringConfiguration { public SpringConfiguration withDeployment(Deployment deployment) { this.deployment = deployment; return this; } }
SpringConfiguration { public SpringConfiguration withDeployment(Deployment deployment) { this.deployment = deployment; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
SpringConfiguration { public SpringConfiguration withDeployment(Deployment deployment) { this.deployment = deployment; return this; } Boolean isPublic(); String getSubscriptionId(); String getResourceGroup(); String getClusterName(); String getAppName(); String getRuntimeVersion(); String getActiveDeploymentName(); Deployment getDeployment(); SpringConfiguration withPublic(Boolean isPublic); SpringConfiguration withSubscriptionId(String subscriptionId); SpringConfiguration withResourceGroup(String resourceGroup); SpringConfiguration withClusterName(String clusterName); SpringConfiguration withAppName(String appName); SpringConfiguration withRuntimeVersion(String runtimeVersion); SpringConfiguration withActiveDeploymentName(String deploymentName); SpringConfiguration withDeployment(Deployment deployment); }
@Test public void testWithCpu() { final Deployment deploy = new Deployment(); deploy.withCpu(1); assertEquals(1, (int) deploy.getCpu()); }
public Deployment withCpu(Integer cpu) { this.cpu = cpu; return this; }
Deployment { public Deployment withCpu(Integer cpu) { this.cpu = cpu; return this; } }
Deployment { public Deployment withCpu(Integer cpu) { this.cpu = cpu; return this; } }
Deployment { public Deployment withCpu(Integer cpu) { this.cpu = cpu; return this; } Integer getCpu(); Integer getMemoryInGB(); Integer getInstanceCount(); String getDeploymentName(); Map<String, String> getEnvironment(); List<Resource> getResources(); Boolean isEnablePersistentStorage(); String getJvmOptions(); String getRuntimeVersion(); Deployment withCpu(Integer cpu); Deployment withMemoryInGB(Integer memoryInGB); Deployment withInstanceCount(Integer instanceCount); Deployment withJvmOptions(String jvmOptions); Deployment withEnvironment(Map<String, String> environment); Deployment withDeploymentName(String deploymentName); Deployment withResources(List<Resource> resources); Deployment withEnablePersistentStorage(Boolean enablePersistentStorage); Deployment withRuntimeVersion(String runtimeVersion); }
Deployment { public Deployment withCpu(Integer cpu) { this.cpu = cpu; return this; } Integer getCpu(); Integer getMemoryInGB(); Integer getInstanceCount(); String getDeploymentName(); Map<String, String> getEnvironment(); List<Resource> getResources(); Boolean isEnablePersistentStorage(); String getJvmOptions(); String getRuntimeVersion(); Deployment withCpu(Integer cpu); Deployment withMemoryInGB(Integer memoryInGB); Deployment withInstanceCount(Integer instanceCount); Deployment withJvmOptions(String jvmOptions); Deployment withEnvironment(Map<String, String> environment); Deployment withDeploymentName(String deploymentName); Deployment withResources(List<Resource> resources); Deployment withEnablePersistentStorage(Boolean enablePersistentStorage); Deployment withRuntimeVersion(String runtimeVersion); }
@Test public void testWithMemoryInGB() { final Deployment deploy = new Deployment(); deploy.withMemoryInGB(2); assertEquals(2, (int) deploy.getMemoryInGB()); }
public Deployment withMemoryInGB(Integer memoryInGB) { this.memoryInGB = memoryInGB; return this; }
Deployment { public Deployment withMemoryInGB(Integer memoryInGB) { this.memoryInGB = memoryInGB; return this; } }
Deployment { public Deployment withMemoryInGB(Integer memoryInGB) { this.memoryInGB = memoryInGB; return this; } }
Deployment { public Deployment withMemoryInGB(Integer memoryInGB) { this.memoryInGB = memoryInGB; return this; } Integer getCpu(); Integer getMemoryInGB(); Integer getInstanceCount(); String getDeploymentName(); Map<String, String> getEnvironment(); List<Resource> getResources(); Boolean isEnablePersistentStorage(); String getJvmOptions(); String getRuntimeVersion(); Deployment withCpu(Integer cpu); Deployment withMemoryInGB(Integer memoryInGB); Deployment withInstanceCount(Integer instanceCount); Deployment withJvmOptions(String jvmOptions); Deployment withEnvironment(Map<String, String> environment); Deployment withDeploymentName(String deploymentName); Deployment withResources(List<Resource> resources); Deployment withEnablePersistentStorage(Boolean enablePersistentStorage); Deployment withRuntimeVersion(String runtimeVersion); }
Deployment { public Deployment withMemoryInGB(Integer memoryInGB) { this.memoryInGB = memoryInGB; return this; } Integer getCpu(); Integer getMemoryInGB(); Integer getInstanceCount(); String getDeploymentName(); Map<String, String> getEnvironment(); List<Resource> getResources(); Boolean isEnablePersistentStorage(); String getJvmOptions(); String getRuntimeVersion(); Deployment withCpu(Integer cpu); Deployment withMemoryInGB(Integer memoryInGB); Deployment withInstanceCount(Integer instanceCount); Deployment withJvmOptions(String jvmOptions); Deployment withEnvironment(Map<String, String> environment); Deployment withDeploymentName(String deploymentName); Deployment withResources(List<Resource> resources); Deployment withEnablePersistentStorage(Boolean enablePersistentStorage); Deployment withRuntimeVersion(String runtimeVersion); }