Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for communication and email services #150

Merged
merged 9 commits into from
Aug 1, 2024
54 changes: 54 additions & 0 deletions examples/communication/communication-service.gyro
Original file line number Diff line number Diff line change
@@ -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
106 changes: 106 additions & 0 deletions src/main/java/gyro/azure/communication/CommunicationServiceFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2024, Perfect Sense, Inc.
deepanjan90 marked this conversation as resolved.
Show resolved Hide resolved
*
* 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;

/**
* Query communication service.
*
* Example
* -------
*
* .. code-block:: gyro
*
* service: $(external-query azure::communication-service {})
deepanjan90 marked this conversation as resolved.
Show resolved Hide resolved
*/
@Type("communication-service")
public class CommunicationServiceFinder extends
AzureFinder<CommunicationManager, com.azure.resourcemanager.communication.models.CommunicationServiceResource, CommunicationServiceResource> {

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<com.azure.resourcemanager.communication.models.CommunicationServiceResource> findAllAzure(
CommunicationManager client) {
return client.communicationServices().list().stream().collect(Collectors.toList());
}

@Override
protected List<com.azure.resourcemanager.communication.models.CommunicationServiceResource> findAzure(
CommunicationManager client, Map<String, String> filters) {

deepanjan90 marked this conversation as resolved.
Show resolved Hide resolved

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();
}
}
Original file line number Diff line number Diff line change
@@ -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<ManagedServiceIdentity> {

private List<IdentityResource> userAssignedIdentity;
private String tenantId;
private String principalId;
private String type;

/**
* The identity to be associated with the application gateway.
*/
@Required
public List<IdentityResource> getUserAssignedIdentity() {
if (userAssignedIdentity == null) {
userAssignedIdentity = new ArrayList<>();
}

return userAssignedIdentity;
}

public void setUserAssignedIdentity(List<IdentityResource> 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<String, UserAssignedIdentity> map = new HashMap<>();

getUserAssignedIdentity().forEach(o -> map.put(o.getId(), userAssignedIdentity));
return new ManagedServiceIdentity().withType(ManagedServiceIdentityType.USER_ASSIGNED)
.withUserAssignedIdentities(map);
}
}
Loading
Loading