use of com.microsoft.azure.management.containerregistry.AccessKeyType 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.AccessKeyType 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.AccessKeyType 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);
}
use of com.microsoft.azure.management.containerregistry.AccessKeyType in project azure-tools-for-java by Microsoft.
the class ContainerRegistryMvpModelTest method testCreateImageSettingWithRegistry.
@Test
public void testCreateImageSettingWithRegistry() throws Exception {
when(registryMock1.adminUserEnabled()).thenReturn(true);
RegistryCredentials credentials = mock(RegistryCredentials.class);
when(registryMock1.getCredentials()).thenReturn(credentials);
when(registryMock1.loginServerUrl()).thenReturn("url");
when(credentials.username()).thenReturn("Alice");
Map<AccessKeyType, String> passwords = new HashMap<>();
passwords.put(AccessKeyType.PRIMARY, "primaryKey");
when(credentials.accessKeys()).thenReturn(passwords);
PrivateRegistryImageSetting setting = containerRegistryMvpModel.createImageSettingWithRegistry(registryMock1);
assertEquals(setting.getUsername(), "Alice");
assertEquals(setting.getPassword(), "primaryKey");
assertEquals(setting.getServerUrl(), "url");
assertEquals(setting.getImageNameWithTag(), "image:tag");
}
Aggregations