Skip to content

Commit

Permalink
feat: assign dataPlaneId to Domain
Browse files Browse the repository at this point in the history
  • Loading branch information
podlesrafal committed Jan 7, 2025
1 parent 2f9ca59 commit 1e0efd4
Show file tree
Hide file tree
Showing 48 changed files with 525 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<artifactId>gravitee-am-plugins-handlers-identityprovider</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.gravitee.am.plugins.handlers</groupId>
<artifactId>gravitee-am-plugins-handlers-dataplane</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Spring dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* 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 io.gravitee.am.management.handlers.management.api.resources.organizations.environments;

import io.gravitee.am.dataplane.api.DataPlane;
import io.gravitee.am.management.handlers.management.api.resources.AbstractResource;
import io.gravitee.am.model.Acl;
import io.gravitee.am.model.permissions.Permission;
import io.gravitee.am.plugins.dataplane.core.MultiDataPlaneLoader;
import io.gravitee.common.http.MediaType;
import io.reactivex.rxjava3.core.Maybe;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.container.Suspended;
import org.springframework.beans.factory.annotation.Autowired;

/**
* @author David BRASSELY (david.brassely at graviteesource.com)
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
* @author GraviteeSource Team
*/
@Tag(name = "dataPlane")
public class DataPlanesResource extends AbstractResource {

@Autowired
private MultiDataPlaneLoader multiDataPlaneLoader;

@GET
@Produces(MediaType.APPLICATION_JSON)
@Operation(
operationId = "listDataPlanes",
summary = "List of data planes",
description = "List all the data planes accessible to the current user. " +
"User must have DOMAIN[CREATE] permission on the specified environment or organization")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "List accessible data planes for current user",
content = @Content(mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = DataPlane.class)))),
@ApiResponse(responseCode = "500", description = "Internal server error")})
public void list(
@PathParam("organizationId") String organizationId,
@PathParam("environmentId") String environmentId,
@Suspended final AsyncResponse response) {

checkAnyPermission(organizationId, environmentId, Permission.DOMAIN, Acl.CREATE)
.andThen(Maybe.just(multiDataPlaneLoader.getDataPlanes()))
.subscribe(response::resume, response::resume);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public MembersResource getMembersResource() {
public DomainsResource getDomainsResource() {
return resourceContext.getResource(DomainsResource.class);
}

@Path("/data-planes")
public DataPlanesResource getDataPlanesResource() {
return resourceContext.getResource(DataPlanesResource.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ public void shouldGetDomains_technicalManagementException() {
public void shouldCreate() {
NewDomain newDomain = new NewDomain();
newDomain.setName("domain-name");
newDomain.setDataPlaneId("data-plane-id");

Domain domain = new Domain();
domain.setId("domain-id");
domain.setName("domain-name");
domain.setDataPlaneId("data-plane-id");

doReturn(Single.just(domain)).when(domainService).create(eq("DEFAULT"), eq("DEFAULT"), any(), any());
doReturn(Single.just(new IdentityProvider())).when(defaultIdentityProviderService).create(domain.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.gravitee.am.plugins.handlers</groupId>
<artifactId>gravitee-am-plugins-handlers-dataplane</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.gravitee.cockpit</groupId>
<artifactId>gravitee-cockpit-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.gravitee.am.common.utils.GraviteeContext;
import io.gravitee.am.common.utils.RandomString;
import io.gravitee.am.common.web.UriBuilder;
import io.gravitee.am.dataplane.api.DataPlaneDescription;
import io.gravitee.am.identityprovider.api.User;
import io.gravitee.am.management.service.DefaultIdentityProviderService;
import io.gravitee.am.management.service.DomainService;
Expand All @@ -40,6 +41,7 @@
import io.gravitee.am.model.membership.MemberType;
import io.gravitee.am.model.oidc.OIDCSettings;
import io.gravitee.am.model.permissions.SystemRole;
import io.gravitee.am.plugins.dataplane.core.MultiDataPlaneLoader;
import io.gravitee.am.repository.management.api.DomainRepository;
import io.gravitee.am.repository.management.api.search.AlertNotifierCriteria;
import io.gravitee.am.repository.management.api.search.AlertTriggerCriteria;
Expand Down Expand Up @@ -148,6 +150,8 @@ public class DomainServiceImpl implements DomainService {

private final Logger LOGGER = LoggerFactory.getLogger(DomainServiceImpl.class);

@Autowired
private MultiDataPlaneLoader multiDataPlaneLoader;

@Lazy
@Autowired
Expand Down Expand Up @@ -337,6 +341,9 @@ public Single<Domain> create(String organizationId, String environmentId, NewDom
LOGGER.debug("Create a new domain: {}", newDomain);
// generate hrid
String hrid = IdGenerator.generate(newDomain.getName());
if (multiDataPlaneLoader.getDataPlanes().stream().map(DataPlaneDescription::id).noneMatch(id -> id.equals(newDomain.getDataPlaneId()))) {
return Single.error(new TechnicalManagementException("An error occurred while trying to create a domain. Data plane with provided Id doesn't exist"));
}
return domainRepository.findByHrid(ReferenceType.ENVIRONMENT, environmentId, hrid)
.isEmpty()
.flatMap(empty -> {
Expand All @@ -357,6 +364,7 @@ public Single<Domain> create(String organizationId, String environmentId, NewDom
domain.setReferenceId(environmentId);
domain.setCreatedAt(new Date());
domain.setUpdatedAt(domain.getCreatedAt());
domain.setDataPlaneId(newDomain.getDataPlaneId());

return environmentService.findById(domain.getReferenceId())
.doOnSuccess(environment -> setDeployMode(domain, environment))
Expand Down Expand Up @@ -645,7 +653,7 @@ public Completable delete(GraviteeContext graviteeContext, String domainId, User
.principal(principal)
.type(EventType.DOMAIN_DELETED)
.throwable(throwable)
.domain(domain)
.domain(domain)
.reference(Reference.organization(graviteeContext.getOrganizationId()))));
})
.onErrorResumeNext(ex -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,24 @@
package io.gravitee.am.service.model;

import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

/**
* @author David BRASSELY (david.brassely at graviteesource.com)
* @author GraviteeSource Team
*/
@Getter
@Setter
public class NewDomain {

@NotNull
private String name;

private String description;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
@NotNull
private String dataPlaneId;

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const createDomain = (accessToken, name, description): Promise<Domain> =>
newDomain: {
name: name,
description: description,
dataPlaneId: "default"
},
});

Expand Down
2 changes: 2 additions & 0 deletions gravitee-am-test/api/management/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apis/AuditApi.ts
apis/AuthenticationDeviceNotifierApi.ts
apis/BotDetectionApi.ts
apis/CertificateApi.ts
apis/DataPlaneApi.ts
apis/DefaultApi.ts
apis/DeviceIdentifierApi.ts
apis/DeviceIdentifiersApi.ts
Expand Down Expand Up @@ -81,6 +82,7 @@ models/ClientSecret.ts
models/CookieSettings.ts
models/CorsSettings.ts
models/Credential.ts
models/DataPlane.ts
models/DeviceIdentifier.ts
models/Domain.ts
models/DomainUserBulkRequest.ts
Expand Down
90 changes: 90 additions & 0 deletions gravitee-am-test/api/management/apis/DataPlaneApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* 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.
*/
/* Gravitee.io - Access Management API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/* tslint:disable */
/* eslint-disable */

import * as runtime from '../runtime';
import {
DataPlane,
DataPlaneFromJSON,
DataPlaneToJSON,
} from '../models';

export interface ListDataPlanesRequest {
organizationId: string;
environmentId: string;
}

/**
*
*/
export class DataPlaneApi extends runtime.BaseAPI {

/**
* List all the data planes accessible to the current user. User must have DOMAIN[CREATE] permission on the specified environment or organization
* List of data planes
*/
async listDataPlanesRaw(requestParameters: ListDataPlanesRequest, initOverrides?: RequestInit | runtime.InitOverideFunction): Promise<runtime.ApiResponse<Array<DataPlane>>> {
if (requestParameters.organizationId === null || requestParameters.organizationId === undefined) {
throw new runtime.RequiredError('organizationId','Required parameter requestParameters.organizationId was null or undefined when calling listDataPlanes.');
}

if (requestParameters.environmentId === null || requestParameters.environmentId === undefined) {
throw new runtime.RequiredError('environmentId','Required parameter requestParameters.environmentId was null or undefined when calling listDataPlanes.');
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

if (this.configuration && this.configuration.accessToken) {
const token = this.configuration.accessToken;
const tokenString = await token("gravitee-auth", []);

if (tokenString) {
headerParameters["Authorization"] = `Bearer ${tokenString}`;
}
}
const response = await this.request({
path: `/organizations/{organizationId}/environments/{environmentId}/data-planes`.replace(`{${"organizationId"}}`, encodeURIComponent(String(requestParameters.organizationId))).replace(`{${"environmentId"}}`, encodeURIComponent(String(requestParameters.environmentId))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(DataPlaneFromJSON));
}

/**
* List all the data planes accessible to the current user. User must have DOMAIN[CREATE] permission on the specified environment or organization
* List of data planes
*/
async listDataPlanes(requestParameters: ListDataPlanesRequest, initOverrides?: RequestInit | runtime.InitOverideFunction): Promise<Array<DataPlane>> {
const response = await this.listDataPlanesRaw(requestParameters, initOverrides);
return await response.value();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ export interface ClientRegistrationSettings {
* @type {boolean}
* @memberof ClientRegistrationSettings
*/
dynamicClientRegistrationEnabled?: boolean;
clientTemplateEnabled?: boolean;
/**
*
* @type {boolean}
* @memberof ClientRegistrationSettings
*/
openDynamicClientRegistrationEnabled?: boolean;
allowedScopesEnabled?: boolean;
/**
*
* @type {boolean}
* @memberof ClientRegistrationSettings
*/
clientTemplateEnabled?: boolean;
dynamicClientRegistrationEnabled?: boolean;
/**
*
* @type {boolean}
* @memberof ClientRegistrationSettings
*/
allowedScopesEnabled?: boolean;
openDynamicClientRegistrationEnabled?: boolean;
}

export function ClientRegistrationSettingsFromJSON(json: any): ClientRegistrationSettings {
Expand All @@ -103,10 +103,10 @@ export function ClientRegistrationSettingsFromJSONTyped(json: any, ignoreDiscrim
'allowWildCardRedirectUri': !exists(json, 'allowWildCardRedirectUri') ? undefined : json['allowWildCardRedirectUri'],
'defaultScopes': !exists(json, 'defaultScopes') ? undefined : json['defaultScopes'],
'allowedScopes': !exists(json, 'allowedScopes') ? undefined : json['allowedScopes'],
'dynamicClientRegistrationEnabled': !exists(json, 'dynamicClientRegistrationEnabled') ? undefined : json['dynamicClientRegistrationEnabled'],
'openDynamicClientRegistrationEnabled': !exists(json, 'openDynamicClientRegistrationEnabled') ? undefined : json['openDynamicClientRegistrationEnabled'],
'clientTemplateEnabled': !exists(json, 'clientTemplateEnabled') ? undefined : json['clientTemplateEnabled'],
'allowedScopesEnabled': !exists(json, 'allowedScopesEnabled') ? undefined : json['allowedScopesEnabled'],
'dynamicClientRegistrationEnabled': !exists(json, 'dynamicClientRegistrationEnabled') ? undefined : json['dynamicClientRegistrationEnabled'],
'openDynamicClientRegistrationEnabled': !exists(json, 'openDynamicClientRegistrationEnabled') ? undefined : json['openDynamicClientRegistrationEnabled'],
};
}

Expand All @@ -124,10 +124,10 @@ export function ClientRegistrationSettingsToJSON(value?: ClientRegistrationSetti
'allowWildCardRedirectUri': value.allowWildCardRedirectUri,
'defaultScopes': value.defaultScopes,
'allowedScopes': value.allowedScopes,
'dynamicClientRegistrationEnabled': value.dynamicClientRegistrationEnabled,
'openDynamicClientRegistrationEnabled': value.openDynamicClientRegistrationEnabled,
'clientTemplateEnabled': value.clientTemplateEnabled,
'allowedScopesEnabled': value.allowedScopesEnabled,
'dynamicClientRegistrationEnabled': value.dynamicClientRegistrationEnabled,
'openDynamicClientRegistrationEnabled': value.openDynamicClientRegistrationEnabled,
};
}

Loading

0 comments on commit 1e0efd4

Please sign in to comment.