From e5348e3304c6c27361229bb0625dbb8e050e6e2c Mon Sep 17 00:00:00 2001 From: Richard Kosegi Date: Sun, 13 Nov 2022 12:52:05 +0100 Subject: [PATCH 1/2] Bump lombok version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4621437..c70d228 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,7 @@ org.projectlombok lombok - 1.18.20 + 1.18.24 com.google.guava From 5f85b34bdde180da4a02d7b9e7dd167c798cfa64 Mon Sep 17 00:00:00 2001 From: Richard Kosegi Date: Sun, 13 Nov 2022 13:12:34 +0100 Subject: [PATCH 2/2] Hetzner Cloud API client has moved New project location is https://github.com/dNationCloud/hetzner-cloud-client-java --- pom.xml | 27 +-- .../hetzner/ConfigurationValidator.java | 18 +- .../hetzner/HetznerCloudResourceManager.java | 34 +-- .../plugins/hetzner/HetznerServerInfo.java | 4 +- .../plugins/hetzner/OrphanedNodesCleaner.java | 2 +- .../client/AbstractSearchResponse.java | 23 --- .../plugins/hetzner/client/ActionDetail.java | 27 --- .../hetzner/client/ActionResponse.java | 23 --- .../client/AuthenticationInterceptor.java | 43 ---- .../plugins/hetzner/client/ClientFactory.java | 69 ------- .../hetzner/client/CreateServerRequest.java | 42 ---- .../hetzner/client/CreateServerResponse.java | 29 --- .../hetzner/client/CreateSshKeyRequest.java | 31 --- .../hetzner/client/CreateSshKeyResponse.java | 25 --- .../hetzner/client/DatacenterDetail.java | 27 --- .../plugins/hetzner/client/ErrorDetail.java | 24 --- .../client/GetAllPrimaryIpsResponse.java | 34 --- .../client/GetDatacentersResponse.java | 27 --- .../hetzner/client/GetImageByIdResponse.java | 24 --- .../client/GetImagesBySelectorResponse.java | 31 --- .../hetzner/client/GetLocationsResponse.java | 27 --- .../client/GetNetworkByIdResponse.java | 23 --- .../client/GetNetworksBySelectorResponse.java | 27 --- .../hetzner/client/GetServerByIdResponse.java | 23 --- .../client/GetServerTypesResponse.java | 29 --- .../client/GetServersBySelectorResponse.java | 29 --- .../client/GetSshKeysBySelectorResponse.java | 27 --- .../plugins/hetzner/client/HetznerApi.java | 193 ------------------ .../hetzner/client/IdentifiableResource.java | 23 --- .../plugins/hetzner/client/ImageDetail.java | 28 --- .../plugins/hetzner/client/Ipv4Detail.java | 27 --- .../hetzner/client/LocationDetail.java | 28 --- .../jenkins/plugins/hetzner/client/Meta.java | 25 --- .../plugins/hetzner/client/NetworkDetail.java | 28 --- .../plugins/hetzner/client/Pagination.java | 35 ---- .../hetzner/client/PrimaryIpDetail.java | 72 ------- .../hetzner/client/PrivateNetDetail.java | 26 --- .../hetzner/client/PublicNetDetail.java | 23 --- .../hetzner/client/PublicNetRequest.java | 44 ---- .../plugins/hetzner/client/ServerDetail.java | 60 ------ .../plugins/hetzner/client/ServerType.java | 29 --- .../plugins/hetzner/client/SshKeyDetail.java | 33 --- .../hetzner/client/UserAgentInterceptor.java | 39 ---- .../launcher/AbstractConnectionMethod.java | 2 +- .../launcher/DefaultConnectionMethod.java | 2 +- .../HetznerServerComputerLauncher.java | 2 +- .../hetzner/launcher/PublicAddressOnly.java | 2 +- .../primaryip/AbstractByLabelSelector.java | 8 +- .../primaryip/AbstractPrimaryIpStrategy.java | 4 +- .../hetzner/primaryip/DefaultStrategy.java | 4 +- .../hetzner/client/HetznerApiTest.java | 105 ---------- .../primaryip/PrimaryIpStrategyTest.java | 8 +- .../resources/get-network-by-id-invalid.json | 7 - src/test/resources/get-network-by-id.json | 7 - .../get-networks-by-selector-empty.json | 13 -- .../resources/get-networks-by-selector.json | 19 -- .../get-primary-ips-by-selector.json | 123 ----------- 57 files changed, 48 insertions(+), 1720 deletions(-) delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/AbstractSearchResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ActionDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ActionResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/AuthenticationInterceptor.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ClientFactory.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateServerRequest.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateServerResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateSshKeyRequest.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateSshKeyResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/DatacenterDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ErrorDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetAllPrimaryIpsResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetDatacentersResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetImageByIdResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetImagesBySelectorResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetLocationsResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetNetworkByIdResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetNetworksBySelectorResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServerByIdResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServerTypesResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServersBySelectorResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetSshKeysBySelectorResponse.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/HetznerApi.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/IdentifiableResource.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ImageDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Ipv4Detail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/LocationDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Meta.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/NetworkDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Pagination.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PrimaryIpDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PrivateNetDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PublicNetDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PublicNetRequest.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ServerDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ServerType.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/SshKeyDetail.java delete mode 100644 src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/UserAgentInterceptor.java delete mode 100644 src/test/java/cloud/dnation/jenkins/plugins/hetzner/client/HetznerApiTest.java delete mode 100644 src/test/resources/get-network-by-id-invalid.json delete mode 100644 src/test/resources/get-network-by-id.json delete mode 100644 src/test/resources/get-networks-by-selector-empty.json delete mode 100644 src/test/resources/get-networks-by-selector.json delete mode 100644 src/test/resources/get-primary-ips-by-selector.json diff --git a/pom.xml b/pom.xml index c70d228..713f966 100644 --- a/pom.xml +++ b/pom.xml @@ -120,24 +120,9 @@ guava - com.squareup.retrofit2 - retrofit - 2.9.0 - - - com.squareup.retrofit2 - converter-gson - 2.9.0 - - - com.squareup.okhttp3 - logging-interceptor - 3.14.9 - - - com.google.code.gson - gson - 2.8.9 + cloud.dnation.integration + hetzner-cloud-client-java + 1.1.0 org.jenkins-ci.plugins @@ -164,12 +149,6 @@ - - com.squareup.okhttp3 - mockwebserver - 3.14.9 - test - io.jenkins.configuration-as-code test-harness diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/ConfigurationValidator.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/ConfigurationValidator.java index e4b3b32..309119e 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/ConfigurationValidator.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/ConfigurationValidator.java @@ -15,15 +15,15 @@ */ package cloud.dnation.jenkins.plugins.hetzner; -import cloud.dnation.jenkins.plugins.hetzner.client.ClientFactory; -import cloud.dnation.jenkins.plugins.hetzner.client.GetDatacentersResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetImageByIdResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetImagesBySelectorResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetLocationsResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetNetworkByIdResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetNetworksBySelectorResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetServerTypesResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.HetznerApi; +import cloud.dnation.hetznerclient.ClientFactory; +import cloud.dnation.hetznerclient.GetDatacentersResponse; +import cloud.dnation.hetznerclient.GetImageByIdResponse; +import cloud.dnation.hetznerclient.GetImagesBySelectorResponse; +import cloud.dnation.hetznerclient.GetLocationsResponse; +import cloud.dnation.hetznerclient.GetNetworkByIdResponse; +import cloud.dnation.hetznerclient.GetNetworksBySelectorResponse; +import cloud.dnation.hetznerclient.GetServerTypesResponse; +import cloud.dnation.hetznerclient.HetznerApi; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.base.Throwables; diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/HetznerCloudResourceManager.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/HetznerCloudResourceManager.java index 0b65e06..dacba73 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/HetznerCloudResourceManager.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/HetznerCloudResourceManager.java @@ -15,23 +15,23 @@ */ package cloud.dnation.jenkins.plugins.hetzner; -import cloud.dnation.jenkins.plugins.hetzner.client.AbstractSearchResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.ClientFactory; -import cloud.dnation.jenkins.plugins.hetzner.client.CreateServerRequest; -import cloud.dnation.jenkins.plugins.hetzner.client.CreateServerResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.CreateSshKeyRequest; -import cloud.dnation.jenkins.plugins.hetzner.client.CreateSshKeyResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetImagesBySelectorResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetNetworksBySelectorResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetServerByIdResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetServersBySelectorResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.GetSshKeysBySelectorResponse; -import cloud.dnation.jenkins.plugins.hetzner.client.HetznerApi; -import cloud.dnation.jenkins.plugins.hetzner.client.IdentifiableResource; -import cloud.dnation.jenkins.plugins.hetzner.client.Meta; -import cloud.dnation.jenkins.plugins.hetzner.client.PublicNetRequest; -import cloud.dnation.jenkins.plugins.hetzner.client.ServerDetail; -import cloud.dnation.jenkins.plugins.hetzner.client.SshKeyDetail; +import cloud.dnation.hetznerclient.AbstractSearchResponse; +import cloud.dnation.hetznerclient.ClientFactory; +import cloud.dnation.hetznerclient.CreateServerRequest; +import cloud.dnation.hetznerclient.CreateServerResponse; +import cloud.dnation.hetznerclient.CreateSshKeyRequest; +import cloud.dnation.hetznerclient.CreateSshKeyResponse; +import cloud.dnation.hetznerclient.GetImagesBySelectorResponse; +import cloud.dnation.hetznerclient.GetNetworksBySelectorResponse; +import cloud.dnation.hetznerclient.GetServerByIdResponse; +import cloud.dnation.hetznerclient.GetServersBySelectorResponse; +import cloud.dnation.hetznerclient.GetSshKeysBySelectorResponse; +import cloud.dnation.hetznerclient.HetznerApi; +import cloud.dnation.hetznerclient.IdentifiableResource; +import cloud.dnation.hetznerclient.Meta; +import cloud.dnation.hetznerclient.PublicNetRequest; +import cloud.dnation.hetznerclient.ServerDetail; +import cloud.dnation.hetznerclient.SshKeyDetail; import cloud.dnation.jenkins.plugins.hetzner.connect.ConnectivityType; import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey; import com.google.common.annotations.VisibleForTesting; diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/HetznerServerInfo.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/HetznerServerInfo.java index 262839c..7910d38 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/HetznerServerInfo.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/HetznerServerInfo.java @@ -15,8 +15,8 @@ */ package cloud.dnation.jenkins.plugins.hetzner; -import cloud.dnation.jenkins.plugins.hetzner.client.ServerDetail; -import cloud.dnation.jenkins.plugins.hetzner.client.SshKeyDetail; +import cloud.dnation.hetznerclient.ServerDetail; +import cloud.dnation.hetznerclient.SshKeyDetail; import lombok.Data; @Data diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/OrphanedNodesCleaner.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/OrphanedNodesCleaner.java index d7c2321..2888266 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/OrphanedNodesCleaner.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/OrphanedNodesCleaner.java @@ -15,7 +15,7 @@ */ package cloud.dnation.jenkins.plugins.hetzner; -import cloud.dnation.jenkins.plugins.hetzner.client.ServerDetail; +import cloud.dnation.hetznerclient.ServerDetail; import hudson.Extension; import hudson.model.PeriodicWork; import jenkins.model.Jenkins; diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/AbstractSearchResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/AbstractSearchResponse.java deleted file mode 100644 index 0e8d7ba..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/AbstractSearchResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; - -@Data -public abstract class AbstractSearchResponse { - protected Meta meta; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ActionDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ActionDetail.java deleted file mode 100644 index 8f41a3d..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ActionDetail.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class ActionDetail extends IdentifiableResource { - private String command; - private String status; - private ErrorDetail error; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ActionResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ActionResponse.java deleted file mode 100644 index 1a5ab18..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ActionResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; - -@Data -public class ActionResponse { - private ActionDetail action; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/AuthenticationInterceptor.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/AuthenticationInterceptor.java deleted file mode 100644 index f8d4b64..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/AuthenticationInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.common.net.HttpHeaders; -import lombok.NonNull; -import okhttp3.Interceptor; -import okhttp3.Response; - -import java.io.IOException; - -/** - * {@link Interceptor} which injects Authorization header. - */ -class AuthenticationInterceptor implements Interceptor { - private final String token; - - AuthenticationInterceptor(String token) { - this.token = token; - } - - @Override - @NonNull - public Response intercept(Chain chain) throws IOException { - //noinspection UnstableApiUsage - return chain.proceed(chain.request().newBuilder() - .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) - .build()); - } -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ClientFactory.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ClientFactory.java deleted file mode 100644 index 8b15012..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ClientFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import cloud.dnation.jenkins.plugins.hetzner.HetznerConstants; -import com.google.common.net.HttpHeaders; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import lombok.extern.slf4j.Slf4j; -import okhttp3.ConnectionPool; -import okhttp3.OkHttpClient; -import okhttp3.logging.HttpLoggingInterceptor; -import retrofit2.Retrofit; -import retrofit2.converter.gson.GsonConverterFactory; - -import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; - -@Slf4j -public class ClientFactory { - private static final ConnectionPool CP = new ConnectionPool(2, - 30, - TimeUnit.SECONDS); - - private static final Gson GSON = new GsonBuilder().create(); - - private static HetznerApi create(String apiToken) { - final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(log::trace); - //noinspection UnstableApiUsage - loggingInterceptor.redactHeader(HttpHeaders.AUTHORIZATION); - loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); - final OkHttpClient client = new OkHttpClient.Builder() - .connectionPool(CP) - .addInterceptor(new AuthenticationInterceptor(apiToken)) - .addInterceptor(UserAgentInterceptor.INSTANCE) - .addInterceptor(loggingInterceptor) - .build(); - - final Retrofit.Builder builder = new Retrofit.Builder() - .baseUrl(System.getProperty(HetznerConstants.PROP_API_ENDPOINT, - HetznerConstants.DEFAULT_ENDPOINT)) - .client(client) - .addConverterFactory(GsonConverterFactory.create(GSON)); - return builder.build().create(HetznerApi.class); - } - /** - * Create new proxy of {@link HetznerApi} using token provider. - * - * @param tokenProvider supplier of Hetzner API token. - * @return Proxy of {@link HetznerApi} - * @throws IllegalStateException when credentialsId is not valid - */ - public static HetznerApi create(Supplier tokenProvider) { - return create(tokenProvider.get()); - } -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateServerRequest.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateServerRequest.java deleted file mode 100644 index 76fbbec..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateServerRequest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -import java.util.List; -import java.util.Map; - -@Data -public class CreateServerRequest { - private String name; - private String location; - private String datacenter; - @SerializedName("server_type") - private String serverType; - @SerializedName("start_after_create") - private boolean startAfterCreate = true; - private String image; - @SerializedName("user_data") - private String userData; - private Map labels; - @SerializedName("ssh_keys") - private List sshKeys; - private List networks; - @SerializedName("public_net") - private PublicNetRequest publicNet; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateServerResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateServerResponse.java deleted file mode 100644 index 28e32c5..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateServerResponse.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -import java.util.List; - -@Data -public class CreateServerResponse { - private ServerDetail server; - private ActionDetail action; - @SerializedName("next_actions") - private List nextActions; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateSshKeyRequest.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateSshKeyRequest.java deleted file mode 100644 index a8732ee..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateSshKeyRequest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Builder; -import lombok.Data; - -import java.util.Map; - -@Builder -@Data -public class CreateSshKeyRequest { - private Map labels; - private String name; - @SerializedName("public_key") - private String publicKey; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateSshKeyResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateSshKeyResponse.java deleted file mode 100644 index 64f897d..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/CreateSshKeyResponse.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -@Data -public class CreateSshKeyResponse { - @SerializedName("ssh_key") - private SshKeyDetail sshKey; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/DatacenterDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/DatacenterDetail.java deleted file mode 100644 index f3c216b..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/DatacenterDetail.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class DatacenterDetail extends IdentifiableResource{ - private String name; - private String description; - private LocationDetail location; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ErrorDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ErrorDetail.java deleted file mode 100644 index 7b24b38..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ErrorDetail.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; - -@Data -public class ErrorDetail { - private String code; - private String message; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetAllPrimaryIpsResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetAllPrimaryIpsResponse.java deleted file mode 100644 index 6a17bfd..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetAllPrimaryIpsResponse.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2022 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - - -import com.google.gson.annotations.SerializedName; -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -@Data -@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") -public class GetAllPrimaryIpsResponse extends AbstractSearchResponse { - @SerializedName("primary_ips") - @NonNull - private List ips; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetDatacentersResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetDatacentersResponse.java deleted file mode 100644 index 5cad61d..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetDatacentersResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -@Data -public class GetDatacentersResponse extends AbstractSearchResponse{ - private List datacenters; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetImageByIdResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetImageByIdResponse.java deleted file mode 100644 index a8dce92..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetImageByIdResponse.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - - -import lombok.Data; - -@Data -public class GetImageByIdResponse { - private ImageDetail image; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetImagesBySelectorResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetImagesBySelectorResponse.java deleted file mode 100644 index 8a0522e..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetImagesBySelectorResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import edu.umd.cs.findbugs.annotations.NonNull; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -@Data -@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") -public class GetImagesBySelectorResponse extends AbstractSearchResponse { - @NonNull - private List images; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetLocationsResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetLocationsResponse.java deleted file mode 100644 index d26e09c..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetLocationsResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -@Data -public class GetLocationsResponse extends AbstractSearchResponse{ - private List locations; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetNetworkByIdResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetNetworkByIdResponse.java deleted file mode 100644 index 340da3e..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetNetworkByIdResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; - -@Data -public class GetNetworkByIdResponse { - private NetworkDetail network; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetNetworksBySelectorResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetNetworksBySelectorResponse.java deleted file mode 100644 index 58d4834..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetNetworksBySelectorResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -@Data -public class GetNetworksBySelectorResponse extends AbstractSearchResponse { - private List networks; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServerByIdResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServerByIdResponse.java deleted file mode 100644 index d4aa858..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServerByIdResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; - -@Data -public class GetServerByIdResponse { - private ServerDetail server; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServerTypesResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServerTypesResponse.java deleted file mode 100644 index 858fa13..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServerTypesResponse.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -@Data -public class GetServerTypesResponse extends AbstractSearchResponse{ - @SerializedName("server_types") - List serverTypes; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServersBySelectorResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServersBySelectorResponse.java deleted file mode 100644 index 789696a..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetServersBySelectorResponse.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -public class GetServersBySelectorResponse extends AbstractSearchResponse{ - private List servers; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetSshKeysBySelectorResponse.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetSshKeysBySelectorResponse.java deleted file mode 100644 index 4dda1f8..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/GetSshKeysBySelectorResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -import java.util.List; - -@Data -public class GetSshKeysBySelectorResponse { - @SerializedName("ssh_keys") - private List sshKeys; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/HetznerApi.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/HetznerApi.java deleted file mode 100644 index 0ac9aa6..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/HetznerApi.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import retrofit2.Call; -import retrofit2.http.Body; -import retrofit2.http.DELETE; -import retrofit2.http.GET; -import retrofit2.http.POST; -import retrofit2.http.Path; -import retrofit2.http.Query; - -/** - * Trimmed-down version of Hetzner public cloud API. - * For full version, check official documentation - */ -public interface HetznerApi { - /** - * Get all images that matches given label expression. - * - * @param selector label expression to match - * @return list of {@link ImageDetail} wrapped in {@link GetImagesBySelectorResponse} - */ - @GET("/v1/images?type=snapshot&status=available") - Call getImagesBySelector(@Query("label_selector") String selector); - - /** - * Get single image by providing image ID. - * - * @param id image ID to get - * @return {@link ImageDetail} object wrapped in {@link GetImageByIdResponse} - * @see Official docs - */ - @GET("/v1/images/{id}") - Call getImageById(@Path("id") Integer id); - - /** - * Get datacenters matching provided string. - * - * @param name name of datacenter to match against - * @return list of matching datacenters in form of {@link DatacenterDetail} - * wrapped in {@link GetDatacentersResponse}. - */ - @GET("/v1/datacenters") - Call getAllDatacentersWithName(@Query("name") String name); - - /** - * Get all datacenters. - * - * @return list of datacenters in form of {@link DatacenterDetail} wrapped in {@link GetDatacentersResponse}. - */ - @GET("/v1/datacenters") - Call getAllDatacenters(); - - /** - * Get locations matching provided string. - * - * @param name name of location to match against - * @return list of matching locations in form of {@link LocationDetail} wrapped in {@link GetLocationsResponse}. - */ - @GET("/v1/locations") - Call getAllLocationsWithName(@Query("name") String name); - - /** - * Get server types whose name is matching provided string. - * - * @param name name of server type to match against - * @return list of matching server types in form of {@link ServerType} wrapped in {@link GetServerTypesResponse}. - */ - @GET("/v1/server_types") - Call getAllServerTypesWithName(@Query("name") String name); - - /** - * Delete sever instance. - * - * @param id ID of server to delete - * @return {@link ActionResponse} inner object {@link ActionDetail} can be used to get result of action. - */ - @DELETE("/v1/servers/{id}") - Call deleteServer(@Path("id") int id); - - /** - * Get server detail for given ID. - * - * @param id ID of server to retrieve details for - * @return GetServerByIdResponse - */ - @GET("/v1/servers/{id}") - Call getServer(@Path("id") int id); - - /** - * Power-off server instance. - * - * @param id ID of server to power-off - * @return {@link ActionResponse} inner object {@link ActionDetail} can be used to get result of action. - */ - @POST("/v1/servers/{id}/actions/poweroff") - Call powerOffServer(@Path("id") int id); - - /** - * Create new server instance. - * - * @param request new server details - * @return {@link CreateServerResponse}. Inner objects {@link ServerDetail} and {@link ActionDetail} - * can be used to retrieve server details and operation result. - */ - @POST("/v1/servers") - Call createServer(@Body CreateServerRequest request); - - /** - * Create new SSH key. - * - * @param request new SSH key details - * @return {@link CreateSshKeyResponse} with details - */ - @POST("/v1/ssh_keys") - Call createSshKey(@Body CreateSshKeyRequest request); - - /** - * Delete existing SSH key. - * - * @param id ID of SSH key to delete - * @return {@link ErrorDetail} in case of error, empty response otherwise - * See API reference - */ - @DELETE("/v1/ssh_keys/{id}") - Call deleteSshKey(@Path("id") int id); - - /** - * Find SSH keys matching given label selector - * - * @param selector label selector used to match keys - * @return list of matched SSH keys - * See API reference - */ - @GET("/v1/ssh_keys") - Call getSshKeysBySelector(@Query("label_selector") String selector); - - /** - * Get all server matching given label selector. - * - * @param selector label selector used to match servers - * @return paged list of servers - */ - @GET("/v1/servers") - Call getServersBySelector(@Query("label_selector") String selector, - @Query("page") int page, - @Query("per_page") int perPage); - - /** - * Get all networks matching given label selector. - * - * @param selector label selector used to match servers - * @return list of networks - * see API reference - */ - @GET("/v1/networks") - Call getNetworkBySelector(@Query("label_selector") String selector); - - /** - * Get network detail based on provided network ID. - * - * @param id network ID - * @return details of network - * see API reference - */ - @GET("/v1/networks/{id}") - Call getNetworkById(@Path("id") int id); - - /** - * Get all Primary IP objects. - * - * @param selector Can be used to filter resources by labels. - * The response will only contain resources matching the label selector. - * @return returns all Primary IP objects. - * see API reference - */ - @GET("/v1/primary_ips") - Call getAllPrimaryIps(@Query("label_selector") String selector); -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/IdentifiableResource.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/IdentifiableResource.java deleted file mode 100644 index bb92f5f..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/IdentifiableResource.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; - -@Data -public class IdentifiableResource { - protected int id; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ImageDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ImageDetail.java deleted file mode 100644 index 0cc5d1d..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ImageDetail.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class ImageDetail extends IdentifiableResource{ - private String type = "snapshot"; - private String status = "available"; - private String name; - private String description; -} \ No newline at end of file diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Ipv4Detail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Ipv4Detail.java deleted file mode 100644 index f61f86d..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Ipv4Detail.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -@Data -public class Ipv4Detail { - private boolean blocked = false; - @SerializedName("dns_ptr") - private String dnsPtr; - private String ip; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/LocationDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/LocationDetail.java deleted file mode 100644 index b267530..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/LocationDetail.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class LocationDetail extends IdentifiableResource{ - private String name; - private String description; - private String country; - private String city; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Meta.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Meta.java deleted file mode 100644 index 25f8f9e..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Meta.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class Meta { - private Pagination pagination; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/NetworkDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/NetworkDetail.java deleted file mode 100644 index 3ad340e..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/NetworkDetail.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class NetworkDetail extends IdentifiableResource{ - private String name; - @SerializedName("ip_range") - private String ipRange; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Pagination.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Pagination.java deleted file mode 100644 index 265fdc8..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/Pagination.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class Pagination { - @SerializedName("last_page") - private String lastPage; - @SerializedName("next_page") - private String nextPage; - @SerializedName("per_page") - private String perPage; - @SerializedName("previous_page") - private String previousPage; - @SerializedName("total_entries") - private String totalEntries; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PrimaryIpDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PrimaryIpDetail.java deleted file mode 100644 index a72acea..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PrimaryIpDetail.java +++ /dev/null @@ -1,72 +0,0 @@ -package cloud.dnation.jenkins.plugins.hetzner.client; - - -import com.google.gson.annotations.SerializedName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; -import java.util.Map; - -@Data -@EqualsAndHashCode(callSuper = true) -public class PrimaryIpDetail extends IdentifiableResource{ - /** - * ID of the resource the Primary IP is assigned to, null if it is not assigned at all. - */ - @SerializedName("assignee_id") - private Integer assigneeId; - - /** - * Resource type the Primary IP can be assigned to. - */ - @SerializedName("assignee_type") - private String assigneeType; - - /** - * Delete this Primary IP when the resource it is assigned to is deleted. - */ - @SerializedName("auto_delete") - private boolean autoDelete; - - /** - * Whether the IP is blocked. - */ - private boolean blocked; - - /** - * Point in time when the Resource was created (in ISO-8601 format). - */ - private String created; - - /** - * Datacenter this Primary IP is located at. - */ - private DatacenterDetail datacenter; - - /** - * Array of reverse DNS entries. - */ - @SerializedName("dns_ptr") - private List dnsPtr; - - /** - * IP address. - */ - private String ip; - - /** - * User-defined labels (key-value pairs) - */ - private Map labels; - - /** - * Name of the Resource. Must be unique per Project. - */ - private String name; - - /** - * ConnectivityType of the Primary IP. - */ - private String type; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PrivateNetDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PrivateNetDetail.java deleted file mode 100644 index 9161104..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PrivateNetDetail.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -@Data -public class PrivateNetDetail { - @SerializedName("network") - private int networkId; - private String ip; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PublicNetDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PublicNetDetail.java deleted file mode 100644 index ee3473b..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PublicNetDetail.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; - -@Data -public class PublicNetDetail { - private Ipv4Detail ipv4; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PublicNetRequest.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PublicNetRequest.java deleted file mode 100644 index 13c1270..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/PublicNetRequest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2022 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -@Data -public class PublicNetRequest { - /** - * Attach an IPv4 on the public NIC. If false, no IPv4 address will be attached. Defaults to true. - */ - @SerializedName("enable_ipv4") - private boolean enableIpv4; - - /** - * Attach an IPv6 on the public NIC. If false, no IPv6 address will be attached. Defaults to true. - */ - @SerializedName("enable_ipv6") - private boolean enableIpv6; - - /** - * ID of the ipv4 Primary IP to use. If omitted and enable_ipv4 is true, a new ipv4 Primary IP will automatically be created. - */ - private Integer ipv4; - - /** - * ID of the ipv6 Primary IP to use. If omitted and enable_ipv6 is true, a new ipv6 Primary IP will automatically be created. - */ - private Integer ipv6; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ServerDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ServerDetail.java deleted file mode 100644 index fed9992..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ServerDetail.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -@Data -public class ServerDetail extends IdentifiableResource { - private String name; - /** - * Status of the Server. - *

