Search in sources :

Example 1 with RegistryCredentials

use of com.microsoft.azure.management.containerregistry.RegistryCredentials in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModel method createImageSettingWithRegistry.

/**
 * Get Registry Credential.
 */
public PrivateRegistryImageSetting createImageSettingWithRegistry(@NotNull final Registry registry) throws Exception {
    if (!registry.adminUserEnabled()) {
        throw new Exception(ADMIN_USER_NOT_ENABLED);
    }
    final RegistryCredentials credentials = registry.getCredentials();
    if (credentials == null) {
        throw new Exception(CANNOT_GET_CREDENTIAL);
    }
    String username = credentials.username();
    final Map<AccessKeyType, String> passwords = credentials.accessKeys();
    if (Utils.isEmptyString(username) || passwords == null || !passwords.containsKey(AccessKeyType.PRIMARY)) {
        throw new Exception(CANNOT_GET_CREDENTIAL);
    }
    return new PrivateRegistryImageSetting(registry.loginServerUrl(), username, passwords.get(AccessKeyType.PRIMARY), IMAGE_TAG, null);
}
Also used : AccessKeyType(com.microsoft.azure.management.containerregistry.AccessKeyType) PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) RegistryCredentials(com.microsoft.azure.management.containerregistry.RegistryCredentials)

Example 2 with RegistryCredentials

use of com.microsoft.azure.management.containerregistry.RegistryCredentials in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModelTest method testCreateImageSettingWithRegistryWhenUserNameIsEmpty.

@Test(expected = Exception.class)
public void testCreateImageSettingWithRegistryWhenUserNameIsEmpty() throws Exception {
    when(registryMock1.adminUserEnabled()).thenReturn(true);
    RegistryCredentials credentials = mock(RegistryCredentials.class);
    when(registryMock1.getCredentials()).thenReturn(credentials);
    when(credentials.username()).thenReturn("");
    containerRegistryMvpModel.createImageSettingWithRegistry(registryMock1);
}
Also used : RegistryCredentials(com.microsoft.azure.management.containerregistry.RegistryCredentials) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with RegistryCredentials

use of com.microsoft.azure.management.containerregistry.RegistryCredentials in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModelTest method testCreateImageSettingWithRegistryWhenPasswordIsNull.

@Test(expected = Exception.class)
public void testCreateImageSettingWithRegistryWhenPasswordIsNull() throws Exception {
    when(registryMock1.adminUserEnabled()).thenReturn(true);
    RegistryCredentials credentials = mock(RegistryCredentials.class);
    when(registryMock1.getCredentials()).thenReturn(credentials);
    when(credentials.accessKeys()).thenReturn(null);
    containerRegistryMvpModel.createImageSettingWithRegistry(registryMock1);
}
Also used : RegistryCredentials(com.microsoft.azure.management.containerregistry.RegistryCredentials) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with RegistryCredentials

use of com.microsoft.azure.management.containerregistry.RegistryCredentials in project azure-tools-for-java by Microsoft.

the class ContainerRegistryPropertyViewPresenter method getProperty.

private ContainerRegistryProperty getProperty(Registry registry, String sid) {
    String userName = "";
    String password = "";
    String password2 = "";
    if (registry.adminUserEnabled()) {
        RegistryCredentials credentials = registry.getCredentials();
        userName = credentials.username();
        Map<AccessKeyType, String> passwords = credentials.accessKeys();
        password = passwords.get(AccessKeyType.PRIMARY) == null ? "" : passwords.get(AccessKeyType.PRIMARY);
        password2 = passwords.get(AccessKeyType.SECONDARY) == null ? "" : passwords.get(AccessKeyType.SECONDARY);
    }
    return new ContainerRegistryProperty(registry.id(), registry.name(), registry.type(), registry.resourceGroupName(), registry.regionName(), sid, registry.loginServerUrl(), registry.adminUserEnabled(), userName, password, password2);
}
Also used : AccessKeyType(com.microsoft.azure.management.containerregistry.AccessKeyType) ContainerRegistryProperty(com.microsoft.azuretools.core.mvp.ui.containerregistry.ContainerRegistryProperty) RegistryCredentials(com.microsoft.azure.management.containerregistry.RegistryCredentials)

Example 5 with RegistryCredentials

use of com.microsoft.azure.management.containerregistry.RegistryCredentials in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModelTest method testCreateImageSettingWithRegistryWhenPasswordIsEmpty.

@Test(expected = Exception.class)
public void testCreateImageSettingWithRegistryWhenPasswordIsEmpty() throws Exception {
    when(registryMock1.adminUserEnabled()).thenReturn(true);
    RegistryCredentials credentials = mock(RegistryCredentials.class);
    when(registryMock1.getCredentials()).thenReturn(credentials);
    Map<AccessKeyType, String> passwords = new HashMap<>();
    when(credentials.accessKeys()).thenReturn(passwords);
    containerRegistryMvpModel.createImageSettingWithRegistry(registryMock1);
}
Also used : AccessKeyType(com.microsoft.azure.management.containerregistry.AccessKeyType) HashMap(java.util.HashMap) Mockito.anyString(org.mockito.Mockito.anyString) RegistryCredentials(com.microsoft.azure.management.containerregistry.RegistryCredentials) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RegistryCredentials (com.microsoft.azure.management.containerregistry.RegistryCredentials)6 AccessKeyType (com.microsoft.azure.management.containerregistry.AccessKeyType)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)2 HashMap (java.util.HashMap)2 Mockito.anyString (org.mockito.Mockito.anyString)2 ContainerRegistryProperty (com.microsoft.azuretools.core.mvp.ui.containerregistry.ContainerRegistryProperty)1