Skip to content

Commit

Permalink
native api
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiiiel committed Nov 16, 2024
1 parent b04f5e4 commit 9ba739c
Show file tree
Hide file tree
Showing 17 changed files with 402 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ io.gravitee.rest.api.management.v2.rest.model.ApiV1 mapToV1(
@Mapping(target = "plans", qualifiedByName = "mapPlanCRD")
ApiCRDSpec map(io.gravitee.rest.api.management.v2.rest.model.ApiCRDSpec crd);

@Mapping(target = "plans", qualifiedByName = "mapPlanCRD")
@Mapping(target = "listeners", qualifiedByName = "toNativeListeners")
@Mapping(target = "metadata", ignore = true)
NativeApiCRDSpec map(io.gravitee.rest.api.management.v2.rest.model.NativeApiCRDSpec crd);

@Mapping(target = "source.configuration", qualifiedByName = "serializeConfiguration")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.gravitee.rest.api.management.v2.rest.model.CreatePlanV2;
import io.gravitee.rest.api.management.v2.rest.model.CreatePlanV4;
import io.gravitee.rest.api.management.v2.rest.model.FlowV4;
import io.gravitee.rest.api.management.v2.rest.model.NativePlanCRD;
import io.gravitee.rest.api.management.v2.rest.model.Plan;
import io.gravitee.rest.api.management.v2.rest.model.PlanCRD;
import io.gravitee.rest.api.management.v2.rest.model.PlanFederated;
Expand Down Expand Up @@ -154,6 +155,9 @@ default io.gravitee.apim.core.plan.model.Plan map(CreatePlanV4 source, Api api)
@Mapping(target = "security", qualifiedByName = "mapToPlanSecurityV4")
io.gravitee.apim.core.api.model.crd.PlanCRD fromPlanCRD(PlanCRD plan);

@Mapping(target = "security", qualifiedByName = "mapToPlanSecurityV4")
io.gravitee.apim.core.api.model.crd.NativePlanCRD fromPlanCRD(NativePlanCRD plan);

@Mapping(target = "security.configuration", qualifiedByName = "serializeConfiguration")
UpdatePlanEntity map(UpdatePlanV4 plan);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
package io.gravitee.rest.api.management.v2.rest.model;

import io.gravitee.definition.model.DefinitionContext;
import io.gravitee.definition.model.DefinitionVersion;
import io.gravitee.definition.model.ResponseTemplate;
import io.gravitee.definition.model.v4.flow.execution.FlowExecution;
import io.gravitee.definition.model.v4.service.ApiServices;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
Expand Down Expand Up @@ -66,7 +71,7 @@ public class NativeApiCRDSpec {

private List<@Valid Resource> resources = new ArrayList<>();

private Map<String, @Valid PlanCRD> plans = new HashMap<>();
private Map<String, @Valid NativePlanCRD> plans = new HashMap<>();

private FlowExecution flowExecution;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright © 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.rest.api.management.v2.rest.model;

import io.gravitee.definition.model.v4.nativeapi.NativeFlow;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.List;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class NativePlanCRD {

@NotNull
@NotEmpty
private String id;

private String crossId;

private String name;

private String description;

private PlanSecurity security;

private List<String> characteristics;

private List<String> excludedGroups;

private String generalConditions;

private int order;

private String selectionRule;

@NotNull
private PlanStatus status;

private List<String> tags;

@NotNull
private PlanType type;

private PlanValidation validation;

private List<NativeFlow> flows;

@NotNull
private PlanMode mode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public Response createApiWithCRD(@Valid ApiCRDSpec crd, @QueryParam("dryRun") bo
}

@PUT
@Path("/_import/native/crd")
@Path("/_import/native-crd")
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_API, acls = RolePermissionAction.CREATE) })
public Response createNativeApiWithCRD(@Valid NativeApiCRDSpec crd, @QueryParam("dryRun") boolean dryRun) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Copyright © 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.rest.api.model.v4.nativeapi;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.gravitee.common.component.Lifecycle;
import io.gravitee.definition.model.DefinitionVersion;
import io.gravitee.definition.model.v4.ApiType;
import io.gravitee.definition.model.v4.nativeapi.NativeApiServices;
import io.gravitee.definition.model.v4.nativeapi.NativeEndpointGroup;
import io.gravitee.definition.model.v4.nativeapi.NativeFlow;
import io.gravitee.definition.model.v4.nativeapi.NativeListener;
import io.gravitee.definition.model.v4.property.Property;
import io.gravitee.definition.model.v4.resource.Resource;
import io.gravitee.rest.api.model.DeploymentRequired;
import io.gravitee.rest.api.model.PrimaryOwnerEntity;
import io.gravitee.rest.api.model.Visibility;
import io.gravitee.rest.api.model.WorkflowState;
import io.gravitee.rest.api.model.api.ApiLifecycleState;
import io.gravitee.rest.api.model.context.OriginContext;
import io.gravitee.rest.api.model.v4.api.GenericApiEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.With;

/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
@EqualsAndHashCode
@Schema(name = "UpdateNativeApiEntityV4")
@Builder(toBuilder = true)
@With
public class UpdateNativeApiEntity {

@Schema(description = "API's uuid.", example = "00f8c9e7-78fc-4907-b8c9-e778fc790750")
private String id;

@Schema(description = "API's crossId. Identifies API across environments.", example = "df83b2a4-cc3e-3f80-9f0d-c138c106c076")
private String crossId;

@Schema(description = "API's name. Duplicate names can exists.", example = "My Api")
private String name;

@Schema(description = "Api's version. It's a simple string only used in the portal.", example = "v1.0")
private String apiVersion;

@Schema(description = "API's gravitee definition version")
private DefinitionVersion definitionVersion;

@Schema(
description = "API's description. A short description of your API.",
example = "I can use a hundred characters to describe this API."
)
private String description;

@Schema(description = "The list of sharding tags associated with this API.", example = "public, private")
@DeploymentRequired
@Builder.Default
private Set<String> tags = new HashSet<>();

@Schema(description = "A list of listeners used to describe our you api could be reached.")
@DeploymentRequired
private List<NativeListener> listeners;

@Schema(description = "A list of endpoint describing the endpoints to contact.")
@DeploymentRequired
private List<NativeEndpointGroup> endpointGroups;

@Schema(description = "A dictionary (could be dynamic) of properties available in the API context.")
@DeploymentRequired
@Builder.Default
private List<Property> properties = new ArrayList<>();

@Schema(description = "The list of API resources used by policies like cache resources or oauth2")
@DeploymentRequired
@Builder.Default
private List<Resource> resources = new ArrayList<>();

@Schema(description = "A list of plans to apply on the API")
@DeploymentRequired
@Builder.Default
private Set<NativePlanEntity> plans = new HashSet<>();

@Schema(description = "A list of flows containing the policies configuration.")
@DeploymentRequired
private List<NativeFlow> flows;

@DeploymentRequired
@Schema(description = "The configuration of API services like the dynamic properties.")
private NativeApiServices services;

@Schema(description = "API's groups. Used to add team in your API.", example = "['MY_GROUP1', 'MY_GROUP2']")
private Set<String> groups;

@Schema(description = "The visibility of the API regarding the portal.", example = "PUBLIC")
private Visibility visibility;

@Schema(description = "The user with role PRIMARY_OWNER on this API.")
private PrimaryOwnerEntity primaryOwner;

@Schema(description = "the API logo encoded in base64")
private String picture;

@Schema(
description = "the API logo URL.",
example = "https://gravitee.mycompany.com/management/apis/6c530064-0b2c-4004-9300-640b2ce0047b/picture"
)
private String pictureUrl;

@Schema(description = "the list of categories associated with this API", example = "Product, Customer, Misc")
private Set<String> categories;

@Schema(description = "the free list of labels associated with this API", example = "json, read_only, awesome")
private List<String> labels;

/** Context explaining where the API comes from. */
@Builder.Default
private OriginContext originContext = new OriginContext.Management();

@JsonIgnore
@Builder.Default
private Map<String, Object> metadata = new HashMap<>();

private ApiLifecycleState lifecycleState;

private WorkflowState workflowState;

private boolean disableMembershipNotifications;

@Schema(description = "the API background encoded in base64")
private String background;

@Schema(
description = "the API background url.",
example = "https://gravitee.mycompany.com/management/apis/6c530064-0b2c-4004-9300-640b2ce0047b/background"
)
private String backgroundUrl;

@JsonIgnore
private String referenceType;

@JsonIgnore
private String referenceId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import io.gravitee.apim.core.member.model.MembershipReferenceType;
import io.gravitee.apim.core.resource.domain_service.ValidateResourceDomainService;
import io.gravitee.apim.core.validation.Validator;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import lombok.RequiredArgsConstructor;

/**
* @author Antoine CORDIER (antoine.cordier at graviteesource.com)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
import io.gravitee.definition.model.v4.property.Property;
import io.gravitee.definition.model.v4.resource.Resource;
import io.gravitee.rest.api.model.context.OriginContext;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* @author Antoine CORDIER (antoine.cordier at graviteesource.com)
Expand Down Expand Up @@ -81,8 +81,8 @@ public class NativeApiCRDSpec {
private Set<String> labels;

private List<Resource> resources;
private Map<String, NativePlanCRD> plans;

private Map<String, PlanCRD> plans;

private List<Property> properties;

Expand Down Expand Up @@ -158,5 +158,4 @@ public Api.ApiBuilder toApiBuilder() {
.tags(tags)
.type(ApiType.valueOf(type));
}

}
Loading

0 comments on commit 9ba739c

Please sign in to comment.