Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release

on:
push:
branches:
- 'main'

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
server-id: github
settings-path: ${{ github.workspace }}

- uses: s4u/maven-settings-action@v3.0.0
with:
servers: '[{"id": "ossrh", "username": "${{ secrets.DISTRIBUTION_REPOSITORY_RELEASE_USERNAME }}", "password": "${{ secrets.DISTRIBUTION_REPOSITORY_RELEASE_PASSWORD }}"}]'
- name: Release to production
run: mvn clean release:clean release:prepare release:perform -B -DaltDeploymentRepository=ossrh::https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/

- name: Delete sample post-production verification function
run: mvn clean polyapi:delete-function -Dcontext=io.polyapi.deploy.verification -Dname=verification-function

- name: Deploy sample post-production verification function
run: mvn polyapi:deploy-functions // Complete this

- name: Generate sources for sample post-production verification function
run: mvn clean compile // Fix this

- name: Execute post-production verification function
run: mvn clean verify
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Java Client Library (beta)

* Latest released version 0.9.3
* Latest snapshot version 0.10.0-SNAPSHOT
* Latest released version 0.10.1
* Latest snapshot version 0.11.0-SNAPSHOT

## Introduction
Welcome my friends! This is the Poly API Java client GitHub page. If you are here, then it means you're familiar with what we do at Poly. If you aren't, you can always check [here](https://github.com/polyapi/poly-alpha).
Expand Down Expand Up @@ -55,7 +55,7 @@ Nice to have some customers looking around here! So, you'll need to run the foll
2. **Update the project.** Add the following to your project's `pom.xml`:
```xml
<properties>
<poly.version>0.9.3</poly.version>
<poly.version>0.10.1</poly.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -227,6 +227,22 @@ Here's the list of parameters:
- **functions:** Comma separated value containing the names of the functions to deploy. The functions must be annotated with the `@PolyFunction` annotation as it is described. This parameter triggers a filter by function name and/or context + function name in the `[context].[functionName]` format. Each comma separated value will be taken independently and deployed.
- **dry-run:** Flag that when added makes the MOJO prepare everything for a deployment but not do it. This is for debugging purposes.

#### delete-function
This MOJO doesn't require a project to run.

It deletes a server/client/api/auth function, webhook or variable from the Poly server. It can take 2 types of inputs:
- **id**: Deletes the entity with the matching ID.
- **contxt/function name**: Deletes the entity that matches the context and function name. It's case insensitive, but will fall back to be case sensitive in case that there are 2 or more matches with different cases. If none of those cases match exactly, it will throw an error.

##### Parameters
Here's the list of parameters:
- **host (required):** The host where the Poly API instance is hosted.
- **port:** The port that the Poly API instance is listening to. Default value is 443.
- **apiKey (required):** The API key required to authenticate to Poly.
- **id:** ID of the entity to delete. Cannot coexist with either `functionName` nor `context` arguments.
- **functionName:** Name of the function to delete. Cannot coexist with `id` argument. Mandatory unless `id` is set.
- **context:** Context of the function to delete. Cannot coexist with `id` argument. Mandatory unless `id` is set.

<a name="project-usage"></a>
## Usage

Expand Down
2 changes: 1 addition & 1 deletion commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.polyapi</groupId>
<artifactId>parent-pom</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.11.0-SNAPSHOT</version>
<relativePath>../parent-pom</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public <I> void patch(String relativePath, Map<String, List<String>> headers, Ma
parsedCall(PATCH, relativePath, headers, queryParams, body, Void.TYPE);
}

public void delete(String relativePath) {
delete(relativePath, new HashMap<>(), new HashMap<>(), null);
}


public <I> void delete(String relativePath, Map<String, List<String>> headers, Map<String, List<String>> queryParams, I body) {
parsedCall(DELETE, relativePath, headers, queryParams, body, Void.TYPE);
}

private <I, O> O parsedCall(HttpMethod method, String relativePath, Map<String, List<String>> headers, Map<String, List<String>> queryParams, I body, Type expectedResponseType) {
Map<String, List<String>> allHeaders = new HashMap<>();
allHeaders.put("Accept", List.of("application/json"));
Expand Down
2 changes: 1 addition & 1 deletion library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.polyapi</groupId>
<artifactId>parent-pom</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.11.0-SNAPSHOT</version>
<relativePath>../parent-pom</relativePath>
</parent>
<artifactId>library</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion parent-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.polyapi</groupId>
<artifactId>parent-pom</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.11.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Poly API Java parent POM</name>
<url>https://polyapi.io</url>
Expand Down
2 changes: 1 addition & 1 deletion polyapi-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.polyapi</groupId>
<artifactId>parent-pom</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>0.11.0-SNAPSHOT</version>
<relativePath>../parent-pom</relativePath>
</parent>
<artifactId>polyapi-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.polyapi.plugin.error.function;

import io.polyapi.plugin.error.PolyApiMavenPluginException;

import java.util.List;

import static java.lang.String.format;
import static java.lang.String.join;

public class UnclearFunctionReferenceException extends PolyApiMavenPluginException {

public UnclearFunctionReferenceException(String expectedReference, List<String> retrievedReferences) {
super(format("Unclear function reference. Expected '%s', but found '%s'. Please retry with a specific case sensitive one.", expectedReference, join(", ", retrievedReferences)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.polyapi.plugin.error.validation;

import static java.lang.String.format;

public class BadExclusionException extends ValidationException {
public BadExclusionException(String propertyName, String excludedPropertyName) {
super(propertyName, format("Property '%s' cannot be set at the same time as property '%s'.", "%s", excludedPropertyName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.polyapi.plugin.error.validation;

import static java.lang.String.format;

public class InvalidUUIDException extends ValidationException {
public InvalidUUIDException(String propertyName, String propertyValue, Throwable cause) {
super(propertyName, format("Property '%s' with value '%s' doesn't match UUID format.", propertyName, propertyValue), cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import io.polyapi.plugin.model.specification.function.ApiFunctionSpecification;
import io.polyapi.plugin.model.specification.function.AuthFunctionSpecification;
import io.polyapi.plugin.model.specification.function.CustomFunctionSpecification;
import io.polyapi.plugin.model.specification.function.ClientFunctionSpecification;
import io.polyapi.plugin.model.specification.function.ServerFunctionSpecification;
import io.polyapi.plugin.model.specification.variable.ServerVariableSpecification;
import io.polyapi.plugin.model.specification.webhook.WebhookHandleSpecification;
Expand All @@ -32,7 +32,7 @@
)
@JsonSubTypes({
@JsonSubTypes.Type(value = ApiFunctionSpecification.class, name = "apiFunction"),
@JsonSubTypes.Type(value = CustomFunctionSpecification.class, name = "customFunction"),
@JsonSubTypes.Type(value = ClientFunctionSpecification.class, name = "customFunction"),
@JsonSubTypes.Type(value = ServerFunctionSpecification.class, name = "serverFunction"),
@JsonSubTypes.Type(value = AuthFunctionSpecification.class, name = "authFunction"),
@JsonSubTypes.Type(value = WebhookHandleSpecification.class, name = "webhookHandle"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

@Getter
@Setter
public class CustomFunctionSpecification extends FunctionSpecification {
public class ClientFunctionSpecification extends FunctionSpecification {
private String[] requirements;
private String code;
private String language;

@Override
protected String getSpecificationSubtype() {
return "custom";
return "client";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ default void visit(ServerFunctionSpecification specification) {
visit((FunctionSpecification) specification);
}

default void visit(CustomFunctionSpecification specification) {
default void visit(ClientFunctionSpecification specification) {
log.trace("Visiting CustomFunctionSpecification.");
visit((FunctionSpecification) specification);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.polyapi.plugin.mojo;

import io.polyapi.plugin.error.validation.BadExclusionException;
import io.polyapi.plugin.service.PolyFunctionService;
import io.polyapi.plugin.service.PolyFunctionServiceImpl;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.util.Optional;

import static io.polyapi.plugin.mojo.validation.Validator.validateNotEmpty;
import static io.polyapi.plugin.mojo.validation.Validator.validateUUIDFormat;
import static org.apache.commons.lang.StringUtils.isNotBlank;

@Slf4j
@Setter
@Mojo(name = "delete-function", requiresProject = false)
public class DeleteFunctionMojo extends PolyApiMojo {
@Parameter(property = "functionName")
private String functionName;

@Parameter(property = "context")
private String context;

@Parameter(property = "id")
private String id;


@Override
protected void execute(String host, Integer port) {
log.info("Initiating deletion of Poly function.");
PolyFunctionService service = new PolyFunctionServiceImpl(getHttpClient(), getJsonParser(), host, port);
Optional.ofNullable(id)
.ifPresentOrElse(functionId -> {
if (isNotBlank(functionName)) {
throw new BadExclusionException("id", "functionName");
}
if (isNotBlank(context)) {
throw new BadExclusionException("id", "context");
}
validateUUIDFormat("id", functionId);
service.delete(functionId);
},
() -> {
validateNotEmpty("functionName", functionName);
validateNotEmpty("context", context);
service.delete(context, functionName);
});
log.info("Poly function deletion complete.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import io.polyapi.plugin.error.validation.InexistentFileException;
import io.polyapi.plugin.error.validation.InvalidPortNumberException;
import io.polyapi.plugin.error.validation.InvalidPropertyException;
import io.polyapi.plugin.error.validation.InvalidUUIDException;
import io.polyapi.plugin.error.validation.NullOrEmptyValueException;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.Optional;
import java.util.UUID;

import static java.util.function.Predicate.not;

Expand Down Expand Up @@ -54,4 +57,14 @@ public static void validatePortFormat(String propertyName, String property) {
throw new InvalidPortNumberException(propertyName, property, e);
}
}

public static void validateUUIDFormat(String propertyName, String property) {
try {
log.debug("Validating that property '{}' has a valid key format.", propertyName);
validateNotEmpty(propertyName, property);
UUID.fromString(property);
} catch (IllegalArgumentException e) {
throw new InvalidUUIDException(propertyName, property, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.lang.model.SourceVersion;

import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void getPropertyFromPlugin(String propertyName, String currentValue, Cons

public String getPropertyFromPlugin(String pluginGroupId, String pluginArtifactId, String propertyName) {
log.debug("Scanning plugins.");
List<Plugin> plugins = project.getBuild().getPlugins();
List<Plugin> plugins = Optional.ofNullable(project).map(MavenProject::getBuild).map(Build::getPlugins).orElseGet(ArrayList::new);
log.debug("Found {} plugins. Filtering by group ID matching '{}' and artifact ID matching '{}'.", plugins.size(), pluginGroupId, pluginArtifactId);
return plugins.stream()
.filter(plugin -> pluginGroupId.equals(plugin.getGroupId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
public interface PolyFunctionService {

PolyFunction deploy(String type, PolyFunction polyFunction);

void delete(String context, String name);

void delete(String id);
}
Loading