From b84472fa5b6180e21db70c9e079eb6332c13de04 Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Wed, 31 Jul 2024 10:41:51 -0400 Subject: [PATCH 1/3] Add communication service resources --- build.gradle | 1 + .../communication/communication-service.gyro | 54 ++++ .../java/gyro/azure/AbstractAzureCommand.java | 2 +- .../java/gyro/azure/AzureCredentials.java | 53 +++- src/main/java/gyro/azure/AzureFinder.java | 16 +- src/main/java/gyro/azure/AzureResource.java | 15 +- .../ActiveDirectoryGroupFinder.java | 2 +- .../ActiveDirectoryUserFinder.java | 2 +- .../accessmanagement/ApplicationFinder.java | 2 +- .../ServicePrincipalFinder.java | 2 +- .../java/gyro/azure/cdn/CdnProfileFinder.java | 2 +- .../CommunicationServiceFinder.java | 96 +++++++ ...nicationServiceManagedServiceIdentity.java | 127 +++++++++ .../CommunicationServiceResource.java | 251 ++++++++++++++++++ .../azure/communication/DomainFinder.java | 90 +++++++ .../azure/communication/DomainResource.java | 211 +++++++++++++++ .../communication/EmailServiceFinder.java | 95 +++++++ .../communication/EmailServiceResource.java | 178 +++++++++++++ .../azure/communication/package-info.java | 20 ++ .../azure/compute/AvailabilitySetFinder.java | 2 +- .../java/gyro/azure/compute/DiskFinder.java | 2 +- .../gyro/azure/compute/SnapshotFinder.java | 2 +- .../gyro/azure/compute/VMScaleSetFinder.java | 2 +- .../compute/VMScaleSetScalingFinder.java | 2 +- .../azure/compute/VirtualMachineFinder.java | 2 +- .../compute/VirtualMachineImageFinder.java | 2 +- .../KubernetesClusterFinder.java | 2 +- .../azure/cosmosdb/CosmosDBAccountFinder.java | 2 +- .../java/gyro/azure/dns/ARecordSetFinder.java | 2 +- .../gyro/azure/dns/AaaaRecordSetFinder.java | 2 +- .../gyro/azure/dns/CaaRecordSetFinder.java | 2 +- .../gyro/azure/dns/CnameRecordSetFinder.java | 2 +- .../java/gyro/azure/dns/DnsZoneFinder.java | 12 +- .../gyro/azure/dns/MxRecordSetFinder.java | 2 +- .../gyro/azure/dns/PtrRecordSetFinder.java | 2 +- .../gyro/azure/dns/SrvRecordSetFinder.java | 2 +- .../gyro/azure/dns/TxtRecordSetFinder.java | 2 +- .../gyro/azure/identity/IdentityFinder.java | 2 +- .../keyvault/KeyVaultCertificateFinder.java | 2 +- .../gyro/azure/keyvault/KeyVaultFinder.java | 2 +- .../azure/keyvault/KeyVaultKeyFinder.java | 2 +- .../azure/keyvault/KeyVaultSecretFinder.java | 2 +- .../network/ApplicationGatewayFinder.java | 2 +- .../ApplicationSecurityGroupFinder.java | 2 +- .../azure/network/LoadBalancerFinder.java | 2 +- .../gyro/azure/network/NetworkFinder.java | 2 +- .../azure/network/NetworkInterfaceFinder.java | 2 +- .../network/NetworkSecurityGroupFinder.java | 2 +- .../azure/network/PublicIpAddressFinder.java | 2 +- .../gyro/azure/network/RouteTableFinder.java | 2 +- .../gyro/azure/registries/RegistryFinder.java | 2 +- .../azure/resources/ResourceGroupFinder.java | 2 +- .../gyro/azure/sql/SqlDatabaseFinder.java | 2 +- .../gyro/azure/sql/SqlElasticPoolFinder.java | 2 +- .../azure/sql/SqlFailoverGroupFinder.java | 2 +- .../gyro/azure/sql/SqlFirewallRuleFinder.java | 2 +- .../java/gyro/azure/sql/SqlServerFinder.java | 2 +- .../sql/SqlVirtualNetworkRuleFinder.java | 2 +- .../azure/storage/StorageAccountFinder.java | 2 +- 59 files changed, 1237 insertions(+), 72 deletions(-) create mode 100644 examples/communication/communication-service.gyro create mode 100644 src/main/java/gyro/azure/communication/CommunicationServiceFinder.java create mode 100644 src/main/java/gyro/azure/communication/CommunicationServiceManagedServiceIdentity.java create mode 100644 src/main/java/gyro/azure/communication/CommunicationServiceResource.java create mode 100644 src/main/java/gyro/azure/communication/DomainFinder.java create mode 100644 src/main/java/gyro/azure/communication/DomainResource.java create mode 100644 src/main/java/gyro/azure/communication/EmailServiceFinder.java create mode 100644 src/main/java/gyro/azure/communication/EmailServiceResource.java create mode 100644 src/main/java/gyro/azure/communication/package-info.java diff --git a/build.gradle b/build.gradle index bd939965..3b826c59 100644 --- a/build.gradle +++ b/build.gradle @@ -70,6 +70,7 @@ dependencies { implementation enforcedPlatform('com.azure:azure-sdk-bom:1.2.25') implementation 'com.azure.resourcemanager:azure-resourcemanager:2.40.0' + implementation 'com.azure.resourcemanager:azure-resourcemanager-communication:2.1.0' implementation 'com.azure:azure-security-keyvault-certificates' implementation 'com.azure:azure-security-keyvault-keys' implementation 'com.azure:azure-security-keyvault-secrets' diff --git a/examples/communication/communication-service.gyro b/examples/communication/communication-service.gyro new file mode 100644 index 00000000..fe2c5e4e --- /dev/null +++ b/examples/communication/communication-service.gyro @@ -0,0 +1,54 @@ +azure::resource-group resource-group-example + name: "resource-group-example-test" + + tags: { + Name: "resource-group-example-test" + } +end + +azure::identity identity-example + name: "identity-example-test" + resource-group: $(azure::resource-group resource-group-example) + + tags: { + Name: "identity-example-test" + } +end + +azure::email-service email-service-example + resource-group: $(azure::resource-group resource-group-example) + name: "example-email-test" + data-location: "United States" + + tags: { + Name: "example-email-test" + } +end + +azure::domain domain-example + resource-group: $(azure::resource-group resource-group-example) + email-service: $(azure::email-service email-service-example) + domain-management: "CustomerManaged" + name: "cloud.brightspot.dev" + + tags: { + "example": "example" + } +end + +azure::communication-service service-example + resource-group: $(azure::resource-group resource-group-example) + name: "service-example-test" + data-location: "United States" + domains: [ + $(azure::domain domain-example) + ] + + identity + user-assigned-identity: [$(azure::identity identity-example)] + end + + tags: { + Name: "service-example-test" + } +end diff --git a/src/main/java/gyro/azure/AbstractAzureCommand.java b/src/main/java/gyro/azure/AbstractAzureCommand.java index 7c2a365a..9504733b 100644 --- a/src/main/java/gyro/azure/AbstractAzureCommand.java +++ b/src/main/java/gyro/azure/AbstractAzureCommand.java @@ -97,7 +97,7 @@ public AzureResourceManager getResourceManagerClient() { getCredential())); } - return AzureResource.createClient((AzureCredentials) credentials); + return AzureResource.createClient(AzureResourceManager.class, (AzureCredentials) credentials); } public TokenCredential getTokenCredential() { diff --git a/src/main/java/gyro/azure/AzureCredentials.java b/src/main/java/gyro/azure/AzureCredentials.java index eba2bec2..b8195b58 100644 --- a/src/main/java/gyro/azure/AzureCredentials.java +++ b/src/main/java/gyro/azure/AzureCredentials.java @@ -22,9 +22,11 @@ import com.azure.core.credential.TokenCredential; import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder; +import com.azure.core.management.AzureEnvironment; import com.azure.core.management.profile.AzureProfile; import com.azure.identity.ClientSecretCredentialBuilder; import com.azure.resourcemanager.AzureResourceManager; +import com.azure.resourcemanager.communication.CommunicationManager; import com.psddev.dari.util.ObjectUtils; import com.psddev.dari.util.StringUtils; import gyro.core.GyroException; @@ -60,7 +62,7 @@ public void setLogLevel(String logLevel) { this.logLevel = logLevel; } - public AzureResourceManager createClient() { + public T createClient(Class clientClass) { Properties properties; try (InputStream input = openInput(getCredentialFilePath())) { @@ -80,21 +82,48 @@ public AzureResourceManager createClient() { String subscription = ObjectUtils.to(String.class, properties.get("subscription")); - AzureProfile azureProfile = new AzureProfile(tenant, subscription, com.azure.core.management.AzureEnvironment.AZURE); + AzureProfile azureProfile = new AzureProfile(tenant, subscription, AzureEnvironment.AZURE); - try { - AzureResourceManager.Authenticated authenticated = AzureResourceManager - .configure() - .withHttpClient(new OkHttpAsyncHttpClientBuilder().build()) - .authenticate(credential, azureProfile); + if (clientClass.getSimpleName().equals("CommunicationManager")) { + try { + CommunicationManager client = CommunicationManager + .configure() + .withHttpClient(new OkHttpAsyncHttpClientBuilder().build()) + .authenticate(credential, azureProfile); + if (clientClass.isInstance(client)) { + return clientClass.cast(client); + } - return StringUtils.isBlank(subscription) - ? authenticated.withDefaultSubscription() - : authenticated.withSubscription(subscription); + throw new GyroException( + String.format("Unable to create %s client", clientClass.getSimpleName())); - } catch (Exception error) { - throw new GyroException(error.getMessage(), error); + } catch (Exception error) { + throw new GyroException(error.getMessage(), error); + } + + } else { + try { + AzureResourceManager.Authenticated authenticated = AzureResourceManager + .configure() + .withHttpClient(new OkHttpAsyncHttpClientBuilder().build()) + .authenticate(credential, azureProfile); + + + AzureResourceManager client = StringUtils.isBlank(subscription) + ? authenticated.withDefaultSubscription() + : authenticated.withSubscription(subscription); + + if (clientClass.isInstance(client)) { + return clientClass.cast(client); + } + + throw new GyroException( + String.format("Unable to create %s client", clientClass.getSimpleName())); + + } catch (Exception error) { + throw new GyroException(error.getMessage(), error); + } } } diff --git a/src/main/java/gyro/azure/AzureFinder.java b/src/main/java/gyro/azure/AzureFinder.java index 17a43b23..9f5be2a9 100644 --- a/src/main/java/gyro/azure/AzureFinder.java +++ b/src/main/java/gyro/azure/AzureFinder.java @@ -22,13 +22,13 @@ import java.util.stream.Collectors; import com.azure.core.credential.TokenCredential; -import com.azure.resourcemanager.AzureResourceManager; +import com.psddev.dari.util.TypeDefinition; import gyro.core.finder.Finder; -public abstract class AzureFinder extends Finder { - protected abstract List findAllAzure(AzureResourceManager client); +public abstract class AzureFinder extends Finder { + protected abstract List findAllAzure(C client); - protected abstract List findAzure(AzureResourceManager client, Map filters); + protected abstract List findAzure(C client, Map filters); @Override public List find(Map filters) { @@ -44,8 +44,12 @@ public List findAll() { .collect(Collectors.toList()); } - private AzureResourceManager newClient() { - return AzureResource.createClient(credentials(AzureCredentials.class)); + private C newClient() { + @SuppressWarnings("unchecked") + Class clientClass = (Class) TypeDefinition.getInstance(getClass()) + .getInferredGenericTypeArgumentClass(AzureFinder.class, 0); + + return AzureResource.createClient(clientClass, credentials(AzureCredentials.class)); } protected TokenCredential getTokenCredential() { diff --git a/src/main/java/gyro/azure/AzureResource.java b/src/main/java/gyro/azure/AzureResource.java index e7f105af..d8d64fcf 100644 --- a/src/main/java/gyro/azure/AzureResource.java +++ b/src/main/java/gyro/azure/AzureResource.java @@ -18,6 +18,7 @@ import com.azure.core.credential.TokenCredential; import com.azure.resourcemanager.AzureResourceManager; +import com.azure.resourcemanager.communication.CommunicationManager; import gyro.core.resource.Resource; public abstract class AzureResource extends Resource { @@ -26,12 +27,20 @@ protected String getRegion() { return credentials(AzureCredentials.class).getRegion(); } - public static AzureResourceManager createClient(AzureCredentials credentials) { - return credentials.createClient(); + public static T createClient(Class clientClass, AzureCredentials credentials) { + return credentials.createClient(clientClass); + } + + protected T createClient(Class clientClass) { + return AzureResource.createClient(clientClass, credentials(AzureCredentials.class)); } protected AzureResourceManager createClient() { - return AzureResource.createClient(credentials(AzureCredentials.class)); + return AzureResource.createClient(AzureResourceManager.class, credentials(AzureCredentials.class)); + } + + protected CommunicationManager createCommunicationClient() { + return AzureResource.createClient(CommunicationManager.class, credentials(AzureCredentials.class)); } public static TokenCredential getTokenCredential(AzureCredentials credentials) { diff --git a/src/main/java/gyro/azure/accessmanagement/ActiveDirectoryGroupFinder.java b/src/main/java/gyro/azure/accessmanagement/ActiveDirectoryGroupFinder.java index d6755a45..6db2e95a 100644 --- a/src/main/java/gyro/azure/accessmanagement/ActiveDirectoryGroupFinder.java +++ b/src/main/java/gyro/azure/accessmanagement/ActiveDirectoryGroupFinder.java @@ -39,7 +39,7 @@ */ @Type("active-directory-group") public class ActiveDirectoryGroupFinder - extends AzureFinder { + extends AzureFinder { private String name; private String id; diff --git a/src/main/java/gyro/azure/accessmanagement/ActiveDirectoryUserFinder.java b/src/main/java/gyro/azure/accessmanagement/ActiveDirectoryUserFinder.java index b1f05760..4b46914c 100644 --- a/src/main/java/gyro/azure/accessmanagement/ActiveDirectoryUserFinder.java +++ b/src/main/java/gyro/azure/accessmanagement/ActiveDirectoryUserFinder.java @@ -39,7 +39,7 @@ */ @Type("active-directory-user") public class ActiveDirectoryUserFinder - extends AzureFinder { + extends AzureFinder { private String id; private String name; diff --git a/src/main/java/gyro/azure/accessmanagement/ApplicationFinder.java b/src/main/java/gyro/azure/accessmanagement/ApplicationFinder.java index 00da2c25..2acdd19f 100644 --- a/src/main/java/gyro/azure/accessmanagement/ApplicationFinder.java +++ b/src/main/java/gyro/azure/accessmanagement/ApplicationFinder.java @@ -37,7 +37,7 @@ * application: $(external-query azure::application {}) */ @Type("application") -public class ApplicationFinder extends AzureFinder { +public class ApplicationFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/accessmanagement/ServicePrincipalFinder.java b/src/main/java/gyro/azure/accessmanagement/ServicePrincipalFinder.java index aecdcf0e..3d8f63cd 100644 --- a/src/main/java/gyro/azure/accessmanagement/ServicePrincipalFinder.java +++ b/src/main/java/gyro/azure/accessmanagement/ServicePrincipalFinder.java @@ -37,7 +37,7 @@ * service-principal: $(external-query azure::service-principal {}) */ @Type("service-principal") -public class ServicePrincipalFinder extends AzureFinder { +public class ServicePrincipalFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/cdn/CdnProfileFinder.java b/src/main/java/gyro/azure/cdn/CdnProfileFinder.java index 0b045561..5edeebd1 100644 --- a/src/main/java/gyro/azure/cdn/CdnProfileFinder.java +++ b/src/main/java/gyro/azure/cdn/CdnProfileFinder.java @@ -37,7 +37,7 @@ * cdn-profile: $(external-query azure::cdn-profile {}) */ @Type("cdn-profile") -public class CdnProfileFinder extends AzureFinder { +public class CdnProfileFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/communication/CommunicationServiceFinder.java b/src/main/java/gyro/azure/communication/CommunicationServiceFinder.java new file mode 100644 index 00000000..822dc6d2 --- /dev/null +++ b/src/main/java/gyro/azure/communication/CommunicationServiceFinder.java @@ -0,0 +1,96 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import com.azure.resourcemanager.communication.CommunicationManager; +import gyro.azure.AzureFinder; +import gyro.core.Type; + +@Type("communication-service") +public class CommunicationServiceFinder extends + AzureFinder { + + private String resourceGroup; + private String name; + private String id; + + /** + * The resource group of the service + */ + public String getResourceGroup() { + return resourceGroup; + } + + public void setResourceGroup(String resourceGroup) { + this.resourceGroup = resourceGroup; + } + + /** + * The communication service + */ + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * The ID of the service + */ + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + protected List findAllAzure( + CommunicationManager client) { + return client.communicationServices().list().stream().collect(Collectors.toList()); + } + + @Override + protected List findAzure( + CommunicationManager client, Map filters) { + + + if (filters.containsKey("id")) { + return Collections.singletonList(client.communicationServices().getById(filters.get("id"))); + } + + if (filters.containsKey("resource-group")) { + if (filters.containsKey("name")) { + return Collections.singletonList(client.communicationServices() + .getByResourceGroup(filters.get("resource-group"), filters.get("name"))); + } + + return client.communicationServices().listByResourceGroup(filters.get("resource-group")).stream() + .collect(Collectors.toList()); + } + + return Collections.emptyList(); + } +} diff --git a/src/main/java/gyro/azure/communication/CommunicationServiceManagedServiceIdentity.java b/src/main/java/gyro/azure/communication/CommunicationServiceManagedServiceIdentity.java new file mode 100644 index 00000000..1d721541 --- /dev/null +++ b/src/main/java/gyro/azure/communication/CommunicationServiceManagedServiceIdentity.java @@ -0,0 +1,127 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +import com.azure.resourcemanager.communication.models.ManagedServiceIdentity; +import com.azure.resourcemanager.communication.models.ManagedServiceIdentityType; +import com.azure.resourcemanager.communication.models.UserAssignedIdentity; +import gyro.azure.Copyable; +import gyro.azure.identity.IdentityResource; +import gyro.core.resource.Diffable; +import gyro.core.resource.Output; +import gyro.core.resource.Updatable; +import gyro.core.validation.CollectionMax; +import gyro.core.validation.Required; + +public class CommunicationServiceManagedServiceIdentity extends Diffable implements Copyable { + + private List userAssignedIdentity; + private String tenantId; + private String principalId; + private String type; + + /** + * The identity to be associated with the application gateway. + */ + @Required + public List getUserAssignedIdentity() { + if (userAssignedIdentity == null) { + userAssignedIdentity = new ArrayList<>(); + } + + return userAssignedIdentity; + } + + public void setUserAssignedIdentity(List userAssignedIdentity) { + this.userAssignedIdentity = userAssignedIdentity; + } + + /** + * The tenant id of the service identity. + */ + @Output + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + /** + * The principal id of the service identity. + */ + @Output + public String getPrincipalId() { + return principalId; + } + + public void setPrincipalId(String principalId) { + this.principalId = principalId; + } + + /** + * The type of the service identity. + */ + @Output + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public void copyFrom(ManagedServiceIdentity managedServiceIdentity) { + UUID tenantUuid = managedServiceIdentity.tenantId(); + setTenantId(tenantUuid == null ? null : tenantUuid.toString()); + + UUID principalUuid = managedServiceIdentity.principalId(); + setPrincipalId(principalUuid == null ? null : principalUuid.toString()); + + setUserAssignedIdentity( + managedServiceIdentity.userAssignedIdentities() != null ? managedServiceIdentity.userAssignedIdentities() + .keySet() + .stream() + .map(o -> findById(IdentityResource.class, o)) + .collect(Collectors.toList()) : null); + + setType(managedServiceIdentity.type().toString()); + } + + @Override + public String primaryKey() { + return ""; + } + + ManagedServiceIdentity toManagedServiceIdentity() { + UserAssignedIdentity userAssignedIdentity = new UserAssignedIdentity(); + Map map = new HashMap<>(); + + getUserAssignedIdentity().forEach(o -> map.put(o.getId(), userAssignedIdentity)); + return new ManagedServiceIdentity().withType(ManagedServiceIdentityType.USER_ASSIGNED) + .withUserAssignedIdentities(map); + } +} diff --git a/src/main/java/gyro/azure/communication/CommunicationServiceResource.java b/src/main/java/gyro/azure/communication/CommunicationServiceResource.java new file mode 100644 index 00000000..2431fa70 --- /dev/null +++ b/src/main/java/gyro/azure/communication/CommunicationServiceResource.java @@ -0,0 +1,251 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import com.azure.resourcemanager.communication.CommunicationManager; +import com.azure.resourcemanager.communication.fluent.models.CommunicationServiceResourceInner; +import gyro.azure.AzureResource; +import gyro.azure.Copyable; +import gyro.azure.resources.ResourceGroupResource; +import gyro.core.GyroUI; +import gyro.core.Type; +import gyro.core.resource.Id; +import gyro.core.resource.Output; +import gyro.core.resource.Resource; +import gyro.core.resource.Updatable; +import gyro.core.scope.State; +import gyro.core.validation.Required; + + +@Type("communication-service") +public class CommunicationServiceResource extends AzureResource + implements Copyable { + + private ResourceGroupResource resourceGroup; + private String name; + private CommunicationServiceManagedServiceIdentity identity; + private String dataLocation; + private List domains; + private Map tags; + + // Read-only + private String id; + private String hostName; + + /** + * The resource group in which to build the service + */ + @Required + public ResourceGroupResource getResourceGroup() { + return resourceGroup; + } + + public void setResourceGroup(ResourceGroupResource resourceGroup) { + this.resourceGroup = resourceGroup; + } + + /** + * The name of the service + */ + @Required + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * The managed service identity for the communication service + */ + public CommunicationServiceManagedServiceIdentity getIdentity() { + return identity; + } + + public void setIdentity(CommunicationServiceManagedServiceIdentity identity) { + this.identity = identity; + } + + /** + * The tags for the service + */ + @Updatable + public Map getTags() { + if (tags == null) { + tags = new HashMap<>(); + } + + return tags; + } + + public void setTags(Map tags) { + this.tags = tags; + } + + /** + * The location where the service stores its data at rest + */ + @Required + public String getDataLocation() { + return dataLocation; + } + + public void setDataLocation(String dataLocation) { + this.dataLocation = dataLocation; + } + + /** + * List of email Domain resources. + */ + @Updatable + public List getDomains() { + if (domains == null) { + domains = new ArrayList<>(); + } + + return domains; + } + + public void setDomains(List domains) { + this.domains = domains; + } + + /** + * The FQDN of the service instance. + */ + @Output + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + /** + * The Id of the service + */ + @Output + @Id + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public void copyFrom(com.azure.resourcemanager.communication.models.CommunicationServiceResource model) { + setResourceGroup(findById(ResourceGroupResource.class, model.resourceGroupName())); + setName(model.name()); + setDataLocation(model.dataLocation()); + setHostName(model.hostname()); + setId(model.id()); + + getDomains().clear(); + if (model.linkedDomains() != null) { + getDomains().addAll(model.linkedDomains().stream().map(r -> findById(DomainResource.class, r)).collect( + Collectors.toList())); + } + + getTags().clear(); + if (model.tags() != null) { + getTags().putAll(model.tags()); + } + + setIdentity(null); + if (model.identity() != null) { + CommunicationServiceManagedServiceIdentity serviceIdentity = + new CommunicationServiceManagedServiceIdentity(); + serviceIdentity.copyFrom(model.identity()); + setIdentity(serviceIdentity); + } + } + + @Override + public boolean refresh() { + CommunicationManager client = createCommunicationClient(); + + com.azure.resourcemanager.communication.models.CommunicationServiceResource service = + client.communicationServices().getById(getId()); + + if (service == null) { + return false; + } + + copyFrom(service); + + return true; + } + + @Override + public void create(GyroUI ui, State state) throws Exception { + CommunicationManager client = createCommunicationClient(); + + CommunicationServiceResourceInner service = new CommunicationServiceResourceInner(); + + if (getIdentity() != null) { + service.withIdentity(getIdentity().toManagedServiceIdentity()); + } + + if (!getTags().isEmpty()) { + service.withTags(getTags()); + } + + if (!getDomains().isEmpty()) { + service.withLinkedDomains(getDomains().stream().map(DomainResource::getId).collect(Collectors.toList())); + } + + if (getDataLocation() != null) { + service.withDataLocation(getDataLocation()); + } + + service.withLocation("global"); + client.serviceClient().getCommunicationServices() + .createOrUpdate(getResourceGroup().getName(), getName(), service); + } + + @Override + public void update(GyroUI ui, State state, Resource current, Set changedFieldNames) throws Exception { + CommunicationManager client = createCommunicationClient(); + + CommunicationServiceResourceInner service = client.serviceClient().getCommunicationServices() + .getByResourceGroup(getResourceGroup().getName(), getName()); + + service.withTags(getTags()); + service.withLinkedDomains(getDomains().stream().map(DomainResource::getId).collect(Collectors.toList())); + + client.serviceClient().getCommunicationServices() + .createOrUpdate(getResourceGroup().getName(), getName(), service); + } + + @Override + public void delete(GyroUI ui, State state) throws Exception { + CommunicationManager client = createCommunicationClient(); + + client.communicationServices().deleteByResourceGroup(getResourceGroup().getName(), getName()); + } +} diff --git a/src/main/java/gyro/azure/communication/DomainFinder.java b/src/main/java/gyro/azure/communication/DomainFinder.java new file mode 100644 index 00000000..ef60c3a3 --- /dev/null +++ b/src/main/java/gyro/azure/communication/DomainFinder.java @@ -0,0 +1,90 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import com.azure.resourcemanager.communication.CommunicationManager; +import gyro.azure.AzureFinder; +import gyro.core.GyroException; +import gyro.core.Type; + +@Type("domain") +public class DomainFinder extends + AzureFinder { + private String resourceGroup; + private String emailService; + private String id; + + /** + * The resource group of the service + */ + public String getResourceGroup() { + return resourceGroup; + } + + public void setResourceGroup(String resourceGroup) { + this.resourceGroup = resourceGroup; + } + + /** + * The email service + */ + public String getEmailService() { + return emailService; + } + + public void setEmailService(String emailService) { + this.emailService = emailService; + } + + /** + * The ID of the domain + */ + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + protected List findAllAzure( + CommunicationManager client) { + throw new GyroException("Cannot list All domains in subscription."); + } + + @Override + protected List findAzure(CommunicationManager client, + Map filters) { + if (filters.containsKey("id")) { + return Collections.singletonList(client.domains().getById(filters.get("id"))); + } + + if (filters.containsKey("resource-group") && filters.containsKey("email-service")) { + return client.domains() + .listByEmailServiceResource(filters.get("resource-group"), filters.get("email-service")).stream() + .collect(Collectors.toList()); + } + + throw new GyroException("Both `resource-group` and `email-service` are required"); + } +} diff --git a/src/main/java/gyro/azure/communication/DomainResource.java b/src/main/java/gyro/azure/communication/DomainResource.java new file mode 100644 index 00000000..9e0ffcef --- /dev/null +++ b/src/main/java/gyro/azure/communication/DomainResource.java @@ -0,0 +1,211 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import com.azure.resourcemanager.communication.CommunicationManager; +import com.azure.resourcemanager.communication.fluent.models.DomainResourceInner; +import com.azure.resourcemanager.communication.models.DomainManagement; +import com.azure.resourcemanager.communication.models.DomainPropertiesVerificationRecords; +import gyro.azure.AzureResource; +import gyro.azure.Copyable; +import gyro.azure.resources.ResourceGroupResource; +import gyro.core.GyroUI; +import gyro.core.Type; +import gyro.core.resource.Id; +import gyro.core.resource.Output; +import gyro.core.resource.Resource; +import gyro.core.resource.Updatable; +import gyro.core.scope.State; +import gyro.core.validation.Required; +import gyro.core.validation.ValidStrings; + +@Type("domain") +public class DomainResource extends AzureResource + implements Copyable { + + private ResourceGroupResource resourceGroup; + private EmailServiceResource emailService; + private String domainManagement; + private String name; + private Map tags; + + // Read-only + private String dataLocation; + private String id; + + /** + * The resource group in which to build the service + */ + @Required + public ResourceGroupResource getResourceGroup() { + return resourceGroup; + } + + public void setResourceGroup(ResourceGroupResource resourceGroup) { + this.resourceGroup = resourceGroup; + } + + /** + * The email service where the domain is + */ + @Required + public EmailServiceResource getEmailService() { + return emailService; + } + + public void setEmailService(EmailServiceResource emailService) { + this.emailService = emailService; + } + + /** + * The domain name + */ + @Required + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * The domain management type. Defaults to ``CUSTOMER_MANAGED``. + */ + @ValidStrings({"AzureManaged", "CustomerManaged", "CustomerManagedInExchangeOnline"}) + public String getDomainManagement() { + if (domainManagement == null) { + domainManagement = DomainManagement.CUSTOMER_MANAGED.toString(); + } + + return domainManagement; + } + + public void setDomainManagement(String domainManagement) { + this.domainManagement = domainManagement; + } + + /** + * The tags associated with this resource + */ + @Updatable + public Map getTags() { + if (tags == null) { + tags = new HashMap<>(); + } + + return tags; + } + + public void setTags(Map tags) { + this.tags = tags; + } + + /** + * The location where the email service stores its data at rest + */ + @Output + public String getDataLocation() { + return dataLocation; + } + + public void setDataLocation(String dataLocation) { + this.dataLocation = dataLocation; + } + + @Output + @Id + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public void copyFrom(com.azure.resourcemanager.communication.models.DomainResource model) { + setDomainManagement(model.domainManagement().toString()); + setId(model.id()); + setName(model.name()); + setDataLocation(model.dataLocation()); + + getTags().clear(); + if (model.tags() != null) { + getTags().putAll(model.tags()); + } + } + + @Override + public boolean refresh() { + CommunicationManager client = createCommunicationClient(); + + com.azure.resourcemanager.communication.models.DomainResource domain = client.domains().getById(getId()); + + if (domain == null) { + return false; + } + + copyFrom(domain); + + return true; + } + + @Override + public void create(GyroUI ui, State state) throws Exception { + CommunicationManager client = createCommunicationClient(); + + DomainResourceInner service = new DomainResourceInner(); + service.withLocation("global"); + + if (!getTags().isEmpty()) { + service.withTags(getTags()); + } + + if (getDomainManagement() != null) { + service.withDomainManagement(DomainManagement.fromString(getDomainManagement())); + } + + setId(client.serviceClient().getDomains() + .createOrUpdate(getResourceGroup().getName(), getEmailService().getName(), getName(), service).id()); + } + + @Override + public void update(GyroUI ui, State state, Resource current, Set changedFieldNames) throws Exception { + CommunicationManager client = createCommunicationClient(); + + DomainResourceInner service = client.serviceClient().getDomains() + .get(getResourceGroup().getName(), getEmailService().getName(), getName()); + + service.withTags(getTags()); + + client.serviceClient().getDomains() + .createOrUpdate(getResourceGroup().getName(), getEmailService().getName(), getName(), service); + } + + @Override + public void delete(GyroUI ui, State state) throws Exception { + CommunicationManager client = createCommunicationClient(); + + client.serviceClient().getDomains() + .delete(getResourceGroup().getName(), getEmailService().getName(), getName()); + } +} diff --git a/src/main/java/gyro/azure/communication/EmailServiceFinder.java b/src/main/java/gyro/azure/communication/EmailServiceFinder.java new file mode 100644 index 00000000..61d2dfed --- /dev/null +++ b/src/main/java/gyro/azure/communication/EmailServiceFinder.java @@ -0,0 +1,95 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import com.azure.resourcemanager.communication.CommunicationManager; +import gyro.azure.AzureFinder; +import gyro.core.Type; + +@Type("email-service") +public class EmailServiceFinder + extends + AzureFinder { + + private String id; + private String resourceGroup; + private String name; + + /** + * The Id of the service + */ + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * The resource group of the service + */ + public String getResourceGroup() { + return resourceGroup; + } + + public void setResourceGroup(String resourceGroup) { + this.resourceGroup = resourceGroup; + } + + /** + * The name of the service + */ + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + protected List findAllAzure( + CommunicationManager client) { + return client.emailServices().list().stream().collect(Collectors.toList()); + } + + @Override + protected List findAzure( + CommunicationManager client, Map filters) { + if (filters.containsKey("id")) { + return Collections.singletonList(client.emailServices().getById(filters.get("id"))); + } + + if (filters.containsKey("resource-group")) { + if (filters.containsKey("name")) { + return Collections.singletonList(client.emailServices().getByResourceGroup( + filters.get("resource-group"), filters.get("name"))); + } + + return client.emailServices().listByResourceGroup(filters.get("resource-group")).stream() + .collect(Collectors.toList()); + } + + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/main/java/gyro/azure/communication/EmailServiceResource.java b/src/main/java/gyro/azure/communication/EmailServiceResource.java new file mode 100644 index 00000000..e4794913 --- /dev/null +++ b/src/main/java/gyro/azure/communication/EmailServiceResource.java @@ -0,0 +1,178 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import com.azure.resourcemanager.communication.CommunicationManager; +import com.azure.resourcemanager.communication.fluent.models.EmailServiceResourceInner; +import gyro.azure.AzureResource; +import gyro.azure.Copyable; +import gyro.azure.resources.ResourceGroupResource; +import gyro.core.GyroUI; +import gyro.core.Type; +import gyro.core.resource.Id; +import gyro.core.resource.Output; +import gyro.core.resource.Resource; +import gyro.core.resource.Updatable; +import gyro.core.scope.State; +import gyro.core.validation.Required; + +@Type("email-service") +public class EmailServiceResource extends AzureResource + implements Copyable { + + private ResourceGroupResource resourceGroup; + private String name; + private String dataLocation; + private Map tags; + + // Read-Only + private String id; + + /** + * The resource group in which to build the client + */ + @Required + public ResourceGroupResource getResourceGroup() { + return resourceGroup; + } + + public void setResourceGroup(ResourceGroupResource resourceGroup) { + this.resourceGroup = resourceGroup; + } + + /** + * The name of the email client + */ + @Required + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * The location where the email service stores its data at rest + */ + @Required + public String getDataLocation() { + return dataLocation; + } + + public void setDataLocation(String dataLocation) { + this.dataLocation = dataLocation; + } + + /** + * The tags associated to the email service + */ + @Updatable + public Map getTags() { + if (tags == null) { + tags = new HashMap<>(); + } + + return tags; + } + + public void setTags(Map tags) { + this.tags = tags; + } + + /** + * The ID of the email service + */ + @Id + @Output + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public void copyFrom(com.azure.resourcemanager.communication.models.EmailServiceResource model) { + setId(model.id()); + setName(model.name()); + setDataLocation(model.dataLocation()); + + getTags().clear(); + if (model.tags() != null) { + getTags().putAll(model.tags()); + } + } + + @Override + public boolean refresh() { + CommunicationManager client = createCommunicationClient(); + + com.azure.resourcemanager.communication.models.EmailServiceResource service = client.emailServices() + .getByResourceGroup(getResourceGroup().getName(), getName()); + + if (service == null) { + return false; + } + + copyFrom(service); + + return true; + } + + @Override + public void create(GyroUI ui, State state) throws Exception { + CommunicationManager client = createCommunicationClient(); + + EmailServiceResourceInner service = new EmailServiceResourceInner(); + service.withLocation("global"); + + if (getDataLocation() != null) { + service.withDataLocation(getDataLocation()); + } + + if (!getTags().isEmpty()) { + service.withTags(getTags()); + } + + client.serviceClient().getEmailServices().createOrUpdate(getResourceGroup().getName(), getName(), service); + } + + @Override + public void update(GyroUI ui, State state, Resource current, Set changedFieldNames) throws Exception { + CommunicationManager client = createCommunicationClient(); + + EmailServiceResourceInner service = client.serviceClient().getEmailServices() + .getByResourceGroup(getResourceGroup().getName(), getName()); + + service.withTags(getTags()); + + client.serviceClient().getEmailServices().createOrUpdate(getResourceGroup().getName(), getName(), service); + } + + @Override + public void delete(GyroUI ui, State state) throws Exception { + CommunicationManager client = createCommunicationClient(); + + client.serviceClient().getEmailServices().delete(getResourceGroup().getName(), getName()); + } +} diff --git a/src/main/java/gyro/azure/communication/package-info.java b/src/main/java/gyro/azure/communication/package-info.java new file mode 100644 index 00000000..96cc97f4 --- /dev/null +++ b/src/main/java/gyro/azure/communication/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@DocGroup("Communication") +package gyro.azure.communication; + +import gyro.core.resource.DocGroup; \ No newline at end of file diff --git a/src/main/java/gyro/azure/compute/AvailabilitySetFinder.java b/src/main/java/gyro/azure/compute/AvailabilitySetFinder.java index 08d08c43..55a896eb 100644 --- a/src/main/java/gyro/azure/compute/AvailabilitySetFinder.java +++ b/src/main/java/gyro/azure/compute/AvailabilitySetFinder.java @@ -37,7 +37,7 @@ * availability-set: $(external-query azure::availability-set {}) */ @Type("availability-set") -public class AvailabilitySetFinder extends AzureFinder { +public class AvailabilitySetFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/compute/DiskFinder.java b/src/main/java/gyro/azure/compute/DiskFinder.java index aa7aeb92..3a62b07f 100644 --- a/src/main/java/gyro/azure/compute/DiskFinder.java +++ b/src/main/java/gyro/azure/compute/DiskFinder.java @@ -37,7 +37,7 @@ * disk: $(external-query azure::disk {}) */ @Type("disk") -public class DiskFinder extends AzureFinder { +public class DiskFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/compute/SnapshotFinder.java b/src/main/java/gyro/azure/compute/SnapshotFinder.java index bf4c04b0..ac6726e4 100644 --- a/src/main/java/gyro/azure/compute/SnapshotFinder.java +++ b/src/main/java/gyro/azure/compute/SnapshotFinder.java @@ -37,7 +37,7 @@ * snapshot: $(external-query azure::snapshot {}) */ @Type("snapshot") -public class SnapshotFinder extends AzureFinder { +public class SnapshotFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/compute/VMScaleSetFinder.java b/src/main/java/gyro/azure/compute/VMScaleSetFinder.java index 9456e6de..7755659b 100644 --- a/src/main/java/gyro/azure/compute/VMScaleSetFinder.java +++ b/src/main/java/gyro/azure/compute/VMScaleSetFinder.java @@ -37,7 +37,7 @@ * scale-set: $(external-query azure::scale-set {}) */ @Type("scale-set") -public class VMScaleSetFinder extends AzureFinder { +public class VMScaleSetFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/compute/VMScaleSetScalingFinder.java b/src/main/java/gyro/azure/compute/VMScaleSetScalingFinder.java index abcc8f73..8a10ac39 100644 --- a/src/main/java/gyro/azure/compute/VMScaleSetScalingFinder.java +++ b/src/main/java/gyro/azure/compute/VMScaleSetScalingFinder.java @@ -37,7 +37,7 @@ * scale-set-scaling: $(external-query azure::scale-set-scaling {}) */ @Type("scale-set-scaling") -public class VMScaleSetScalingFinder extends AzureFinder { +public class VMScaleSetScalingFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/compute/VirtualMachineFinder.java b/src/main/java/gyro/azure/compute/VirtualMachineFinder.java index d64c7e2c..800837fa 100644 --- a/src/main/java/gyro/azure/compute/VirtualMachineFinder.java +++ b/src/main/java/gyro/azure/compute/VirtualMachineFinder.java @@ -37,7 +37,7 @@ * virtual-machine: $(external-query azure::virtual-machine {}) */ @Type("virtual-machine") -public class VirtualMachineFinder extends AzureFinder { +public class VirtualMachineFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/compute/VirtualMachineImageFinder.java b/src/main/java/gyro/azure/compute/VirtualMachineImageFinder.java index 3fbc78e5..970384b1 100644 --- a/src/main/java/gyro/azure/compute/VirtualMachineImageFinder.java +++ b/src/main/java/gyro/azure/compute/VirtualMachineImageFinder.java @@ -38,7 +38,7 @@ */ @Type("virtual-machine-image") public class VirtualMachineImageFinder - extends AzureFinder { + extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/containerservice/KubernetesClusterFinder.java b/src/main/java/gyro/azure/containerservice/KubernetesClusterFinder.java index ccbfeb09..a8b83f0d 100644 --- a/src/main/java/gyro/azure/containerservice/KubernetesClusterFinder.java +++ b/src/main/java/gyro/azure/containerservice/KubernetesClusterFinder.java @@ -37,7 +37,7 @@ * kubernetes-cluster: $(external-query azure::kubernetes-cluster {}) */ @Type("kubernetes-cluster") -public class KubernetesClusterFinder extends AzureFinder { +public class KubernetesClusterFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/cosmosdb/CosmosDBAccountFinder.java b/src/main/java/gyro/azure/cosmosdb/CosmosDBAccountFinder.java index 09d78a90..56f87331 100644 --- a/src/main/java/gyro/azure/cosmosdb/CosmosDBAccountFinder.java +++ b/src/main/java/gyro/azure/cosmosdb/CosmosDBAccountFinder.java @@ -37,7 +37,7 @@ * cosmos-db: $(external-query azure::cosmos-db {}) */ @Type("cosmos-db") -public class CosmosDBAccountFinder extends AzureFinder { +public class CosmosDBAccountFinder extends AzureFinder { private String id; /** diff --git a/src/main/java/gyro/azure/dns/ARecordSetFinder.java b/src/main/java/gyro/azure/dns/ARecordSetFinder.java index d39ffb1b..d117c4f7 100644 --- a/src/main/java/gyro/azure/dns/ARecordSetFinder.java +++ b/src/main/java/gyro/azure/dns/ARecordSetFinder.java @@ -40,7 +40,7 @@ * a-record-set: $(external-query azure::a-record-set {}) */ @Type("a-record-set") -public class ARecordSetFinder extends AzureFinder { +public class ARecordSetFinder extends AzureFinder { private String dnsZoneId; private String name; diff --git a/src/main/java/gyro/azure/dns/AaaaRecordSetFinder.java b/src/main/java/gyro/azure/dns/AaaaRecordSetFinder.java index bb8a498e..0bcc59d5 100644 --- a/src/main/java/gyro/azure/dns/AaaaRecordSetFinder.java +++ b/src/main/java/gyro/azure/dns/AaaaRecordSetFinder.java @@ -40,7 +40,7 @@ * aaaa-record-set: $(external-query azure::aaaa-record-set {}) */ @Type("aaaa-record-set") -public class AaaaRecordSetFinder extends AzureFinder { +public class AaaaRecordSetFinder extends AzureFinder { private String dnsZoneId; private String name; diff --git a/src/main/java/gyro/azure/dns/CaaRecordSetFinder.java b/src/main/java/gyro/azure/dns/CaaRecordSetFinder.java index 407b5b53..c7749bfb 100644 --- a/src/main/java/gyro/azure/dns/CaaRecordSetFinder.java +++ b/src/main/java/gyro/azure/dns/CaaRecordSetFinder.java @@ -40,7 +40,7 @@ * caa-record-set: $(external-query azure::caa-record-set {}) */ @Type("caa-record-set") -public class CaaRecordSetFinder extends AzureFinder { +public class CaaRecordSetFinder extends AzureFinder { private String dnsZoneId; private String name; diff --git a/src/main/java/gyro/azure/dns/CnameRecordSetFinder.java b/src/main/java/gyro/azure/dns/CnameRecordSetFinder.java index 2178e503..aec05091 100644 --- a/src/main/java/gyro/azure/dns/CnameRecordSetFinder.java +++ b/src/main/java/gyro/azure/dns/CnameRecordSetFinder.java @@ -40,7 +40,7 @@ * cname-record-set: $(external-query azure::cname-record-set {}) */ @Type("cname-record-set") -public class CnameRecordSetFinder extends AzureFinder { +public class CnameRecordSetFinder extends AzureFinder { private String dnsZoneId; private String name; diff --git a/src/main/java/gyro/azure/dns/DnsZoneFinder.java b/src/main/java/gyro/azure/dns/DnsZoneFinder.java index 82dd0abb..c7422c65 100644 --- a/src/main/java/gyro/azure/dns/DnsZoneFinder.java +++ b/src/main/java/gyro/azure/dns/DnsZoneFinder.java @@ -16,6 +16,11 @@ package gyro.azure.dns; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + import com.azure.resourcemanager.AzureResourceManager; import com.azure.resourcemanager.dns.models.DnsZone; import com.psddev.dari.util.ObjectUtils; @@ -23,11 +28,6 @@ import gyro.core.GyroException; import gyro.core.Type; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - /** * Query dns zone. * @@ -39,7 +39,7 @@ * dns-zone: $(external-query azure::dns-zone {}) */ @Type("dns-zone") -public class DnsZoneFinder extends AzureFinder { +public class DnsZoneFinder extends AzureFinder { private String id; /** diff --git a/src/main/java/gyro/azure/dns/MxRecordSetFinder.java b/src/main/java/gyro/azure/dns/MxRecordSetFinder.java index 7de2405a..a41d2ecb 100644 --- a/src/main/java/gyro/azure/dns/MxRecordSetFinder.java +++ b/src/main/java/gyro/azure/dns/MxRecordSetFinder.java @@ -40,7 +40,7 @@ * mx-record-set: $(external-query azure::mx-record-set {}) */ @Type("mx-record-set") -public class MxRecordSetFinder extends AzureFinder { +public class MxRecordSetFinder extends AzureFinder { private String dnsZoneId; private String name; diff --git a/src/main/java/gyro/azure/dns/PtrRecordSetFinder.java b/src/main/java/gyro/azure/dns/PtrRecordSetFinder.java index 34e69e47..69ab9500 100644 --- a/src/main/java/gyro/azure/dns/PtrRecordSetFinder.java +++ b/src/main/java/gyro/azure/dns/PtrRecordSetFinder.java @@ -40,7 +40,7 @@ * ptr-record-set: $(external-query azure::ptr-record-set {}) */ @Type("ptr-record-set") -public class PtrRecordSetFinder extends AzureFinder { +public class PtrRecordSetFinder extends AzureFinder { private String dnsZoneId; private String name; diff --git a/src/main/java/gyro/azure/dns/SrvRecordSetFinder.java b/src/main/java/gyro/azure/dns/SrvRecordSetFinder.java index 3d30cc17..159a63a7 100644 --- a/src/main/java/gyro/azure/dns/SrvRecordSetFinder.java +++ b/src/main/java/gyro/azure/dns/SrvRecordSetFinder.java @@ -40,7 +40,7 @@ * srv-record-set: $(external-query azure::srv-record-set {}) */ @Type("srv-record-set") -public class SrvRecordSetFinder extends AzureFinder { +public class SrvRecordSetFinder extends AzureFinder { private String dnsZoneId; private String name; diff --git a/src/main/java/gyro/azure/dns/TxtRecordSetFinder.java b/src/main/java/gyro/azure/dns/TxtRecordSetFinder.java index cde37c52..0bf02701 100644 --- a/src/main/java/gyro/azure/dns/TxtRecordSetFinder.java +++ b/src/main/java/gyro/azure/dns/TxtRecordSetFinder.java @@ -40,7 +40,7 @@ * txt-record-set: $(external-query azure::txt-record-set {}) */ @Type("txt-record-set") -public class TxtRecordSetFinder extends AzureFinder { +public class TxtRecordSetFinder extends AzureFinder { private String dnsZoneId; private String name; diff --git a/src/main/java/gyro/azure/identity/IdentityFinder.java b/src/main/java/gyro/azure/identity/IdentityFinder.java index b3e8f259..a15ac4e8 100644 --- a/src/main/java/gyro/azure/identity/IdentityFinder.java +++ b/src/main/java/gyro/azure/identity/IdentityFinder.java @@ -37,7 +37,7 @@ * identity: $(external-query azure::identity {}) */ @Type("identity") -public class IdentityFinder extends AzureFinder { +public class IdentityFinder extends AzureFinder { private String id; /** diff --git a/src/main/java/gyro/azure/keyvault/KeyVaultCertificateFinder.java b/src/main/java/gyro/azure/keyvault/KeyVaultCertificateFinder.java index f885c0f5..e8b49111 100644 --- a/src/main/java/gyro/azure/keyvault/KeyVaultCertificateFinder.java +++ b/src/main/java/gyro/azure/keyvault/KeyVaultCertificateFinder.java @@ -40,7 +40,7 @@ * certificate: $(external-query azure::key-vault-certificate {resource-group: "resource-group-example", vault: "vault-example", name: "certificate-example"}) */ @Type("key-vault-certificate") -public class KeyVaultCertificateFinder extends AzureFinder { +public class KeyVaultCertificateFinder extends AzureFinder { private String resourceGroup; private String vault; diff --git a/src/main/java/gyro/azure/keyvault/KeyVaultFinder.java b/src/main/java/gyro/azure/keyvault/KeyVaultFinder.java index 28b30190..0a7a7a4a 100644 --- a/src/main/java/gyro/azure/keyvault/KeyVaultFinder.java +++ b/src/main/java/gyro/azure/keyvault/KeyVaultFinder.java @@ -38,7 +38,7 @@ * identity: $(external-query azure::key-vault {resource-group: "resource-group-example", name: "vault-example"}) */ @Type("key-vault") -public class KeyVaultFinder extends AzureFinder { +public class KeyVaultFinder extends AzureFinder { private String resourceGroup; private String name; diff --git a/src/main/java/gyro/azure/keyvault/KeyVaultKeyFinder.java b/src/main/java/gyro/azure/keyvault/KeyVaultKeyFinder.java index 6b5d510a..e70b9776 100644 --- a/src/main/java/gyro/azure/keyvault/KeyVaultKeyFinder.java +++ b/src/main/java/gyro/azure/keyvault/KeyVaultKeyFinder.java @@ -21,7 +21,7 @@ * certificate: $(external-query azure::key-vault-key {resource-group: "resource-group-example", vault: "vault-example", name: "key-example"}) */ @Type("key-vault-key") -public class KeyVaultKeyFinder extends AzureFinder { +public class KeyVaultKeyFinder extends AzureFinder { private String resourceGroup; private String vault; diff --git a/src/main/java/gyro/azure/keyvault/KeyVaultSecretFinder.java b/src/main/java/gyro/azure/keyvault/KeyVaultSecretFinder.java index d30a964c..39978782 100644 --- a/src/main/java/gyro/azure/keyvault/KeyVaultSecretFinder.java +++ b/src/main/java/gyro/azure/keyvault/KeyVaultSecretFinder.java @@ -37,7 +37,7 @@ * certificate: $(external-query azure::key-vault-secret {resource-group: "resource-group-example", vault: "vault-example", name: "secret-example"}) */ @Type("key-vault-secret") -public class KeyVaultSecretFinder extends AzureFinder { +public class KeyVaultSecretFinder extends AzureFinder { private String resourceGroup; private String vault; diff --git a/src/main/java/gyro/azure/network/ApplicationGatewayFinder.java b/src/main/java/gyro/azure/network/ApplicationGatewayFinder.java index 13b1d873..e2529487 100644 --- a/src/main/java/gyro/azure/network/ApplicationGatewayFinder.java +++ b/src/main/java/gyro/azure/network/ApplicationGatewayFinder.java @@ -38,7 +38,7 @@ */ @Type("application-gateway") public class ApplicationGatewayFinder - extends AzureFinder { + extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/network/ApplicationSecurityGroupFinder.java b/src/main/java/gyro/azure/network/ApplicationSecurityGroupFinder.java index 729f4702..aae02700 100644 --- a/src/main/java/gyro/azure/network/ApplicationSecurityGroupFinder.java +++ b/src/main/java/gyro/azure/network/ApplicationSecurityGroupFinder.java @@ -38,7 +38,7 @@ */ @Type("application-security-group") public class ApplicationSecurityGroupFinder - extends AzureFinder { + extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/network/LoadBalancerFinder.java b/src/main/java/gyro/azure/network/LoadBalancerFinder.java index d9c9246a..a70c624d 100644 --- a/src/main/java/gyro/azure/network/LoadBalancerFinder.java +++ b/src/main/java/gyro/azure/network/LoadBalancerFinder.java @@ -37,7 +37,7 @@ * load-balancer: $(external-query azure::load-balancer {}) */ @Type("load-balancer") -public class LoadBalancerFinder extends AzureFinder { +public class LoadBalancerFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/network/NetworkFinder.java b/src/main/java/gyro/azure/network/NetworkFinder.java index 11fe1bda..4bea3e55 100644 --- a/src/main/java/gyro/azure/network/NetworkFinder.java +++ b/src/main/java/gyro/azure/network/NetworkFinder.java @@ -37,7 +37,7 @@ * network: $(external-query azure::network {}) */ @Type("network") -public class NetworkFinder extends AzureFinder { +public class NetworkFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/network/NetworkInterfaceFinder.java b/src/main/java/gyro/azure/network/NetworkInterfaceFinder.java index 0ef56833..c2373132 100644 --- a/src/main/java/gyro/azure/network/NetworkInterfaceFinder.java +++ b/src/main/java/gyro/azure/network/NetworkInterfaceFinder.java @@ -37,7 +37,7 @@ * network-interface: $(external-query azure::network-interface {}) */ @Type("network-interface") -public class NetworkInterfaceFinder extends AzureFinder { +public class NetworkInterfaceFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/network/NetworkSecurityGroupFinder.java b/src/main/java/gyro/azure/network/NetworkSecurityGroupFinder.java index 0f2b70d0..9b3e1b73 100644 --- a/src/main/java/gyro/azure/network/NetworkSecurityGroupFinder.java +++ b/src/main/java/gyro/azure/network/NetworkSecurityGroupFinder.java @@ -38,7 +38,7 @@ */ @Type("network-security-group") public class NetworkSecurityGroupFinder - extends AzureFinder { + extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/network/PublicIpAddressFinder.java b/src/main/java/gyro/azure/network/PublicIpAddressFinder.java index 61e4c2e7..f66b4727 100644 --- a/src/main/java/gyro/azure/network/PublicIpAddressFinder.java +++ b/src/main/java/gyro/azure/network/PublicIpAddressFinder.java @@ -37,7 +37,7 @@ * public-ip-address: $(external-query azure::public-ip-address {}) */ @Type("public-ip-address") -public class PublicIpAddressFinder extends AzureFinder { +public class PublicIpAddressFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/network/RouteTableFinder.java b/src/main/java/gyro/azure/network/RouteTableFinder.java index f9cbc5a2..a5738e2b 100644 --- a/src/main/java/gyro/azure/network/RouteTableFinder.java +++ b/src/main/java/gyro/azure/network/RouteTableFinder.java @@ -37,7 +37,7 @@ * route-table: $(external-query azure::route-table {}) */ @Type("route-table") -public class RouteTableFinder extends AzureFinder { +public class RouteTableFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/registries/RegistryFinder.java b/src/main/java/gyro/azure/registries/RegistryFinder.java index 8ddfd5e2..29357660 100644 --- a/src/main/java/gyro/azure/registries/RegistryFinder.java +++ b/src/main/java/gyro/azure/registries/RegistryFinder.java @@ -37,7 +37,7 @@ * registry: $(external-query azure::registry {}) */ @Type("registry") -public class RegistryFinder extends AzureFinder { +public class RegistryFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/resources/ResourceGroupFinder.java b/src/main/java/gyro/azure/resources/ResourceGroupFinder.java index 5deb8fc8..ea6658c4 100644 --- a/src/main/java/gyro/azure/resources/ResourceGroupFinder.java +++ b/src/main/java/gyro/azure/resources/ResourceGroupFinder.java @@ -37,7 +37,7 @@ * resource-group: $(external-query azure::resource-group {}) */ @Type("resource-group") -public class ResourceGroupFinder extends AzureFinder { +public class ResourceGroupFinder extends AzureFinder { private String name; /** diff --git a/src/main/java/gyro/azure/sql/SqlDatabaseFinder.java b/src/main/java/gyro/azure/sql/SqlDatabaseFinder.java index 43738515..283a10af 100644 --- a/src/main/java/gyro/azure/sql/SqlDatabaseFinder.java +++ b/src/main/java/gyro/azure/sql/SqlDatabaseFinder.java @@ -39,7 +39,7 @@ * sql-database: $(external-query azure::sql-database {}) */ @Type("sql-database") -public class SqlDatabaseFinder extends AzureFinder { +public class SqlDatabaseFinder extends AzureFinder { private String sqlServerId; private String name; diff --git a/src/main/java/gyro/azure/sql/SqlElasticPoolFinder.java b/src/main/java/gyro/azure/sql/SqlElasticPoolFinder.java index 361fd996..0ee8cd91 100644 --- a/src/main/java/gyro/azure/sql/SqlElasticPoolFinder.java +++ b/src/main/java/gyro/azure/sql/SqlElasticPoolFinder.java @@ -39,7 +39,7 @@ * sql-elastic-pool: $(external-query azure::sql-elastic-pool {}) */ @Type("sql-elastic-pool") -public class SqlElasticPoolFinder extends AzureFinder { +public class SqlElasticPoolFinder extends AzureFinder { private String sqlServerId; private String name; diff --git a/src/main/java/gyro/azure/sql/SqlFailoverGroupFinder.java b/src/main/java/gyro/azure/sql/SqlFailoverGroupFinder.java index 3ee123f8..368b7d08 100644 --- a/src/main/java/gyro/azure/sql/SqlFailoverGroupFinder.java +++ b/src/main/java/gyro/azure/sql/SqlFailoverGroupFinder.java @@ -39,7 +39,7 @@ * sql-failover-group: $(external-query azure::sql-failover-group {}) */ @Type("sql-failover-group") -public class SqlFailoverGroupFinder extends AzureFinder { +public class SqlFailoverGroupFinder extends AzureFinder { private String sqlServerId; private String name; diff --git a/src/main/java/gyro/azure/sql/SqlFirewallRuleFinder.java b/src/main/java/gyro/azure/sql/SqlFirewallRuleFinder.java index 6f36493b..b37430f8 100644 --- a/src/main/java/gyro/azure/sql/SqlFirewallRuleFinder.java +++ b/src/main/java/gyro/azure/sql/SqlFirewallRuleFinder.java @@ -39,7 +39,7 @@ * sql-firewall-rule: $(external-query azure::sql-firewall-rule {}) */ @Type("sql-firewall-rule") -public class SqlFirewallRuleFinder extends AzureFinder { +public class SqlFirewallRuleFinder extends AzureFinder { private String sqlServerId; private String name; diff --git a/src/main/java/gyro/azure/sql/SqlServerFinder.java b/src/main/java/gyro/azure/sql/SqlServerFinder.java index fa8fe383..edc16bac 100644 --- a/src/main/java/gyro/azure/sql/SqlServerFinder.java +++ b/src/main/java/gyro/azure/sql/SqlServerFinder.java @@ -37,7 +37,7 @@ * sql-server: $(external-query azure::sql-server {}) */ @Type("sql-server") -public class SqlServerFinder extends AzureFinder { +public class SqlServerFinder extends AzureFinder { private String id; diff --git a/src/main/java/gyro/azure/sql/SqlVirtualNetworkRuleFinder.java b/src/main/java/gyro/azure/sql/SqlVirtualNetworkRuleFinder.java index 56435f74..0164a431 100644 --- a/src/main/java/gyro/azure/sql/SqlVirtualNetworkRuleFinder.java +++ b/src/main/java/gyro/azure/sql/SqlVirtualNetworkRuleFinder.java @@ -40,7 +40,7 @@ */ @Type("sql-virtual-network-rule") public class SqlVirtualNetworkRuleFinder - extends AzureFinder { + extends AzureFinder { private String sqlServerId; private String name; diff --git a/src/main/java/gyro/azure/storage/StorageAccountFinder.java b/src/main/java/gyro/azure/storage/StorageAccountFinder.java index f406e694..fb7d5704 100644 --- a/src/main/java/gyro/azure/storage/StorageAccountFinder.java +++ b/src/main/java/gyro/azure/storage/StorageAccountFinder.java @@ -28,7 +28,7 @@ import gyro.core.Type; @Type("storage-account") -public class StorageAccountFinder extends AzureFinder { +public class StorageAccountFinder extends AzureFinder { private String id; private String resourceGroup; From 082db186bc0b04e57e5864d0a1d460c2f9d788b1 Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Wed, 31 Jul 2024 13:50:38 -0400 Subject: [PATCH 2/3] Add examples and more output fields --- .../CommunicationServiceResource.java | 45 +++++- .../azure/communication/DomainDnsRecord.java | 90 ++++++++++++ .../azure/communication/DomainResource.java | 40 +++++- .../communication/EmailServiceResource.java | 23 ++- .../communication/VerificationRecords.java | 135 ++++++++++++++++++ 5 files changed, 323 insertions(+), 10 deletions(-) create mode 100644 src/main/java/gyro/azure/communication/DomainDnsRecord.java create mode 100644 src/main/java/gyro/azure/communication/VerificationRecords.java diff --git a/src/main/java/gyro/azure/communication/CommunicationServiceResource.java b/src/main/java/gyro/azure/communication/CommunicationServiceResource.java index 2431fa70..ed2e4afc 100644 --- a/src/main/java/gyro/azure/communication/CommunicationServiceResource.java +++ b/src/main/java/gyro/azure/communication/CommunicationServiceResource.java @@ -37,7 +37,31 @@ import gyro.core.scope.State; import gyro.core.validation.Required; - +/** + * Creates a communication service. + * + * Example + * ------- + * + * .. code-block:: gyro + * + * azure::communication-service service-example + * resource-group: $(azure::resource-group resource-group-example) + * name: "service-example-test" + * data-location: "United States" + * domains: [ + * $(azure::domain domain-example) + * ] + * + * identity + * user-assigned-identity: [$(azure::identity identity-example)] + * end + * + * tags: { + * Name: "service-example-test" + * } + * end + */ @Type("communication-service") public class CommunicationServiceResource extends AzureResource implements Copyable { @@ -117,7 +141,7 @@ public void setDataLocation(String dataLocation) { } /** - * List of email Domain resources. + * List of email Domain resources. These domain have to be verified for them to be connected ot the service. */ @Updatable public List getDomains() { @@ -179,7 +203,7 @@ public void copyFrom(com.azure.resourcemanager.communication.models.Communicatio setIdentity(null); if (model.identity() != null) { CommunicationServiceManagedServiceIdentity serviceIdentity = - new CommunicationServiceManagedServiceIdentity(); + newSubresource(CommunicationServiceManagedServiceIdentity.class); serviceIdentity.copyFrom(model.identity()); setIdentity(serviceIdentity); } @@ -215,15 +239,22 @@ public void create(GyroUI ui, State state) throws Exception { service.withTags(getTags()); } - if (!getDomains().isEmpty()) { - service.withLinkedDomains(getDomains().stream().map(DomainResource::getId).collect(Collectors.toList())); - } - if (getDataLocation() != null) { service.withDataLocation(getDataLocation()); } service.withLocation("global"); + setId(client.serviceClient().getCommunicationServices() + .createOrUpdate(getResourceGroup().getName(), getName(), service).id()); + + state.save(); + + // Add domains in the update call + // If domains are not verified but are added to the create call, the api errors out at the service is not saved to the state + if (!getDomains().isEmpty()) { + service.withLinkedDomains(getDomains().stream().map(DomainResource::getId).collect(Collectors.toList())); + } + client.serviceClient().getCommunicationServices() .createOrUpdate(getResourceGroup().getName(), getName(), service); } diff --git a/src/main/java/gyro/azure/communication/DomainDnsRecord.java b/src/main/java/gyro/azure/communication/DomainDnsRecord.java new file mode 100644 index 00000000..4a449720 --- /dev/null +++ b/src/main/java/gyro/azure/communication/DomainDnsRecord.java @@ -0,0 +1,90 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import com.azure.resourcemanager.communication.models.DnsRecord; +import gyro.azure.Copyable; +import gyro.core.resource.Diffable; +import gyro.core.resource.Output; + +public class DomainDnsRecord extends Diffable implements Copyable { + private String name; + private Integer ttl; + private String type; + private String value; + + /** + * The name of the dns record. + */ + @Output + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * The ttl of the dns record. + */ + @Output + public Integer getTtl() { + return ttl; + } + + public void setTtl(Integer ttl) { + this.ttl = ttl; + } + + /** + * The type of the dns record. + */ + @Output + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + /** + * The value of the dns record. + */ + @Output + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public void copyFrom(DnsRecord model) { + setName(model.name()); + setTtl(model.ttl()); + setType(model.type()); + setValue(model.value()); + } + + @Override + public String primaryKey() { + return ""; + } +} diff --git a/src/main/java/gyro/azure/communication/DomainResource.java b/src/main/java/gyro/azure/communication/DomainResource.java index 9e0ffcef..e05e0636 100644 --- a/src/main/java/gyro/azure/communication/DomainResource.java +++ b/src/main/java/gyro/azure/communication/DomainResource.java @@ -23,7 +23,6 @@ import com.azure.resourcemanager.communication.CommunicationManager; import com.azure.resourcemanager.communication.fluent.models.DomainResourceInner; import com.azure.resourcemanager.communication.models.DomainManagement; -import com.azure.resourcemanager.communication.models.DomainPropertiesVerificationRecords; import gyro.azure.AzureResource; import gyro.azure.Copyable; import gyro.azure.resources.ResourceGroupResource; @@ -37,6 +36,25 @@ import gyro.core.validation.Required; import gyro.core.validation.ValidStrings; +/** + * Creates a Domain + * + * Example + * ------- + * + * .. code-block:: gyro + * + * azure::domain domain-example + * resource-group: $(azure::resource-group resource-group-example) + * email-service: $(azure::email-service email-service-example) + * domain-management: "CustomerManaged" + * name: "cloud.brightspot.dev" + * + * tags: { + * "example": "example" + * } + * end + */ @Type("domain") public class DomainResource extends AzureResource implements Copyable { @@ -50,6 +68,7 @@ public class DomainResource extends AzureResource // Read-only private String dataLocation; private String id; + private VerificationRecords verificationRecords; /** * The resource group in which to build the service @@ -141,6 +160,18 @@ public void setId(String id) { this.id = id; } + /** + * The verification records for this domain + */ + @Output + public VerificationRecords getVerificationRecords() { + return verificationRecords; + } + + public void setVerificationRecords(VerificationRecords verificationRecords) { + this.verificationRecords = verificationRecords; + } + @Override public void copyFrom(com.azure.resourcemanager.communication.models.DomainResource model) { setDomainManagement(model.domainManagement().toString()); @@ -152,6 +183,13 @@ public void copyFrom(com.azure.resourcemanager.communication.models.DomainResour if (model.tags() != null) { getTags().putAll(model.tags()); } + + setVerificationRecords(null); + if (model.verificationRecords() != null) { + VerificationRecords records = new VerificationRecords(); + records.copyFrom(model.verificationRecords()); + setVerificationRecords(records); + } } @Override diff --git a/src/main/java/gyro/azure/communication/EmailServiceResource.java b/src/main/java/gyro/azure/communication/EmailServiceResource.java index e4794913..ff65505f 100644 --- a/src/main/java/gyro/azure/communication/EmailServiceResource.java +++ b/src/main/java/gyro/azure/communication/EmailServiceResource.java @@ -34,6 +34,24 @@ import gyro.core.scope.State; import gyro.core.validation.Required; +/** + * Creates an email service. + * + * Example + * ------- + * + * .. code-block:: gyro + * + * azure::email-service email-service-example + * resource-group: $(azure::resource-group resource-group-example) + * name: "example-email-test" + * data-location: "United States" + * + * tags: { + * Name: "example-email-test" + * } + * end + */ @Type("email-service") public class EmailServiceResource extends AzureResource implements Copyable { @@ -128,7 +146,7 @@ public boolean refresh() { CommunicationManager client = createCommunicationClient(); com.azure.resourcemanager.communication.models.EmailServiceResource service = client.emailServices() - .getByResourceGroup(getResourceGroup().getName(), getName()); + .getById(getId()); if (service == null) { return false; @@ -154,7 +172,8 @@ public void create(GyroUI ui, State state) throws Exception { service.withTags(getTags()); } - client.serviceClient().getEmailServices().createOrUpdate(getResourceGroup().getName(), getName(), service); + setId(client.serviceClient().getEmailServices().createOrUpdate(getResourceGroup().getName(), getName(), service) + .id()); } @Override diff --git a/src/main/java/gyro/azure/communication/VerificationRecords.java b/src/main/java/gyro/azure/communication/VerificationRecords.java new file mode 100644 index 00000000..c6146d2a --- /dev/null +++ b/src/main/java/gyro/azure/communication/VerificationRecords.java @@ -0,0 +1,135 @@ +/* + * Copyright 2024, Perfect Sense, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gyro.azure.communication; + +import com.azure.resourcemanager.communication.models.DomainPropertiesVerificationRecords; +import gyro.azure.Copyable; +import gyro.core.resource.Diffable; +import gyro.core.resource.Output; + +public class VerificationRecords extends Diffable implements Copyable { + + private DomainDnsRecord dkim; + private DomainDnsRecord spf; + private DomainDnsRecord dkim2; + private DomainDnsRecord dmarc; + private DomainDnsRecord domain; + + /** + * The dkim verification record. + */ + @Output + public DomainDnsRecord getDkim() { + return dkim; + } + + public void setDkim(DomainDnsRecord dkim) { + this.dkim = dkim; + } + + /** + * The spf verification record. + */ + @Output + public DomainDnsRecord getSpf() { + return spf; + } + + public void setSpf(DomainDnsRecord spf) { + this.spf = spf; + } + + /** + * The dkim2 verification record. + */ + @Output + public DomainDnsRecord getDkim2() { + return dkim2; + } + + public void setDkim2(DomainDnsRecord dkim2) { + this.dkim2 = dkim2; + } + + /** + * The dmarc verification record. + */ + @Output + public DomainDnsRecord getDmarc() { + return dmarc; + } + + public void setDmarc(DomainDnsRecord dmarc) { + this.dmarc = dmarc; + } + + /** + * The domain verification record. + */ + @Output + public DomainDnsRecord getDomain() { + return domain; + } + + public void setDomain(DomainDnsRecord domain) { + this.domain = domain; + } + + @Override + public void copyFrom(DomainPropertiesVerificationRecords model) { + setDkim(null); + if (model.dkim() != null) { + DomainDnsRecord dkimRecord = new DomainDnsRecord(); + dkimRecord.copyFrom(model.dkim()); + setDkim(dkimRecord); + } + + setSpf(null); + if (model.spf() != null) { + DomainDnsRecord spfRecord = new DomainDnsRecord(); + spfRecord.copyFrom(model.spf()); + setSpf(spfRecord); + } + + setDkim2(null); + if (model.dkim2() != null) { + DomainDnsRecord dkim2Record = new DomainDnsRecord(); + dkim2Record.copyFrom(model.dkim2()); + setDkim2(dkim2Record); + } + + setDmarc(null); + if (model.dmarc() != null) { + DomainDnsRecord dmarcRecord = new DomainDnsRecord(); + dmarcRecord.copyFrom(model.dmarc()); + setDmarc(dmarcRecord); + } + + setDomain(null); + if (model.domain() != null) { + DomainDnsRecord domainRecord = new DomainDnsRecord(); + domainRecord.copyFrom(model.domain()); + setDomain(domainRecord); + } + + } + + @Override + public String primaryKey() { + return ""; + } +} From 04183ffefc53f5396122a2981e9a17fe34129a71 Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Wed, 31 Jul 2024 13:59:57 -0400 Subject: [PATCH 3/3] Add finder examples --- .../communication/CommunicationServiceFinder.java | 10 ++++++++++ .../java/gyro/azure/communication/DomainFinder.java | 10 ++++++++++ .../gyro/azure/communication/EmailServiceFinder.java | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/main/java/gyro/azure/communication/CommunicationServiceFinder.java b/src/main/java/gyro/azure/communication/CommunicationServiceFinder.java index 822dc6d2..3dc47a4c 100644 --- a/src/main/java/gyro/azure/communication/CommunicationServiceFinder.java +++ b/src/main/java/gyro/azure/communication/CommunicationServiceFinder.java @@ -25,6 +25,16 @@ import gyro.azure.AzureFinder; import gyro.core.Type; +/** + * Query communication service. + * + * Example + * ------- + * + * .. code-block:: gyro + * + * service: $(external-query azure::communication-service {}) + */ @Type("communication-service") public class CommunicationServiceFinder extends AzureFinder { diff --git a/src/main/java/gyro/azure/communication/DomainFinder.java b/src/main/java/gyro/azure/communication/DomainFinder.java index ef60c3a3..9efb9f4b 100644 --- a/src/main/java/gyro/azure/communication/DomainFinder.java +++ b/src/main/java/gyro/azure/communication/DomainFinder.java @@ -26,6 +26,16 @@ import gyro.core.GyroException; import gyro.core.Type; +/** + * Query domains. + * + * Example + * ------- + * + * .. code-block:: gyro + * + * domain: $(external-query azure::domain {id: "/subscriptions/26c9ce65-e0ea-42e8-9e5e-22d5ccd58343/resourceGroups/resource-group-example-test/providers/Microsoft.Communication/emailServices/example-email-test/domains/cloud.brightspot.dev"}) + */ @Type("domain") public class DomainFinder extends AzureFinder { diff --git a/src/main/java/gyro/azure/communication/EmailServiceFinder.java b/src/main/java/gyro/azure/communication/EmailServiceFinder.java index 61d2dfed..c99f7d26 100644 --- a/src/main/java/gyro/azure/communication/EmailServiceFinder.java +++ b/src/main/java/gyro/azure/communication/EmailServiceFinder.java @@ -25,6 +25,16 @@ import gyro.azure.AzureFinder; import gyro.core.Type; +/** + * Query email service. + * + * Example + * ------- + * + * .. code-block:: gyro + * + * service: $(external-query azure::email-service {}) + */ @Type("email-service") public class EmailServiceFinder extends