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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations