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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@

**/target
**/pom.xml.versionsBackup

src/it/deploy-function-it/build.log
23 changes: 20 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.10.1
* Latest snapshot version 0.11.0-SNAPSHOT
* Latest released version 0.11.0
* Latest snapshot version 0.12.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.10.1</poly.version>
<poly.version>0.11.0</poly.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -243,6 +243,23 @@ Here's the list of parameters:
- **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.

#### create-server-variable
This MOJO doesn't require a project to run.

Creates a Poly server variable. Available types are String or primitive types.

##### 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.
- **context (required):** Context of the variable to add.
- **name (required):** The name of the variable to add.
- **value (required):** The content of the variable to add.
- **description:** The description of the variable being added. If not set, it will be automatically generated.
- **secret:** Whether or not the variable contents will be revealed.
- **type:** The type of the variable being set. This field is case insensitive. Valid inputs are `string`, `java.lang.String`, `integer`, `int`, `java.lang.Integer`, `double`, `java.lang.Double`, `long`, `java.lang.Long`, `float`, `java.lang.Float`, `byte`, `java.lang.Byte`, `short`, `java.lang.Short`, `boolean`, `java.lang.Boolean`. The content of the `value` field will be cast to this type before upload. If not set, the type will be auto-detected from the `value` content.

<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.11.1-SNAPSHOT</version>
<version>0.12.0-SNAPSHOT</version>
<relativePath>../parent-pom</relativePath>
</parent>

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.11.1-SNAPSHOT</version>
<version>0.12.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.11.1-SNAPSHOT</version>
<version>0.12.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.11.1-SNAPSHOT</version>
<version>0.12.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,18 @@
package io.polyapi.plugin.model;

import io.polyapi.commons.api.model.PolyObject;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Setter
@Getter
@ToString
public class ServerVariable implements PolyObject {
private String id;
private String name;
private String description;
private Object value;
private boolean secret;
private String context;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.polyapi.plugin.mojo;

import io.polyapi.plugin.model.ServerVariable;
import io.polyapi.plugin.service.ServerVariableService;
import io.polyapi.plugin.service.ServerVariableServiceImpl;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.util.Optional;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;

@Slf4j
@Setter
@Mojo(name = "create-server-variable", requiresProject = false)
public class createServerVariableMojo extends PolyApiMojo {
@Parameter(property = "name", required = true)
private String name;

@Parameter(property = "context", required = true)
private String context;

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

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

@Parameter(property = "value", required = true)
private String value;

@Parameter(property = "secret", defaultValue = "true")
private boolean secret;

@Override
protected void execute(String host, Integer port) {
log.info("Initiating creation of server variable.");
ServerVariableService serverVariableService = new ServerVariableServiceImpl(getHttpClient(), getJsonParser(), host, port);
Object usedValue = switch (Optional.ofNullable(type).orElse("").toLowerCase()) {
case "string", "java.lang.string" -> value;
case "byte", "java.lang.byte", "short", "java.lang.short", "integer", "java.lang.integer", "long", "java.lang.long" -> Long.valueOf(value);
case "float", "java.lang.float", "double", "java.lang.double" -> Double.valueOf(value);
case "boolean", "java.lang.boolean" -> Boolean.valueOf(value);
default -> {
if (value.equalsIgnoreCase(TRUE.toString()) || value.equalsIgnoreCase(FALSE.toString())) {
yield Boolean.valueOf(value);
}
if (NumberUtils.isParsable(value)) {
Double doubleValue = Double.valueOf(value);
if (doubleValue - doubleValue.longValue() == 0) {
yield doubleValue.longValue();
} else {
yield doubleValue;
}
}
yield value;
}
};
log.debug("Used type '{}'", value.getClass().getName());
ServerVariable serverVariable = serverVariableService.create(name, description, usedValue, secret, context);
log.info("Server variable '{}' created with ID '{}'.", serverVariable.getName(), serverVariable.getId());
log.info("Server variable creation complete.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.polyapi.plugin.service;

import io.polyapi.plugin.model.ServerVariable;

public interface ServerVariableService {

ServerVariable create(String name, String description, Object value, boolean secret, String context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.polyapi.plugin.service;

import io.polyapi.commons.api.http.HttpClient;
import io.polyapi.commons.api.json.JsonParser;
import io.polyapi.commons.api.service.PolyApiService;
import io.polyapi.plugin.model.ServerVariable;

public class ServerVariableServiceImpl extends PolyApiService implements ServerVariableService {

public ServerVariableServiceImpl(HttpClient client, JsonParser jsonParser, String host, Integer port) {
super(client, jsonParser, host, port);
}

@Override
public ServerVariable create(String name, String description, Object value, boolean secret, String context) {
ServerVariable serverVariable = new ServerVariable();
serverVariable.setName(name);
serverVariable.setDescription(description);
serverVariable.setValue(value);
serverVariable.setSecret(secret);
serverVariable.setContext(context);
return post("variables", serverVariable, ServerVariable.class);
}
}
2 changes: 1 addition & 1 deletion 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>polyapi-java</artifactId>
<version>0.11.1-SNAPSHOT</version>
<version>0.12.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>parent-pom</module>
Expand Down