- * Possible values: - *

    - *
  • running
  • - *
  • initializing
  • - *
  • starting
  • - *
  • stopping
  • - *
  • off
  • - *
  • deleting
  • - *
  • migrating
  • - *
  • rebuilding
  • - *
  • unknown
  • - *
- */ - private String status; - - private String created; - - @SerializedName("public_net") - private PublicNetDetail publicNet; - - @SerializedName("private_net") - private List privateNet; - - @SerializedName("server_type") - private ServerType serverType; - - private DatacenterDetail datacenter; - - private ImageDetail image; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ServerType.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ServerType.java deleted file mode 100644 index f539c8f..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/ServerType.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class ServerType extends IdentifiableResource{ - private String name; - private String description; - private int cores; - private int memory; - private int disk; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/SshKeyDetail.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/SshKeyDetail.java deleted file mode 100644 index 7739906..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/SshKeyDetail.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.Map; - -@EqualsAndHashCode(callSuper = true) -@Data -public class SshKeyDetail extends IdentifiableResource{ - private String created; - private String fingerprint; - private Map labels; - private String name; - @SerializedName("public_key") - private String publicKey; -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/UserAgentInterceptor.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/UserAgentInterceptor.java deleted file mode 100644 index 2a25914..0000000 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/client/UserAgentInterceptor.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import com.google.common.net.HttpHeaders; -import lombok.NonNull; -import okhttp3.Interceptor; -import okhttp3.Response; - -import java.io.IOException; - -/** - * {@link Interceptor} which adds "User-Agent" request header. - */ -class UserAgentInterceptor implements Interceptor { - static final UserAgentInterceptor INSTANCE = new UserAgentInterceptor(); - - @Override - @NonNull - public Response intercept(Chain chain) throws IOException { - //noinspection UnstableApiUsage - return chain.proceed(chain.request().newBuilder() - .addHeader(HttpHeaders.USER_AGENT, "Jenkins Hetzner Plugin") - .build()); - } -} diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/AbstractConnectionMethod.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/AbstractConnectionMethod.java index b3c4b25..3e936b1 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/AbstractConnectionMethod.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/AbstractConnectionMethod.java @@ -15,7 +15,7 @@ */ package cloud.dnation.jenkins.plugins.hetzner.launcher; -import cloud.dnation.jenkins.plugins.hetzner.client.ServerDetail; +import cloud.dnation.hetznerclient.ServerDetail; import hudson.model.AbstractDescribableImpl; public abstract class AbstractConnectionMethod extends AbstractDescribableImpl { diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultConnectionMethod.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultConnectionMethod.java index 2862edf..26cc9c4 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultConnectionMethod.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultConnectionMethod.java @@ -15,8 +15,8 @@ */ package cloud.dnation.jenkins.plugins.hetzner.launcher; +import cloud.dnation.hetznerclient.ServerDetail; import cloud.dnation.jenkins.plugins.hetzner.Messages; -import cloud.dnation.jenkins.plugins.hetzner.client.ServerDetail; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.Descriptor; diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/HetznerServerComputerLauncher.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/HetznerServerComputerLauncher.java index 3ab5eda..61175d3 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/HetznerServerComputerLauncher.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/HetznerServerComputerLauncher.java @@ -15,11 +15,11 @@ */ package cloud.dnation.jenkins.plugins.hetzner.launcher; +import cloud.dnation.hetznerclient.ServerDetail; import cloud.dnation.jenkins.plugins.hetzner.Helper; import cloud.dnation.jenkins.plugins.hetzner.HetznerConstants; import cloud.dnation.jenkins.plugins.hetzner.HetznerServerAgent; import cloud.dnation.jenkins.plugins.hetzner.HetznerServerComputer; -import cloud.dnation.jenkins.plugins.hetzner.client.ServerDetail; import com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator; import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey; import com.google.common.base.Preconditions; diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/PublicAddressOnly.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/PublicAddressOnly.java index 9d83ea7..24c7a8b 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/PublicAddressOnly.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/PublicAddressOnly.java @@ -15,8 +15,8 @@ */ package cloud.dnation.jenkins.plugins.hetzner.launcher; +import cloud.dnation.hetznerclient.ServerDetail; import cloud.dnation.jenkins.plugins.hetzner.Messages; -import cloud.dnation.jenkins.plugins.hetzner.client.ServerDetail; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.Descriptor; diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/AbstractByLabelSelector.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/AbstractByLabelSelector.java index 2f0d780..13852b5 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/AbstractByLabelSelector.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/AbstractByLabelSelector.java @@ -15,10 +15,10 @@ */ package cloud.dnation.jenkins.plugins.hetzner.primaryip; -import cloud.dnation.jenkins.plugins.hetzner.client.CreateServerRequest; -import cloud.dnation.jenkins.plugins.hetzner.client.HetznerApi; -import cloud.dnation.jenkins.plugins.hetzner.client.PrimaryIpDetail; -import cloud.dnation.jenkins.plugins.hetzner.client.PublicNetRequest; +import cloud.dnation.hetznerclient.CreateServerRequest; +import cloud.dnation.hetznerclient.HetznerApi; +import cloud.dnation.hetznerclient.PrimaryIpDetail; +import cloud.dnation.hetznerclient.PublicNetRequest; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import lombok.Getter; diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/AbstractPrimaryIpStrategy.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/AbstractPrimaryIpStrategy.java index 7396b2c..e6e8b89 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/AbstractPrimaryIpStrategy.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/AbstractPrimaryIpStrategy.java @@ -15,8 +15,8 @@ */ package cloud.dnation.jenkins.plugins.hetzner.primaryip; -import cloud.dnation.jenkins.plugins.hetzner.client.CreateServerRequest; -import cloud.dnation.jenkins.plugins.hetzner.client.HetznerApi; +import cloud.dnation.hetznerclient.CreateServerRequest; +import cloud.dnation.hetznerclient.HetznerApi; import hudson.model.AbstractDescribableImpl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/DefaultStrategy.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/DefaultStrategy.java index 869c73c..1c58941 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/DefaultStrategy.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/DefaultStrategy.java @@ -15,9 +15,9 @@ */ package cloud.dnation.jenkins.plugins.hetzner.primaryip; +import cloud.dnation.hetznerclient.CreateServerRequest; +import cloud.dnation.hetznerclient.HetznerApi; import cloud.dnation.jenkins.plugins.hetzner.Messages; -import cloud.dnation.jenkins.plugins.hetzner.client.CreateServerRequest; -import cloud.dnation.jenkins.plugins.hetzner.client.HetznerApi; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.Descriptor; diff --git a/src/test/java/cloud/dnation/jenkins/plugins/hetzner/client/HetznerApiTest.java b/src/test/java/cloud/dnation/jenkins/plugins/hetzner/client/HetznerApiTest.java deleted file mode 100644 index 65da565..0000000 --- a/src/test/java/cloud/dnation/jenkins/plugins/hetzner/client/HetznerApiTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2021 https://dnation.cloud - * - * 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 cloud.dnation.jenkins.plugins.hetzner.client; - -import cloud.dnation.jenkins.plugins.hetzner.HetznerConstants; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import retrofit2.Call; -import retrofit2.Response; - -import java.io.IOException; - -import static cloud.dnation.jenkins.plugins.hetzner.TestHelper.resourceAsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -public class HetznerApiTest { - private static MockWebServer ws; - private static HetznerApi api; - - @BeforeClass - public static void setUpBeforeClass() throws IOException { - ws = new MockWebServer(); - ws.start(); - System.setProperty(HetznerConstants.PROP_API_ENDPOINT, "http://localhost:" + ws.getPort()); - api = ClientFactory.create(() -> "mock"); - } - - @AfterClass - public static void tearDownAfterClass() throws IOException { - ws.shutdown(); - ws.close(); - } - - @Test - public void testGetNetworkById() throws IOException { - ws.enqueue(new MockResponse() - .setBody(resourceAsString("get-network-by-id.json")) - ); - Call call = api.getNetworkById(10); - GetNetworkByIdResponse result = call.execute().body(); - assertEquals("my-net-1", result.getNetwork().getName()); - assertEquals(10, result.getNetwork().getId()); - assertEquals("10.132.0.0/14", result.getNetwork().getIpRange()); - } - - - @Test - public void testGetNetworkByIdInvalid() throws IOException { - ws.enqueue(new MockResponse() - .setBody(resourceAsString("get-network-by-id-invalid.json")) - .setResponseCode(404) - ); - Call call = api.getNetworkById(11); - Response response = call.execute(); - assertEquals(404, response.code()); - } - - @Test - public void testGetNetworksBySelector() throws IOException { - ws.enqueue(new MockResponse().setBody(resourceAsString("get-networks-by-selector.json"))); - Call call = api.getNetworkBySelector("test=1"); - GetNetworksBySelectorResponse result = call.execute().body(); - assertEquals(1, result.getNetworks().size()); - assertEquals(12, result.getNetworks().get(0).getId()); - assertEquals("my-net-2", result.getNetworks().get(0).getName()); - assertEquals("10.132.0.0/14", result.getNetworks().get(0).getIpRange()); - assertEquals("1", result.getMeta().getPagination().getTotalEntries()); - } - - @Test - public void testGetNetworksBySelectorEmpty() throws IOException { - ws.enqueue(new MockResponse().setBody(resourceAsString("get-networks-by-selector-empty.json"))); - Call call = api.getNetworkBySelector("test=invalid"); - GetNetworksBySelectorResponse result = call.execute().body(); - assertEquals(0, result.getNetworks().size()); - assertEquals("0", result.getMeta().getPagination().getTotalEntries()); - } - - @Test - public void testGetPrimaryIpsBySelector() throws IOException { - ws.enqueue(new MockResponse().setBody(resourceAsString("get-primary-ips-by-selector.json"))); - Call call = api.getAllPrimaryIps("jenkins"); - GetAllPrimaryIpsResponse result = call.execute().body(); - assertEquals(1, result.getIps().size()); - assertEquals("1.2.3.4", result.getIps().get(0).getIp()); - assertNull(result.getIps().get(0).getAssigneeId()); - } -} diff --git a/src/test/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/PrimaryIpStrategyTest.java b/src/test/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/PrimaryIpStrategyTest.java index 5ee2a12..cf83522 100644 --- a/src/test/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/PrimaryIpStrategyTest.java +++ b/src/test/java/cloud/dnation/jenkins/plugins/hetzner/primaryip/PrimaryIpStrategyTest.java @@ -15,10 +15,10 @@ */ package cloud.dnation.jenkins.plugins.hetzner.primaryip; -import cloud.dnation.jenkins.plugins.hetzner.client.CreateServerRequest; -import cloud.dnation.jenkins.plugins.hetzner.client.DatacenterDetail; -import cloud.dnation.jenkins.plugins.hetzner.client.LocationDetail; -import cloud.dnation.jenkins.plugins.hetzner.client.PrimaryIpDetail; +import cloud.dnation.hetznerclient.CreateServerRequest; +import cloud.dnation.hetznerclient.DatacenterDetail; +import cloud.dnation.hetznerclient.LocationDetail; +import cloud.dnation.hetznerclient.PrimaryIpDetail; import org.junit.Test; import static cloud.dnation.jenkins.plugins.hetzner.primaryip.AbstractByLabelSelector.isIpUsable; diff --git a/src/test/resources/get-network-by-id-invalid.json b/src/test/resources/get-network-by-id-invalid.json deleted file mode 100644 index ce1913d..0000000 --- a/src/test/resources/get-network-by-id-invalid.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "error": { - "message": "network with ID 11 not found", - "code": "not_found", - "details": null - } -} diff --git a/src/test/resources/get-network-by-id.json b/src/test/resources/get-network-by-id.json deleted file mode 100644 index a5627ce..0000000 --- a/src/test/resources/get-network-by-id.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "network": { - "id": 10, - "name": "my-net-1", - "ip_range": "10.132.0.0/14" - } -} diff --git a/src/test/resources/get-networks-by-selector-empty.json b/src/test/resources/get-networks-by-selector-empty.json deleted file mode 100644 index c668c0f..0000000 --- a/src/test/resources/get-networks-by-selector-empty.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "networks": [], - "meta": { - "pagination": { - "page": 1, - "per_page": 25, - "previous_page": null, - "next_page": null, - "last_page": 1, - "total_entries": 0 - } - } -} \ No newline at end of file diff --git a/src/test/resources/get-networks-by-selector.json b/src/test/resources/get-networks-by-selector.json deleted file mode 100644 index d191d40..0000000 --- a/src/test/resources/get-networks-by-selector.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "networks": [ - { - "id": 12, - "name": "my-net-2", - "ip_range": "10.132.0.0/14" - } - ], - "meta": { - "pagination": { - "page": 1, - "per_page": 25, - "previous_page": null, - "next_page": null, - "last_page": 1, - "total_entries": 1 - } - } -} diff --git a/src/test/resources/get-primary-ips-by-selector.json b/src/test/resources/get-primary-ips-by-selector.json deleted file mode 100644 index 928a82e..0000000 --- a/src/test/resources/get-primary-ips-by-selector.json +++ /dev/null @@ -1,123 +0,0 @@ -{ - "primary_ips": [ - { - "id": 7890123, - "name": "primary_ip-123456", - "labels": { - "jenkins": "1" - }, - "created": "2022-07-15T05:21:04.780842+00:00", - "blocked": false, - "datacenter": { - "id": 4, - "name": "fsn1-dc14", - "description": "Falkenstein 1 DC14", - "location": { - "id": 1, - "name": "fsn1", - "description": "Falkenstein DC Park 1", - "country": "DE", - "city": "Falkenstein", - "latitude": 50.47612, - "longitude": 12.370071, - "network_zone": "eu-central" - }, - "server_types": { - "supported": [ - 9, - 7, - 5, - 3, - 1, - 11, - 12, - 13, - 14, - 15, - 22, - 23, - 24, - 25, - 26, - 33, - 34, - 35, - 36, - 37, - 38 - ], - "available": [ - 1, - 3, - 5, - 7, - 9, - 11, - 12, - 13, - 14, - 15, - 22, - 23, - 24, - 25, - 26, - 33, - 34, - 35, - 36, - 37, - 38 - ], - "available_for_migration": [ - 1, - 3, - 5, - 7, - 9, - 11, - 12, - 13, - 14, - 15, - 22, - 23, - 24, - 25, - 26, - 33, - 34, - 35, - 36, - 37, - 38 - ] - } - }, - "ip": "1.2.3.4", - "dns_ptr": [ - { - "ip": "1.2.3.4", - "dns_ptr": "static.14.3.2.1.clients.your-server.de" - } - ], - "protection": { - "delete": false - }, - "type": "ipv4", - "auto_delete": false, - "assignee_type": "server", - "assignee_id": null - } - ], - "meta": { - "pagination": { - "page": 1, - "per_page": 25, - "previous_page": null, - "next_page": null, - "last_page": 1, - "total_entries": 1 - } - } -}