diff --git a/cs-httpclient-commons/pom.xml b/cs-httpclient-commons/pom.xml index aebbd76060..a5d6bfa932 100644 --- a/cs-httpclient-commons/pom.xml +++ b/cs-httpclient-commons/pom.xml @@ -21,7 +21,7 @@ io.cloudslang.content cs-httpclient-commons - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT jar ${project.groupId}:${project.artifactId} diff --git a/cs-office-365/src/main/java/io/cloudslang/content/office365/actions/utils/GetAuthorizationTokenV2.java b/cs-office-365/src/main/java/io/cloudslang/content/office365/actions/utils/GetAuthorizationTokenV2.java index ea4de73acb..3c5cef2be3 100644 --- a/cs-office-365/src/main/java/io/cloudslang/content/office365/actions/utils/GetAuthorizationTokenV2.java +++ b/cs-office-365/src/main/java/io/cloudslang/content/office365/actions/utils/GetAuthorizationTokenV2.java @@ -1,3 +1,17 @@ +/* + * (c) Copyright 2019 Micro Focus, L.P. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available 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. + */ /* * (c) Copyright 2022 Micro Focus, L.P. * All rights reserved. This program and the accompanying materials @@ -88,6 +102,7 @@ public class GetAuthorizationTokenV2 { public Map execute(@Param(value = LOGIN_TYPE, description = LOGIN_TYPE_DESC) String loginType, @Param(value = CLIENT_ID, required = true, description = CLIENT_ID_DESC) String clientId, @Param(value = CLIENT_SECRET, encrypted = true, description = CLIENT_SECRET_DESC) String clientSecret, + @Param(value = RESOURCE, description = RESOURCES_DESC) String resource, @Param(value = USERNAME, description = USERNAME_DESC) String username, @Param(value = PASSWORD, encrypted = true, description = PASSWORD_DESC) String password, @Param(value = LOGIN_AUTHORITY, required = true, description = LOGIN_AUTHORITY_DESC) String loginAuthority, @@ -111,6 +126,10 @@ public Map execute(@Param(value = LOGIN_TYPE, description = LOGI return getFailureResultsMap(StringUtilities.join(exceptionMessages, NEW_LINE)); } + if(!resource.isEmpty()){ + scope = resource; + } + try { final IAuthenticationResult result = AuthorizationTokenV2Impl.getToken(AuthorizationTokenInputs.builder() .loginType(loginType) diff --git a/cs-office-365/src/main/java/io/cloudslang/content/office365/services/AuthorizationTokenV2Impl.java b/cs-office-365/src/main/java/io/cloudslang/content/office365/services/AuthorizationTokenV2Impl.java index 4d6aaae209..fe407c8cee 100644 --- a/cs-office-365/src/main/java/io/cloudslang/content/office365/services/AuthorizationTokenV2Impl.java +++ b/cs-office-365/src/main/java/io/cloudslang/content/office365/services/AuthorizationTokenV2Impl.java @@ -1,3 +1,17 @@ +/* + * (c) Copyright 2019 Micro Focus, L.P. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available 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. + */ /* * (c) Copyright 2022 Micro Focus, L.P. * All rights reserved. This program and the accompanying materials diff --git a/cs-openshift/header-definitions.xml b/cs-openshift/header-definitions.xml new file mode 100644 index 0000000000..0f34784aaa --- /dev/null +++ b/cs-openshift/header-definitions.xml @@ -0,0 +1,15 @@ + + + + /* + + */ + + /* + */ + true + false + true + false + + diff --git a/cs-openshift/license.template b/cs-openshift/license.template new file mode 100644 index 0000000000..7592b89f18 --- /dev/null +++ b/cs-openshift/license.template @@ -0,0 +1,12 @@ +* (c) Copyright ${copyright.year} Micro Focus, L.P. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Apache License v2.0 which accompany this distribution. +* +* The Apache License is available 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. \ No newline at end of file diff --git a/cs-openshift/pom.xml b/cs-openshift/pom.xml new file mode 100644 index 0000000000..872bacecb1 --- /dev/null +++ b/cs-openshift/pom.xml @@ -0,0 +1,252 @@ + + + + 4.0.0 + + io.cloudslang.content + cs-openshift + 0.0.1-SNAPSHOT + jar + + ${project.groupId}:${project.artifactId} + Openshift + https://github.com/CloudSlang/cs-actions + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + scm:git:https://CloudSlang/cs-actions.git + scm:git:git@github.com:CloudSlang/cs-actions.git + https://github.com/CloudSlang/cs-actions.git + master + + + + + ossrh + Maven Central staging repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + ossrh + Maven Central snapshots repository + https://oss.sonatype.org/content/repositories/snapshots/ + + + + + + 3.1 + 2.5.2 + 2.10.4 + 3.0 + 3.0.1 + 2.8.2 + 1.6 + + 1.10.7 + 0.0.5 + 0.1.74 + + UTF-8 + 1.8 + 1.8 + true + overwritten_by_ci + + + + + com.hp.score.sdk + score-content-sdk + ${score-content-sdk.version} + + + + + + + + io.cloudslang.content + cs-httpclient-commons + 0.0.2-SNAPSHOT + compile + + + + org.jsoup + jsoup + 1.15.3 + + + + com.google.code.gson + gson + 2.10 + + + com.jayway.jsonpath + json-path + 2.7.0 + compile + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + + + -Xdoclint:none + + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + + org.apache.maven.plugins + maven-release-plugin + ${maven-release-plugin.version} + + + + + + + com.mycila + license-maven-plugin + 3.0 + +
${project.basedir}/license.template
+ + ${project.basedir}/header-definitions.xml + + + **/*.java + pom.xml + + + 2022 + + false + + cs-actions-java-header + XML_STYLE + +
+ + + process-resources + + format + + + +
+ + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + +
+
+ + + + gpg + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + + + deploy-internal + + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + + custom-deployment-to-nexus + + deploy + + deploy + + ${custom.nexus} + + + + + + + + + +
\ No newline at end of file diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/CreateDeployment.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/CreateDeployment.java new file mode 100644 index 0000000000..13fc5acd11 --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/CreateDeployment.java @@ -0,0 +1,137 @@ +/* + * (c) Copyright 2022 Micro Focus + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.cloudslang.content.redhat.actions; + + +import com.hp.oo.sdk.content.annotations.Action; +import com.hp.oo.sdk.content.annotations.Output; +import com.hp.oo.sdk.content.annotations.Param; +import com.hp.oo.sdk.content.annotations.Response; +import com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType; +import com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType; +import com.hp.oo.sdk.content.plugin.GlobalSessionObject; +import com.hp.oo.sdk.content.plugin.SerializableSessionObject; +import io.cloudslang.content.constants.ResponseNames; +import io.cloudslang.content.constants.ReturnCodes; +import io.cloudslang.content.httpclient.actions.HttpClientPostAction; +import io.cloudslang.content.utils.OutputUtilities; + +import java.util.Map; + +import static io.cloudslang.content.constants.OutputNames.RETURN_CODE; +import static io.cloudslang.content.constants.OutputNames.RETURN_RESULT; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_CONNECTION_POOL_DESC; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_COOKIES_DESC; +import static io.cloudslang.content.redhat.services.OpenshiftService.processHttpResult; +import static io.cloudslang.content.redhat.utils.Constants.CommonConstants.*; +import static io.cloudslang.content.redhat.utils.Descriptions.Common.*; +import static io.cloudslang.content.redhat.utils.Descriptions.CreateDeploymentAction.*; +import static io.cloudslang.content.redhat.utils.Descriptions.CreateDeploymentAction.EXCEPTION_DESC; +import static io.cloudslang.content.redhat.utils.Descriptions.CreateDeploymentAction.RETURN_RESULT_DESC; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.*; +import static org.apache.commons.lang3.StringUtils.EMPTY; + +public class CreateDeployment { + + @Action(name = CREATE_DEPLOYMENT, + description = CREATE_DEPLOYMENT_DESCRIPTION, + outputs = { + @Output(value = RETURN_RESULT, description = RETURN_RESULT_DESC), + @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), + @Output(value = EXCEPTION, description = EXCEPTION_DESC), + @Output(value = STATUS_CODE, description = STATUS_CODE_DESC) + }, + responses = { + @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), + @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) + }) + public Map execute( + @Param(value = HOST, description = HOST_DESC, required = true) String hostName, + @Param(value = AUTH_TOKEN, description = AUTH_TOKEN_DESCRIPTION, required = true) String authToken, + @Param(value = DEFINITION, description = DEFINITION_DESCRIPTION, required = true) String body, + @Param(value = NAMESPACE, description = NAMESPACE_DESCRIPTION, required = true) String namespace, + + @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, + @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, + @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, + @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, + @Param(value = TLS_VERSION, description = TLS_VERSION_DESC) String tlsVersion, + @Param(value = ALLOWED_CIPHERS, description = ALLOWED_CIPHERS_DESC) String allowedCiphers, + @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, + @Param(value = X509_HOSTNAME_VERIFIER, description = X509_HOSTNAME_VERIFIER_DESC) String x509HostnameVerifier, + @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, + @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, + @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, + @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, + @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, + @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESC) String executionTimeout, + @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, + @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONNECTIONS_MAX_PER_ROUTE_DESC) String connectionsMaxPerRoute, + @Param(value = CONNECTIONS_MAX_TOTAL, description = CONNECTIONS_MAX_TOTAL_DESC) String connectionsMaxTotal, + @Param(value = SESSION_COOKIES, description = SESSION_COOKIES_DESC) SerializableSessionObject sessionCookies, + @Param(value = SESSION_CONNECTION_POOL, description = SESSION_CONNECTION_POOL_DESC) GlobalSessionObject sessionConnectionPool) { + + try { + + Map result = new HttpClientPostAction().execute( + hostName + APPS_V1_NAMESPACES + namespace + "/deployments", + ANONYMOUS, + EMPTY, + EMPTY, + TRUE, + proxyHost, + proxyPort, + proxyUsername, + proxyPassword, + tlsVersion, + allowedCiphers, + trustAllRoots, + x509HostnameVerifier, + trustKeystore, + trustPassword, + keystore, + keystorePassword, + keepAlive, + connectionsMaxPerRoute, + connectionsMaxTotal, + EMPTY, + EMPTY, + CONTENT_TYPE + APPLICATION_JSON + COMMA + AUTHORIZATION_BEARER + authToken, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + body, + APPLICATION_JSON, + EMPTY, + connectTimeout, + EMPTY, + executionTimeout, + sessionCookies, + sessionConnectionPool + ); + + processHttpResult(result); + return result; + + } catch (Exception exception) { + return OutputUtilities.getFailureResultsMap(exception); + } + } +} diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/DeleteDeployment.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/DeleteDeployment.java new file mode 100644 index 0000000000..1ff390ec0f --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/DeleteDeployment.java @@ -0,0 +1,123 @@ +/* + * (c) Copyright 2022 Micro Focus, L.P. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.cloudslang.content.redhat.actions; + +import com.hp.oo.sdk.content.annotations.Action; +import com.hp.oo.sdk.content.annotations.Output; +import com.hp.oo.sdk.content.annotations.Param; +import com.hp.oo.sdk.content.annotations.Response; +import com.hp.oo.sdk.content.plugin.GlobalSessionObject; +import com.hp.oo.sdk.content.plugin.SerializableSessionObject; +import io.cloudslang.content.constants.ReturnCodes; +import io.cloudslang.content.httpclient.actions.HttpClientDeleteAction; +import io.cloudslang.content.utils.OutputUtilities; + +import java.util.Map; + +import static com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType.COMPARE_EQUAL; +import static com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType.ERROR; +import static com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType.RESOLVED; +import static io.cloudslang.content.constants.OutputNames.*; +import static io.cloudslang.content.constants.ResponseNames.FAILURE; +import static io.cloudslang.content.constants.ResponseNames.SUCCESS; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_CONNECTION_POOL_DESC; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_COOKIES_DESC; +import static io.cloudslang.content.redhat.services.OpenshiftService.processHttpResult; +import static io.cloudslang.content.redhat.utils.Constants.CommonConstants.*; +import static io.cloudslang.content.redhat.utils.Descriptions.Common.*; +import static io.cloudslang.content.redhat.utils.Descriptions.DeleteDeployment.*; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.AUTH_TOKEN; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.STATUS_CODE; + +public class DeleteDeployment { + @Action(name = DELETE_DEPLOYMENT_NAME, + description = DELETE_DEPLOYMENT_DESC, + outputs = { + @Output(value = RETURN_RESULT, description = RETURN_RESULT_DESC), + @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), + @Output(value = EXCEPTION, description = EXCEPTION_DESC), + @Output(value = STATUS_CODE, description = STATUS_CODE_DESC) + }, + responses = { + @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = COMPARE_EQUAL, responseType = RESOLVED, description = SUCCESS_DESC), + @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = COMPARE_EQUAL, responseType = ERROR, description = FAILURE_DESC) + }) + public Map execute(@Param(value = HOST, required = true, description = HOST_DESC) String host, + @Param(value = AUTH_TOKEN, required = true, description = AUTH_TOKEN_DESC) String authToken, + @Param(value = NAMESPACE, required = true, description = NAMESPACE_DESC) String namespace, + @Param(value = DEPLOYMENT, required = true, description = DEPLOYMENT_DESC) String deployment, + + @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, + @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, + @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, + @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, + @Param(value = TLS_VERSION, description = TLS_VERSION_DESC) String tlsVersion, + @Param(value = ALLOWED_CIPHERS, description = ALLOWED_CIPHERS_DESC) String allowedCyphers, + @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, + @Param(value = X509_HOSTNAME_VERIFIER, description = X509_HOSTNAME_VERIFIER_DESC) String x509HostnameVerifier, + @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, + @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, + @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, + @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, + @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, + @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESC) String executionTimeout, + @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, + @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONNECTIONS_MAX_PER_ROUTE_DESC) String connectionsMaxPerRoute, + @Param(value = CONNECTIONS_MAX_TOTAL, description = CONNECTIONS_MAX_TOTAL_DESC) String connectionsMaxTotal, + @Param(value = SESSION_COOKIES, description = SESSION_COOKIES_DESC) SerializableSessionObject sessionCookies, + @Param(value = SESSION_CONNECTION_POOL, description = SESSION_CONNECTION_POOL_DESC) GlobalSessionObject sessionConnectionPool) { + try { + + Map result = new HttpClientDeleteAction().execute( + host + APPS_V1_NAMESPACES + namespace + DEPLOYMENTS + deployment, + ANONYMOUS, + EMPTY_STRING, + EMPTY_STRING, + TRUE, + proxyHost, + proxyPort, + proxyUsername, + proxyPassword, + tlsVersion, + allowedCyphers, + trustAllRoots, + x509HostnameVerifier, + trustKeystore, + trustPassword, + keystore, + keystorePassword, + keepAlive, + connectionsMaxPerRoute, + connectionsMaxTotal, + TRUE, + AUTHORIZATION_BEARER + authToken, + EMPTY_STRING, + EMPTY_STRING, + connectTimeout, + EMPTY_STRING, + executionTimeout, + sessionCookies, + sessionConnectionPool); + + processHttpResult(result); + return result; + } catch (Exception exception) { + return OutputUtilities.getFailureResultsMap(exception); + } + } + +} diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetDeploymentStatus.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetDeploymentStatus.java new file mode 100644 index 0000000000..1891ef31dc --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetDeploymentStatus.java @@ -0,0 +1,157 @@ +package io.cloudslang.content.redhat.actions; + +import com.hp.oo.sdk.content.annotations.Action; +import com.hp.oo.sdk.content.annotations.Output; +import com.hp.oo.sdk.content.annotations.Param; +import com.hp.oo.sdk.content.annotations.Response; +import com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType; +import com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType; +import com.hp.oo.sdk.content.plugin.GlobalSessionObject; +import com.hp.oo.sdk.content.plugin.SerializableSessionObject; +import io.cloudslang.content.constants.OutputNames; +import io.cloudslang.content.constants.ResponseNames; +import io.cloudslang.content.constants.ReturnCodes; +import io.cloudslang.content.httpclient.actions.HttpClientGetAction; +import io.cloudslang.content.utils.OutputUtilities; + +import static io.cloudslang.content.redhat.services.OpenshiftService.*; +import static io.cloudslang.content.redhat.utils.Constants.CommonConstants.*; + +import java.util.Map; + +import static io.cloudslang.content.redhat.utils.Descriptions.GetDeploymentStatus.FAILURE_DESC; +import static io.cloudslang.content.redhat.utils.Descriptions.GetDeploymentStatus.STATUS_CODE_DESC; +import static io.cloudslang.content.redhat.utils.Descriptions.GetDeploymentStatus.SUCCESS_DESC; +import static io.cloudslang.content.redhat.utils.Descriptions.GetDeploymentStatus.RETURN_RESULT_DESC; +import static io.cloudslang.content.redhat.utils.Descriptions.GetPodList.FAILURE_RETURN_RESULT; +import static io.cloudslang.content.redhat.utils.Descriptions.GetPodList.NEGATIVE_RETURN_CODE; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.*; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.EXCEPTION; +import static org.apache.commons.lang3.StringUtils.EMPTY; + +import static io.cloudslang.content.constants.OutputNames.*; +import static io.cloudslang.content.redhat.utils.Descriptions.Common.*; +import static io.cloudslang.content.redhat.utils.Descriptions.GetDeploymentStatus.*; + +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_CONNECTION_POOL_DESC; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_COOKIES_DESC; +import static io.cloudslang.content.httpclient.utils.Inputs.HTTPInputs.SESSION_CONNECTION_POOL; +import static io.cloudslang.content.httpclient.utils.Inputs.HTTPInputs.SESSION_COOKIES; + +public class GetDeploymentStatus { + + @Action(name = GET_DEPLOYMENT_STATUS, + description = GET_DEPLOYMENT_STATUS_DESC, + outputs = { + //Common outputs + @Output(value = RETURN_RESULT, description = RETURN_RESULT_DESC), + @Output(value = STATUS_CODE, description = STATUS_CODE_DESC), + @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), + @Output(value = EXCEPTION, description = EXCEPTION_DESC), + //Specific outputs - general + @Output(value = DOCUMENT_OUTPUT, description = DOCUMENT_OUTPUT_DESC), + + @Output(value = KIND_OUTPUT, description = KIND_OUTPUT_DESC), + @Output(value = NAME_OUTPUT, description = NAME_OUTPUT_DESC), + @Output(value = NAMESPACE_OUTPUT, description = NAMESPACE_OUTPUT_DESC), + @Output(value = UID_OUTPUT, description = UID_OUTPUT_DESC), + + @Output(value = OBSERVED_GENERATION_OUTPUT, description = OBSERVED_GENERATION_OUTPUT_DESC), + @Output(value = REPLICAS_OUTPUT, description = REPLICAS_OUTPUT_DESC), + @Output(value = UPDATED_REPLICAS_OUTPUT, description = UPDATED_REPLICAS_OUTPUT_DESC), + @Output(value = UNAVAILABLE_REPLICAS_OUTPUT, description = UNAVAILABLE_REPLICAS_OUTPUT_DESC), + @Output(value = CONDITIONS_OUTPUT, description = CONDITIONS_OUTPUT_DESC) + }, + responses = { + @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, + matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), + @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, + matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, description = FAILURE_DESC) + }) + + public Map execute( + //Common Inputs + @Param(value = HOST, description = HOST_DESC, required = true) String host, + @Param(value = AUTH_TOKEN, description = AUTH_TOKEN_DESC, required = true) String authToken, + //Specific inputs + @Param(value = NAME, description = NAME_DESC, required = true) String name, + @Param(value = NAMESPACE, description = NAMESPACE_DESC, required = true) String namespace, + //Common Inputs + @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, + @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, + @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, + @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, + @Param(value = TLS_VERSION, description = TLS_VERSION_DESC) String tlsVersion, + @Param(value = ALLOWED_CIPHERS, description = ALLOWED_CIPHERS_DESC) String allowedCiphers, + @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, + @Param(value = X509_HOSTNAME_VERIFIER, description = X509_HOSTNAME_VERIFIER_DESC) String x509HostnameVerifier, + @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, + @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, + @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, + @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, + @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, + @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESC) String executionTimeout, + @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, + @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONNECTIONS_MAX_PER_ROUTE_DESC) String connectionsMaxPerRoute, + @Param(value = CONNECTIONS_MAX_TOTAL, description = CONNECTIONS_MAX_TOTAL_DESC) String connectionsMaxTotal, + @Param(value = SESSION_COOKIES, description = SESSION_COOKIES_DESC) SerializableSessionObject sessionCookies, + @Param(value = SESSION_CONNECTION_POOL, description = SESSION_CONNECTION_POOL_DESC) GlobalSessionObject sessionConnectionPool) { + + try { + + Map result = new HttpClientGetAction().execute( + host + GET_DEPLOYMENT_STATUS_ENDPOINT_1 + namespace + + GET_DEPLOYMENT_STATUS_ENDPOINT_2 + name + + GET_DEPLOYMENT_STATUS_ENDPOINT_3, + ANONYMOUS, + EMPTY, + EMPTY, + EMPTY, + proxyHost, + proxyPort, + proxyUsername, + proxyPassword, + tlsVersion, + allowedCiphers, + trustAllRoots, + x509HostnameVerifier, + trustKeystore, + trustPassword, + keystore, + keystorePassword, + keepAlive, + connectionsMaxPerRoute, + connectionsMaxTotal, + EMPTY, + EMPTY, + AUTHORIZATION_BEARER + authToken, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + connectTimeout, + EMPTY, + executionTimeout, + sessionCookies, + sessionConnectionPool + ); + + if (Integer.parseInt(result.get(RETURN_CODE)) != -1) { + if (Integer.parseInt(result.get(STATUS_CODE)) >= 200 && Integer.parseInt(result.get(STATUS_CODE)) < 300) + processHttpGetDeploymentStatusResult(result); + else { + result.put(RETURN_CODE, NEGATIVE_RETURN_CODE); + result.put(EXCEPTION, result.get(RETURN_RESULT)); + result.put(RETURN_RESULT, FAILURE_RETURN_RESULT); + } + } + + return result; + + } catch (Exception exception) { + return OutputUtilities.getFailureResultsMap(exception); + } + } + +} diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetPodList.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetPodList.java new file mode 100644 index 0000000000..68e7b97556 --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetPodList.java @@ -0,0 +1,141 @@ +package io.cloudslang.content.redhat.actions; + + +import com.hp.oo.sdk.content.annotations.Action; +import com.hp.oo.sdk.content.annotations.Output; +import com.hp.oo.sdk.content.annotations.Param; +import com.hp.oo.sdk.content.annotations.Response; +import com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType; +import com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType; +import com.hp.oo.sdk.content.plugin.GlobalSessionObject; +import com.hp.oo.sdk.content.plugin.SerializableSessionObject; +import io.cloudslang.content.constants.OutputNames; +import io.cloudslang.content.constants.ResponseNames; +import io.cloudslang.content.constants.ReturnCodes; +import io.cloudslang.content.httpclient.actions.HttpClientGetAction; + +import java.util.HashMap; +import java.util.Map; + +import static io.cloudslang.content.constants.OutputNames.RETURN_CODE; +import static io.cloudslang.content.constants.OutputNames.RETURN_RESULT; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_CONNECTION_POOL_DESC; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_COOKIES_DESC; +import static io.cloudslang.content.redhat.services.OpenshiftService.*; +import static io.cloudslang.content.redhat.utils.Constants.CommonConstants.*; +import static io.cloudslang.content.redhat.utils.Descriptions.Common.*; +import static io.cloudslang.content.redhat.utils.Descriptions.GetPodList.*; +import static io.cloudslang.content.redhat.utils.Descriptions.GetPodList.STATUS_CODE_DESC; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.*; +import static org.apache.commons.lang3.StringUtils.EMPTY; + +public class GetPodList { + + + @Action(name = GET_POD_LIST, + description = GET_POD_LIST_DESC, + outputs = { + //Common outputs + @Output(value = RETURN_RESULT, description = RETURN_RESULT_DESC), + @Output(value = STATUS_CODE, description = STATUS_CODE_DESC), + @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), + @Output(value = EXCEPTION, description = EXCEPTION_DESC), + //Specific outputs - general + @Output(value = DOCUMENT_OUTPUT, description = DOCUMENT_OUTPUT_DESC), + @Output(value = POD_LIST, description = POD_LIST_DESC), + @Output(value = POD_ARRAY, description = POD_ARRAY_DESC), + }, + responses = { + @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, + matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), + @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, + matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, description = FAILURE_DESC) + }) + + public Map execute( + //Specific input + @Param(value = HOST, description = HOST_DESC, required = true) String host, + @Param(value = AUTH_TOKEN, description = AUTH_TOKEN_DESC, required = true) String authToken, + @Param(value = NAMESPACE, description = NAMESPACE_DESC, required = true) String namespace, + //Common Inputs + @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, + @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, + @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, + @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, + @Param(value = TLS_VERSION, description = TLS_VERSION_DESC) String tlsVersion, + @Param(value = ALLOWED_CIPHERS, description = ALLOWED_CIPHERS_DESC) String allowedCiphers, + @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, + @Param(value = X509_HOSTNAME_VERIFIER, description = X509_HOSTNAME_VERIFIER_DESC) String x509HostnameVerifier, + @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, + @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, + @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, + @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, + @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, + @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESC) String executionTimeout, + @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, + @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONNECTIONS_MAX_PER_ROUTE_DESC) String connectionsMaxPerRoute, + @Param(value = CONNECTIONS_MAX_TOTAL, description = CONNECTIONS_MAX_TOTAL_DESC) String connectionsMaxTotal, + @Param(value = SESSION_COOKIES, description = SESSION_COOKIES_DESC) SerializableSessionObject sessionCookies, + @Param(value = SESSION_CONNECTION_POOL, description = SESSION_CONNECTION_POOL_DESC) GlobalSessionObject sessionConnectionPool) { + + Map result = new HashMap<>(); + + try { + + result = new HttpClientGetAction().execute( + host + GET_POD_LIST_ENDPOINT_1 + namespace + GET_POD_LIST_ENDPOINT_2, + ANONYMOUS, + EMPTY, + EMPTY, + EMPTY, + proxyHost, + proxyPort, + proxyUsername, + proxyPassword, + tlsVersion, + allowedCiphers, + trustAllRoots, + x509HostnameVerifier, + trustKeystore, + trustPassword, + keystore, + keystorePassword, + keepAlive, + connectionsMaxPerRoute, + connectionsMaxTotal, + EMPTY, + EMPTY, + AUTHORIZATION_BEARER + authToken, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + EMPTY, + connectTimeout, + EMPTY, + executionTimeout, + sessionCookies, + sessionConnectionPool + ); + + if (Integer.parseInt(result.get(RETURN_CODE)) != -1) { + if (Integer.parseInt(result.get(STATUS_CODE)) >= 200 && Integer.parseInt(result.get(STATUS_CODE)) < 300) + addPodListResults(result); + else { + setFailureCustomResults(result); + result.put(RETURN_CODE, NEGATIVE_RETURN_CODE); + result.put(EXCEPTION, result.get(RETURN_RESULT)); + result.put(RETURN_RESULT, FAILURE_RETURN_RESULT); + } + + } else + setFailureCustomResults(result); + return result; + + } catch (Exception exception) { + setFailureCommonResults(result, exception); + return result; + } + } + +} diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetTokenAction.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetTokenAction.java new file mode 100644 index 0000000000..655e80dff8 --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/actions/GetTokenAction.java @@ -0,0 +1,157 @@ +/* + * (c) Copyright 2022 Micro Focus, L.P. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.cloudslang.content.redhat.actions; + +import com.hp.oo.sdk.content.annotations.Action; +import com.hp.oo.sdk.content.annotations.Output; +import com.hp.oo.sdk.content.annotations.Param; +import com.hp.oo.sdk.content.annotations.Response; +import com.hp.oo.sdk.content.plugin.GlobalSessionObject; +import com.hp.oo.sdk.content.plugin.SerializableSessionObject; +import io.cloudslang.content.constants.ReturnCodes; +import io.cloudslang.content.httpclient.actions.HttpClientGetAction; +import io.cloudslang.content.redhat.entities.HttpInput; +import io.cloudslang.content.utils.OutputUtilities; +import org.apache.commons.codec.binary.Base64; + +import java.nio.charset.StandardCharsets; +import java.util.Map; + +import static com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType.COMPARE_EQUAL; +import static com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType.ERROR; +import static com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType.RESOLVED; +import static io.cloudslang.content.constants.OutputNames.*; +import static io.cloudslang.content.constants.ResponseNames.FAILURE; +import static io.cloudslang.content.constants.ResponseNames.SUCCESS; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_CONNECTION_POOL_DESC; +import static io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_COOKIES_DESC; + +import static io.cloudslang.content.redhat.services.OpenshiftService.processAuthTokenResult; +import static io.cloudslang.content.redhat.utils.Constants.CommonConstants.*; +import static io.cloudslang.content.redhat.utils.Descriptions.Common.*; +import static io.cloudslang.content.redhat.utils.Descriptions.GetTokenAction.AUTH_TOKEN_DESC; +import static io.cloudslang.content.redhat.utils.Descriptions.GetTokenAction.*; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.AUTH_TOKEN; + +public class GetTokenAction { + @Action(name = GET_TOKEN_NAME, + description = GET_TOKEN_NAME_DESC, + outputs = { + @Output(value = RETURN_RESULT, description = RETURN_RESULT_DESC), + @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), + @Output(value = AUTH_TOKEN, description = AUTH_TOKEN_DESC), + @Output(value = EXCEPTION, description = EXCEPTION_DESC) + }, + responses = { + @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = COMPARE_EQUAL, responseType = RESOLVED, description = SUCCESS_DESC), + @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = COMPARE_EQUAL, responseType = ERROR, description = FAILURE_DESC) + }) + public Map execute(@Param(value = HOST, required = true, description = HOST_DESC) String host, + @Param(value = USERNAME, required = true, description = USERNAME_DESC) String username, + @Param(value = PASSWORD, required = true, encrypted = true, description = PASSWORD_DESC) String password, + + @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, + @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, + @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, + @Param(value = PROXY_PASSWORD,encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, + @Param(value = TLS_VERSION, description = TLS_VERSION_DESC) String tlsVersion, + @Param(value = ALLOWED_CIPHERS, description = ALLOWED_CIPHERS_DESC) String allowedCyphers, + @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, + @Param(value = X509_HOSTNAME_VERIFIER, description = X509_HOSTNAME_VERIFIER_DESC) String x509HostnameVerifier, + @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, + @Param(value = TRUST_PASSWORD,encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, + @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, + @Param(value = KEYSTORE_PASSWORD,encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, + @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, + @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESC) String executionTimeout, + @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, + @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONNECTIONS_MAX_PER_ROUTE_DESC) String connectionsMaxPerRoute, + @Param(value = CONNECTIONS_MAX_TOTAL, description = CONNECTIONS_MAX_TOTAL_DESC) String connectionsMaxTotal, + @Param(value = SESSION_COOKIES, description = SESSION_COOKIES_DESC) SerializableSessionObject sessionCookies, + @Param(value = SESSION_CONNECTION_POOL, description = SESSION_CONNECTION_POOL_DESC) GlobalSessionObject sessionConnectionPool) { + try { + + String auth = username + COLON_PUNCTUATION + password; + byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); + + HttpInput input = HttpInput.builder() + .host(host) + .proxyHost(proxyHost) + .proxyPassword(proxyPassword) + .proxyPort(proxyPort) + .proxyPassword(proxyPassword) + .connectionsMaxPerRoute(connectionsMaxPerRoute) + .keystorePassword(keystorePassword) + .proxyUsername(proxyUsername) + .allowedCyphers(allowedCyphers) + .trustKeystore(trustKeystore) + .connectionsMaxTotal(connectionsMaxTotal) + .keepAlive(keepAlive) + .keystore(keystore) + .tlsVersion(tlsVersion) + .trustAllRoots(trustAllRoots) + .trustPassword(trustPassword) + .x509HostnameVerifier(x509HostnameVerifier) + .username(username) + .password(password) + .build(); + + Map result = new HttpClientGetAction().execute( + input.getHost() +AUTHORIZE_TOKEN_URL, + ANONYMOUS, + EMPTY_STRING, + EMPTY_STRING, + TRUE, + input.getProxyHost(), + input.getProxyPort(), + input.getProxyUsername(), + input.getProxyPassword(), + input.getTlsVersion(), + input.getAllowedCyphers(), + input.getTrustAllRoots(), + input.getX509HostnameVerifier(), + input.getTrustKeystore(), + input.getTrustPassword(), + input.getKeystore(), + input.getKeystorePassword(), + input.getKeepAlive(), + input.getConnectionsMaxPerRoute(), + input.getConnectionsMaxTotal(), + TRUE, + TRUE, + AUTHORIZATION_BASIC + new String(encodedAuth), + EMPTY_STRING, + EMPTY_STRING, + QUERY_PARAM, + TRUE, + FALSE, + input.getConnectTimeout(), + EMPTY_STRING, + input.getExecutionTimeout(), + sessionCookies, + sessionConnectionPool); + + + processAuthTokenResult(result,input,sessionCookies,sessionConnectionPool); + + return result; + } catch (Exception exception) { + return OutputUtilities.getFailureResultsMap(exception); + } + } + +} diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/entities/HttpInput.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/entities/HttpInput.java new file mode 100644 index 0000000000..68b002911d --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/entities/HttpInput.java @@ -0,0 +1,347 @@ +package io.cloudslang.content.redhat.entities; + +import com.hp.oo.sdk.content.plugin.GlobalSessionObject; + +import static org.apache.commons.lang3.StringUtils.EMPTY; + +public class HttpInput { + private String host; + private String proxyHost; + private String proxyPort; + private String proxyUsername; + private String proxyPassword; + private String tlsVersion; + private String allowedCyphers; + private String trustAllRoots; + private String x509HostnameVerifier; + private String trustKeystore; + private String trustPassword; + private String keystore; + private String keystorePassword; + private String keepAlive; + private String connectionsMaxPerRoute; + private String connectionsMaxTotal; + private String username; + private String password; + private String connectTimeout; + private String executionTimeout; + + public HttpInput(String host, String proxyHost, String proxyPort, String proxyUsername, String proxyPassword, + String tlsVersion, String allowedCyphers, String trustAllRoots, String x509HostnameVerifier, + String trustKeystore, String trustPassword, String keystore, String keystorePassword, + String keepAlive, String connectionsMaxPerRoute, String connectionsMaxTotal,String username, + String password,String connectTimeout,String executionTimeout) { + this.host = host; + this.proxyHost = proxyHost; + this.proxyPort = proxyPort; + this.proxyUsername = proxyUsername; + this.proxyPassword = proxyPassword; + this.tlsVersion = tlsVersion; + this.allowedCyphers = allowedCyphers; + this.trustAllRoots = trustAllRoots; + this.x509HostnameVerifier = x509HostnameVerifier; + this.trustKeystore = trustKeystore; + this.trustPassword = trustPassword; + this.keystore = keystore; + this.keystorePassword = keystorePassword; + this.keepAlive = keepAlive; + this.connectionsMaxPerRoute = connectionsMaxPerRoute; + this.connectionsMaxTotal = connectionsMaxTotal; + this.username = username; + this.password = password; + this.connectTimeout = connectTimeout; + this.executionTimeout = executionTimeout; + } + + public String getExecutionTimeout() { + return executionTimeout; + } + + public void setExecutionTimeout(String executionTimeout) { + this.executionTimeout = executionTimeout; + } + + public String getConnectTimeout() { + return connectTimeout; + } + + public void setConnectTimeout(String connectTimeout) { + this.connectTimeout = connectTimeout; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getProxyUsername() { + return proxyUsername; + } + + public void setProxyUsername(String proxyUsername) { + this.proxyUsername = proxyUsername; + } + + public String getProxyPassword() { + return proxyPassword; + } + + public void setProxyPassword(String proxyPassword) { + this.proxyPassword = proxyPassword; + } + + public String getTlsVersion() { + return tlsVersion; + } + + public void setTlsVersion(String tlsVersion) { + this.tlsVersion = tlsVersion; + } + + public String getAllowedCyphers() { + return allowedCyphers; + } + + public void setAllowedCyphers(String allowedCyphers) { + this.allowedCyphers = allowedCyphers; + } + + public String getTrustAllRoots() { + return trustAllRoots; + } + + public void setTrustAllRoots(String trustAllRoots) { + this.trustAllRoots = trustAllRoots; + } + + public String getX509HostnameVerifier() { + return x509HostnameVerifier; + } + + public void setX509HostnameVerifier(String x509HostnameVerifier) { + this.x509HostnameVerifier = x509HostnameVerifier; + } + + public String getTrustKeystore() { + return trustKeystore; + } + + public void setTrustKeystore(String trustKeystore) { + this.trustKeystore = trustKeystore; + } + + public String getTrustPassword() { + return trustPassword; + } + + public void setTrustPassword(String trustPassword) { + this.trustPassword = trustPassword; + } + + public String getKeystore() { + return keystore; + } + + public void setKeystore(String keystore) { + this.keystore = keystore; + } + + public String getKeystorePassword() { + return keystorePassword; + } + + public void setKeystorePassword(String keystorePassword) { + this.keystorePassword = keystorePassword; + } + + public String getKeepAlive() { + return keepAlive; + } + + public void setKeepAlive(String keepAlive) { + this.keepAlive = keepAlive; + } + + public String getConnectionsMaxPerRoute() { + return connectionsMaxPerRoute; + } + + public void setConnectionsMaxPerRoute(String connectionsMaxPerRoute) { + this.connectionsMaxPerRoute = connectionsMaxPerRoute; + } + + public String getConnectionsMaxTotal() { + return connectionsMaxTotal; + } + + public void setConnectionsMaxTotal(String connectionsMaxTotal) { + this.connectionsMaxTotal = connectionsMaxTotal; + } + + public static GetHttpInputBuilder builder() { + return new GetHttpInputBuilder(); + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getProxyHost() { + return proxyHost; + } + + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public String getProxyPort() { + return proxyPort; + } + + public void setProxyPort(String proxyPort) { + this.proxyPort = proxyPort; + } + + public static class GetHttpInputBuilder { + private String host = EMPTY; + private String connectTimeout = EMPTY; + private String proxyHost = EMPTY; + private String proxyPort = EMPTY; + private String proxyUsername = EMPTY; + private String proxyPassword = EMPTY; + private String tlsVersion = EMPTY; + private String allowedCyphers = EMPTY; + private String trustAllRoots = EMPTY; + private String x509HostnameVerifier = EMPTY; + private String trustKeystore = EMPTY; + private String trustPassword = EMPTY; + private String keystore = EMPTY; + private String keystorePassword = EMPTY; + private String keepAlive = EMPTY; + private String connectionsMaxPerRoute = EMPTY; + private String connectionsMaxTotal = EMPTY; + private String username = EMPTY; + private String password = EMPTY; + private String executionTimeout = EMPTY; + + public GetHttpInputBuilder() { + } + + public GetHttpInputBuilder host(final String host) { + this.host = host; + return this; + } + public GetHttpInputBuilder executionTimeout(final String executionTimeout) { + this.executionTimeout = executionTimeout; + return this; + } + public GetHttpInputBuilder connectTimeout(final String connectTimeout) { + this.connectTimeout = connectTimeout; + return this; + } + public GetHttpInputBuilder username(final String username) { + this.username = username; + return this; + } + public GetHttpInputBuilder password(final String password) { + this.password = password; + return this; + } + + public GetHttpInputBuilder trustKeystore(final String trustKeystore) { + this.trustKeystore = trustKeystore; + return this; + } + + public GetHttpInputBuilder keystorePassword(final String keystorePassword) { + this.keystorePassword = keystorePassword; + return this; + } + + public GetHttpInputBuilder keystore(final String keystore) { + this.keystore = keystore; + return this; + } + + public GetHttpInputBuilder trustPassword(final String trustPassword) { + this.trustPassword = trustPassword; + return this; + } + + public GetHttpInputBuilder proxyPassword(final String proxyPassword) { + this.proxyPassword = proxyPassword; + return this; + } + + public GetHttpInputBuilder tlsVersion(final String tlsVersion) { + this.tlsVersion = tlsVersion; + return this; + } + + public GetHttpInputBuilder proxyUsername(final String proxyUsername) { + this.proxyUsername = proxyUsername; + return this; + } + + public GetHttpInputBuilder allowedCyphers(final String allowedCyphers) { + this.allowedCyphers = allowedCyphers; + return this; + } + + public GetHttpInputBuilder trustAllRoots(final String trustAllRoots) { + this.trustAllRoots = trustAllRoots; + return this; + } + + public GetHttpInputBuilder x509HostnameVerifier(final String x509HostnameVerifier) { + this.x509HostnameVerifier = x509HostnameVerifier; + return this; + } + + public GetHttpInputBuilder keepAlive(final String keepAlive) { + this.keepAlive = keepAlive; + return this; + } + + public GetHttpInputBuilder connectionsMaxPerRoute(final String connectionsMaxPerRoute) { + this.connectionsMaxPerRoute = connectionsMaxPerRoute; + return this; + } + + public GetHttpInputBuilder connectionsMaxTotal(final String connectionsMaxTotal) { + this.connectionsMaxTotal = connectionsMaxTotal; + return this; + } + + public GetHttpInputBuilder proxyHost(final String proxyHost) { + this.proxyHost = proxyHost; + return this; + } + + public GetHttpInputBuilder proxyPort(final String proxyPort) { + this.proxyPort = proxyPort; + return this; + } + + public HttpInput build() { + return new HttpInput(host,proxyHost,proxyPort,proxyUsername,proxyPassword,tlsVersion,allowedCyphers, + trustAllRoots, x509HostnameVerifier,trustKeystore,trustPassword,keystore,keystorePassword,keepAlive, + connectionsMaxPerRoute,connectionsMaxTotal,username,password,connectTimeout,executionTimeout); + } + } +} diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/services/OpenshiftService.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/services/OpenshiftService.java new file mode 100644 index 0000000000..f01aa2e86e --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/services/OpenshiftService.java @@ -0,0 +1,230 @@ +package io.cloudslang.content.redhat.services; + +import com.google.gson.*; +import com.hp.oo.sdk.content.plugin.GlobalSessionObject; +import com.hp.oo.sdk.content.plugin.SerializableSessionObject; +import io.cloudslang.content.httpclient.actions.HttpClientPostAction; +import io.cloudslang.content.redhat.entities.HttpInput; +import com.google.gson.JsonPrimitive; +import com.jayway.jsonpath.JsonPath; +import org.apache.commons.lang3.StringUtils; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.apache.commons.lang3.exception.ExceptionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static io.cloudslang.content.constants.OutputNames.RETURN_CODE; +import static io.cloudslang.content.constants.OutputNames.RETURN_RESULT; +import static io.cloudslang.content.redhat.utils.Constants.CommonConstants.*; +import static io.cloudslang.content.redhat.utils.Constants.CommonConstants.COMMA; +import static io.cloudslang.content.redhat.utils.Descriptions.GetTokenAction.SUCCESS_DESC; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.AUTH_TOKEN; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.EXCEPTION; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.STATUS_CODE; +import static io.cloudslang.content.redhat.utils.Descriptions.GetPodList.*; +import static io.cloudslang.content.redhat.utils.Outputs.OutputNames.*; +import static io.cloudslang.content.redhat.utils.Descriptions.GetDeploymentStatus.RETURN_RESULT_MESSAGE_DESC; +import static org.apache.commons.lang3.StringUtils.EMPTY; + +public class OpenshiftService { + + public static void processAuthTokenResult(Map httpResults, HttpInput input, SerializableSessionObject sessionCookies, GlobalSessionObject sessionConnectionPool) { + + try { + String getHtmlResponse = httpResults.get(RETURN_RESULT); + Document doc = Jsoup.parse(getHtmlResponse); + String code = doc.select(FORM_INPUT).get(0).attr(VALUE); + String csrf = doc.select(FORM_INPUT).get(1).attr(VALUE); + String statusCode = httpResults.get(STATUS_CODE); + + if (StringUtils.isEmpty(statusCode) || Integer.parseInt(statusCode) < 200 || Integer.parseInt(statusCode) >= 300) { + if (StringUtils.isEmpty(httpResults.get(EXCEPTION))) + httpResults.put(EXCEPTION, httpResults.get(RETURN_RESULT)); + httpResults.put(RETURN_CODE, NEGATIVE_RETURN_CODE); + } + Map test = new HttpClientPostAction().execute( + input.getHost() + DISPLAY_TOKEN_ENDPOINT, + BASIC, + input.getUsername(), + input.getPassword(), + EMPTY_STRING, + input.getProxyHost(), + input.getProxyPort(), + input.getProxyUsername(), + input.getPassword(), + input.getTlsVersion(), + input.getAllowedCyphers(), + TRUE, + input.getX509HostnameVerifier(), + input.getTrustKeystore(), + input.getTrustPassword(), + input.getKeystore(), + input.getKeystorePassword(), + input.getKeepAlive(), + input.getConnectionsMaxPerRoute(), + input.getConnectionsMaxTotal(), + EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, + EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, + EMPTY_STRING, + EMPTY_STRING, + CODE + EQUAL + code + CSRF + EQUAL + csrf, + TRUE, EMPTY_STRING, + EMPTY_STRING, + CONTENT_TYPE_FORM, + EMPTY_STRING, input.getConnectTimeout(), + EMPTY_STRING, input.getExecutionTimeout(), + sessionCookies, sessionConnectionPool); + + String postHtmlResponse = test.get(RETURN_RESULT); + Document second_response = Jsoup.parse(postHtmlResponse); + if (!StringUtils.isEmpty(postHtmlResponse)) { + httpResults.put(RETURN_RESULT, SUCCESS_DESC); + httpResults.put(AUTH_TOKEN, second_response.select(CODE).get(0).text()); + } + + if (StringUtils.isEmpty(statusCode) || Integer.parseInt(statusCode) < 200 || Integer.parseInt(statusCode) >= 300) { + if (StringUtils.isEmpty(httpResults.get(EXCEPTION))) + httpResults.put(EXCEPTION, httpResults.get(RETURN_RESULT)); + httpResults.put(RETURN_CODE, NEGATIVE_RETURN_CODE); + } + + + } catch (IndexOutOfBoundsException e) { + httpResults.put(EXCEPTION, httpResults.get(RETURN_RESULT)); + httpResults.put(RETURN_CODE, NEGATIVE_RETURN_CODE); + } + } + + public static void processHttpResult(Map httpResults) { + + String statusCode = httpResults.get(STATUS_CODE); + + if (StringUtils.isEmpty(statusCode) || Integer.parseInt(statusCode) < 200 || Integer.parseInt(statusCode) >= 300) { + if (StringUtils.isEmpty(httpResults.get(EXCEPTION))) + httpResults.put(EXCEPTION, httpResults.get(RETURN_RESULT)); + httpResults.put(RETURN_CODE, NEGATIVE_RETURN_CODE); + } + } + + public static void addPodListResults(Map httpResults) { + try { + String returnResult = httpResults.get(RETURN_RESULT); + if (!(returnResult.isEmpty())) { + + //populate the document output + httpResults.put(DOCUMENT_OUTPUT, returnResult); + + //parse the API response, extract required information construct the podList and podArray outputs + JsonObject jsonResponse = JsonParser.parseString(httpResults.get(RETURN_RESULT)).getAsJsonObject(); + JsonArray podArray = jsonResponse.getAsJsonArray(PROPERTY_ITEMS); + StringBuilder podList = new StringBuilder(); + List podPairList = new ArrayList<>(); + for (JsonElement pod : podArray) { + JsonObject podObject = new JsonObject(); + podObject.add(PROPERTY_NAME, pod.getAsJsonObject().get(PROPERTY_METADATA).getAsJsonObject().get(PROPERTY_NAME)); + podObject.add(PROPERTY_UID, pod.getAsJsonObject().get(PROPERTY_METADATA).getAsJsonObject().get(PROPERTY_UID)); + podPairList.add(podObject); + podList.append(pod.getAsJsonObject().get(PROPERTY_METADATA).getAsJsonObject().get(PROPERTY_UID).getAsString()); + podList.append(COMMA); + } + + //remove the last comma from the podList value + podList.deleteCharAt(podList.length() - 1); + + //populate the podList and podArray outputs + httpResults.put(POD_LIST, podList.toString()); + httpResults.put(POD_ARRAY, podPairList.toString()); + + //overwrite the returnResult output with a success message + httpResults.put(RETURN_RESULT, SUCCESSFUL_RETURN_RESULT); + + } + + } catch (Exception e) { + //in case an error arises during the parsing, populate the custom outputs with empty values + setFailureCustomResults(httpResults); + + throw new RuntimeException(e); + } + + } + + public static void setFailureCustomResults(Map httpResults) { + httpResults.put(POD_LIST, EMPTY); + httpResults.put(POD_ARRAY, EMPTY); + httpResults.put(DOCUMENT_OUTPUT, EMPTY); + } + + public static void setFailureCommonResults(Map httpResults, Exception e) { + httpResults.put(RETURN_CODE, NEGATIVE_RETURN_CODE); + httpResults.put(RETURN_RESULT, e.getMessage()); + httpResults.put(EXCEPTION, ExceptionUtils.getStackTrace(e)); + } + + public static void processHttpGetDeploymentStatusResult(Map httpResults) { + + //Process the return result output + String returnResult = httpResults.get(RETURN_RESULT); + try { + + if (!(returnResult.isEmpty())) { + httpResults.put(DOCUMENT_OUTPUT, returnResult); + + JsonObject jsonResponse = JsonParser.parseString(httpResults.get(RETURN_RESULT)).getAsJsonObject(); + + //Kind output + JsonPrimitive tmpResponse = (JsonPrimitive) jsonResponse.get(KIND_OUTPUT); + httpResults.put(KIND_OUTPUT, tmpResponse.toString()); + + //Name outputs + String namePath = "$.metadata.name"; + String namePathResponse = JsonPath.read(jsonResponse.toString(), namePath); + httpResults.put(NAME_OUTPUT, namePathResponse); + + //Namespace outputs + String namespacePath = "$.metadata.namespace"; + String namespacePathResponse = JsonPath.read(jsonResponse.toString(), namespacePath); + httpResults.put(NAMESPACE_OUTPUT, namespacePathResponse); + + //Uid outputs + String uidPath = "$.metadata.uid"; + String uidPathResponse = JsonPath.read(jsonResponse.toString(), uidPath); + httpResults.put(UID_OUTPUT, uidPathResponse); + + //ObservedGeneration output + String observedGenerationPath = "$.status.observedGeneration"; + Integer observedGenerationPathResponse = JsonPath.read(jsonResponse.toString(), observedGenerationPath); + httpResults.put(OBSERVED_GENERATION_OUTPUT, observedGenerationPathResponse.toString()); + + //Replicas output + String replicasPath = "$.status.replicas"; + Integer replicasPathResponse = JsonPath.read(jsonResponse.toString(), replicasPath); + httpResults.put(REPLICAS_OUTPUT, replicasPathResponse.toString()); + + //UpdatedReplicas output + String updatedReplicasPath = "$.status.updatedReplicas"; + Integer updatedReplicasPathResponse = JsonPath.read(jsonResponse.toString(), updatedReplicasPath); + httpResults.put(UPDATED_REPLICAS_OUTPUT, updatedReplicasPathResponse.toString()); + + //UnavailableReplicas output + String unavailableReplicasPath = "$.status.unavailableReplicas"; + Integer unavailableReplicasPathResponse = JsonPath.read(jsonResponse.toString(), unavailableReplicasPath); + httpResults.put(UNAVAILABLE_REPLICAS_OUTPUT, unavailableReplicasPathResponse.toString()); + + //Conditions output + String conditionsPath = "$.status.conditions"; + List conditionsPathResponse = JsonPath.read(jsonResponse.toString(), conditionsPath); + httpResults.put(CONDITIONS_OUTPUT, conditionsPathResponse.toString()); + + httpResults.put(RETURN_RESULT, RETURN_RESULT_MESSAGE_DESC); + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Constants.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Constants.java new file mode 100644 index 0000000000..79db6bf1ab --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Constants.java @@ -0,0 +1,106 @@ +/* + * (c) Copyright 2022 Micro Focus + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available 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. + */ +/* + * (c) Copyright 2022 Micro Focus + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.cloudslang.content.redhat.utils; + +public final class Constants { + + public static final class CommonConstants { + + //Inputs + public static final String HOST = "host"; + public static final String USERNAME = "username"; + public static final String PASSWORD = "password"; + public static final String NAME = "name"; + public static final String NAMESPACE = "namespace"; + public static final String DEPLOYMENT = "deployment"; + public static final String PROXY_HOST = "proxyHost"; + public static final String PROXY_PORT = "proxyPort"; + public static final String PROXY_USERNAME = "proxyUsername"; + public static final String PROXY_PASSWORD = "proxyPassword"; + public static final String TLS_VERSION = "tlsVersion"; + public static final String ALLOWED_CIPHERS = "allowedCiphers"; + public static final String TRUST_ALL_ROOTS = "trustAllRoots"; + public static final String X509_HOSTNAME_VERIFIER = "x509HostnameVerifier"; + public static final String TRUST_KEYSTORE = "trustKeystore"; + public static final String TRUST_PASSWORD = "trustPassword"; + public static final String KEYSTORE = "keystore"; + public static final String KEYSTORE_PASSWORD = "keystorePassword"; + public static final String CONNECT_TIMEOUT = "connectTimeout"; + public static final String EXECUTION_TIMEOUT = "executionTimeout"; + public static final String KEEP_ALIVE = "keepAlive"; + public static final String CONNECTIONS_MAX_PER_ROUTE = "connectionsMaxPerRoute"; + public static final String CONNECTIONS_MAX_TOTAL = "connectionsMaxTotal"; + public static final String SESSION_COOKIES = "httpClientCookieSession"; + public static final String SESSION_CONNECTION_POOL = "httpClientPoolingConnectionManager"; + + // + public static final String BASIC = "BASIC"; + public static final String APPLICATION_JSON = "application/json"; + public static final String CONTENT_TYPE = "Content-Type:"; + public static final String TRUE = "true"; + public static final String FALSE = "FALSE"; + public static final String EMPTY_STRING = ""; + public static final String AUTHORIZATION_BEARER = "Authorization: Bearer "; + public static final String AUTHORIZATION_BASIC = "Authorization: Basic "; + public static final String ANONYMOUS = "Anonymous"; + + //Other + public static final String PROTOCOL_DELIMITER = "://"; + public static final String FORWARD_SLASH = "/"; + public static final String COMMA = ","; + public static final String EQUALS = "="; + public static final String SEMICOLON = ";"; + + // Create Deployment + public static final String DEFINITION = "definition"; + + + // endpoints + public static final String CREATE_DEPLOYMENT_ENDPOINT(String namespace) { + return "/apis/apps/v1/namespaces/" + namespace + "/deployments"; + } + + public static final String APPS_V1_NAMESPACES = "/apis/apps/v1/namespaces/"; + public static final String DEPLOYMENTS = "/deployments/"; + + //query for authorization + public static final String QUERY_PARAM = "response_type=code&client_id=openshift-browser-client"; + public static final String AUTHORIZE_TOKEN_URL = "/oauth/authorize"; + public static final String FORM_INPUT = "form > input"; + public static final String VALUE = "value"; + public static final String CODE = "code"; + public static final String CSRF = "&csrf"; + public static final String EQUAL = "="; + public static final String CONTENT_TYPE_FORM = "application/x-www-form-urlencoded"; + public static final String DISPLAY_TOKEN_ENDPOINT = "/oauth/token/display"; + public static final String COLON_PUNCTUATION = ":"; + } + +} + diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Descriptions.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Descriptions.java new file mode 100644 index 0000000000..0a645b7c7d --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Descriptions.java @@ -0,0 +1,194 @@ +/* + * (c) Copyright 2022 Micro Focus, L.P. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.cloudslang.content.redhat.utils; + +public class Descriptions { + + public static class Common { + + public static final String RETURN_CODE_DESC = "0 if success, -1 if failure."; + public static final String STATUS_CODE_DESC = "The HTTP status code for Openshift API request."; + + public static final String HOST_DESC = "The OpenShift hostname."; + public static final String AUTH_TOKEN_DESC = "Token used to authenticate to the Openshift environment."; + public static final String PROXY_HOST_DESC = "The proxy server used to access the web site."; + public static final String PROXY_PORT_DESC = "The proxy server port." + + "Default value: 8080."; + public static final String PROXY_USERNAME_DESC = "The username used when connecting to the proxy."; + public static final String PROXY_PASSWORD_DESC = "The proxy server password associated with the 'proxyUsername'" + + " input value."; + public static final String TLS_VERSION_DESC = "The version of TLS to use. The value of this input will be ignored if 'protocol'" + + "is set to 'HTTP'. This capability is provided “as is”, please see product documentation for further information." + + "Valid values: TLSv1, TLSv1.1, TLSv1.2. \n" + + "Default value: TLSv1.2. \n"; + public static final String ALLOWED_CIPHERS_DESC = "A list of ciphers to use. The value of this input will be ignored " + + "if 'tlsVersion' does " + + "not contain 'TLSv1.2'. This capability is provided “as is”, please see product documentation for further security considerations." + + "In order to connect successfully to the target host, it should accept at least one of the following ciphers. If this is not the case, it is " + + "the user's responsibility to configure the host accordingly or to update the list of allowed ciphers. \n" + + "Default value: TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, " + + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, " + + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, " + + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, " + + "TLS_RSA_WITH_AES_128_CBC_SHA256."; + public static final String TRUST_ALL_ROOTS_DESC = "Specifies whether to enable weak security over SSL/TSL. " + + "A certificate is trusted even if no trusted certification authority issued it."; + public static final String X509_HOSTNAME_VERIFIER_DESC = "Specifies the way the server hostname must match a domain name in " + + "the subject's Common Name (CN) or subjectAltName field of the X.509 certificate. Set this to " + + "\"allow_all\" to skip any checking. For the value \"browser_compatible\" the hostname verifier " + + "works the same way as Curl and Firefox. The hostname must match either the first CN, or any of " + + "the subject-alts. A wildcard can occur in the CN, and in any of the subject-alts. The only " + + "difference between \"browser_compatible\" and \"strict\" is that a wildcard (such as \"*.foo.com\") " + + "with \"browser_compatible\" matches all subdomains, including \"a.b.foo.com\"."; + public static final String TRUST_KEYSTORE_DESC = "The pathname of the Java TrustStore file. This contains " + + "certificates from other parties that you expect to communicate with, or from Certificate Authorities" + + " that you trust to identify other parties. If the protocol (specified by the 'url') is not 'https' " + + "or if trustAllRoots is 'true' this input is ignored. \n " + + "Format: Java KeyStore (JKS)"; + public static final String TRUST_PASSWORD_DESC = "The password associated with the TrustStore file. If " + + "trustAllRoots is false and trustKeystore is empty, trustPassword default will be supplied."; + public static final String KEYSTORE_DESC = "The pathname of the Java KeyStore file. You only need this if " + + "the server requires client authentication. If the protocol (specified by the 'url') is not 'https' " + + "or if trustAllRoots is 'true' this input is ignored. Format: Java KeyStore (JKS)"; + public static final String KEYSTORE_PASSWORD_DESC = "The password associated with the KeyStore file. If " + + "trustAllRoots is false and keystore is empty, keystorePassword default will be supplied."; + public static final String CONNECT_TIMEOUT_DESC = "The time to wait for a connection to be established, " + + "in seconds. A timeout value of '0' represents an infinite timeout."; + public static final String EXECUTION_TIMEOUT_DESC = "The amount of time (in seconds) to allow the client to complete the execution " + + "of an API call. A value of '0' disables this feature. \n" + + "Default: 60 \n"; + public static final String KEEP_ALIVE_DESC = "Specifies whether to create a shared connection that will be " + + "used in subsequent calls. If keepAlive is false, the already open connection will be used and after" + + "execution it will close it."; + public static final String CONNECTIONS_MAX_PER_ROUTE_DESC = "The maximum limit of connections on a per route basis."; + public static final String CONNECTIONS_MAX_TOTAL_DESC = "The maximum limit of connections in total."; + + } + + public static class GetTokenAction { + + public static final String GET_TOKEN_NAME = "Get Token"; + public static final String GET_TOKEN_NAME_DESC = "Get Authorization Token"; + public static final String RETURN_RESULT_DESC = "The authorization token for Openshift."; + public static final String AUTH_TOKEN_DESC = "Generated authentication token."; + public static final String EXCEPTION_DESC = "An error message in case there was an error while generating the " + + "token."; + public static final String USERNAME_DESC = "The name of the user who is logging in to Openshift."; + public static final String PASSWORD_DESC = "The password used by the user to log in to Openshift."; + + public static final String SUCCESS_DESC = "Token generated successfully."; + public static final String FAILURE_DESC = "There was an error while trying to retrieve token."; + + } + + public static class CreateDeploymentAction { + public static final String CREATE_DEPLOYMENT = "Create Deployment"; + public static final String CREATE_DEPLOYMENT_DESCRIPTION = "This operation creates a deployment with the inputs from the user."; + public static final String AUTH_TOKEN_DESCRIPTION = "Token used to authenticate to the openshift environment."; + public static final String NAMESPACE_DESCRIPTION = "The namespace in which the deployment will be created."; + public static final String DEFINITION_DESCRIPTION = "YAML or JSON definitions."; + public static final String RETURN_RESULT_DESC = "The authorization token for Openshift."; + public static final String EXCEPTION_DESC = "An error message in case there was an error"; + public static final String SUCCESS_DESC = "Deployment created successfully."; + public static final String FAILURE_DESC = "There was an error while trying to create the deployment."; + } + + public static class DeleteDeployment { + + public static final String DELETE_DEPLOYMENT_NAME = "Delete Deployment"; + public static final String DELETE_DEPLOYMENT_DESC = "Deletes the deployment from namespace."; + + public static final String NAMESPACE_DESC = "Namespace to delete the deployment from."; + public static final String DEPLOYMENT_DESC = "Name of the deployment to delete."; + public static final String RETURN_RESULT_DESC = "The deployment was successfully deleted."; + public static final String EXCEPTION_DESC = "An error message in case there was an error while deleting the deployment."; + + public static final String SUCCESS_DESC = "Deployment was successfully deleted."; + public static final String FAILURE_DESC = "There was an error while trying to delete the deployment."; + + } + + public static class GetDeploymentStatus { + + public static final String GET_DEPLOYMENT_STATUS = "Get Deployment Status"; + public static final String GET_DEPLOYMENT_STATUS_DESC = "Read the status of the specified deployment."; + + public static final String NAME_DESC = "The name of the deployment."; + public static final String NAMESPACE_DESC = "The object name and auth scope, such as for teams and projects."; + + //Outputs + public static final String RETURN_RESULT_DESC = "A suggestive message both for the case of success and for the " + + "case of failure."; + public static final String RETURN_RESULT_MESSAGE_DESC = "The request was made successfully, please analyze the " + + "entire response generated by the API call in the document output as a json format."; + public static final String STATUS_CODE_DESC = "The status code of the request."; + public static final String EXCEPTION_DESC = "An error message in case there was an error while reading the " + + "deployment status."; + + public static final String SUCCESS_DESC = "The request to read the status of the specified deployment was made " + + "successfully."; + public static final String FAILURE_DESC = "There was an error while trying to get the status of the deployment."; + + //Specific outputs + + //Get Deployment Status + public static final String NAME_OUTPUT_DESC = "The deployment name."; + public static final String NAMESPACE_OUTPUT_DESC = "The deployment namespace."; + public static final String UID_OUTPUT_DESC = "The deployment uid."; + public static final String KIND_OUTPUT_DESC = "The deployment kind."; + public static final String OBSERVED_GENERATION_OUTPUT_DESC = "The observedGeneration status property of the deployment."; + public static final String REPLICAS_OUTPUT_DESC = "The replicas status property of the deployment."; + public static final String UPDATED_REPLICAS_OUTPUT_DESC = "The updatedReplicas status property of the deployment."; + public static final String UNAVAILABLE_REPLICAS_OUTPUT_DESC = "The unavailableReplicas status property of the deployment."; + public static final String CONDITIONS_OUTPUT_DESC = "The conditions status properties of the deployment in the json format."; + + public static final String DOCUMENT_OUTPUT_DESC = "All the information related to a specific deployment in the " + + "json format."; + + //API + public static final String GET_DEPLOYMENT_STATUS_ENDPOINT_1 = "/apis/apps/v1/namespaces/"; + public static final String GET_DEPLOYMENT_STATUS_ENDPOINT_2 = "/deployments/"; + public static final String GET_DEPLOYMENT_STATUS_ENDPOINT_3 = "/status"; + + } + + public static class GetPodList { + public static final String GET_POD_LIST = "Get Pod List"; + public static final String GET_POD_LIST_DESC = "List objects of Pod type."; + public static final String NAMESPACE_DESC = "The object name and auth scope, such as for teams and projects."; + public static final String RETURN_RESULT_DESC = "A suggestive message both for the case of success and for the " + + "case of failure."; + public static final String STATUS_CODE_DESC = "The status code of the request."; + public static final String EXCEPTION_DESC = "An error message in case there was an error while retrieving the Pod list."; + public static final String SUCCESS_DESC = "The retrieval of the pod list was made successfully."; + public static final String FAILURE_DESC = "There was an error while trying to retrieve the pod list."; + public static final String POD_LIST_DESC = "The comma separated list of pod uids."; + public static final String POD_ARRAY_DESC = "The list containing pairs of pod name and uids."; + + public static final String DOCUMENT_OUTPUT_DESC = "All the information related to a the pod list in json format."; + + //API + public static final String GET_POD_LIST_ENDPOINT_1 = "/api/v1/namespaces/"; + public static final String GET_POD_LIST_ENDPOINT_2 = "/pods"; + public static final String NEGATIVE_RETURN_CODE = "-1"; + public static final String SUCCESSFUL_RETURN_RESULT = "The Pod list was returned successfully."; + public static final String FAILURE_RETURN_RESULT = "An issue was encountered during your query. Please check the exception output for more information."; + public static final String PROPERTY_NAME = "name"; + public static final String PROPERTY_UID = "uid"; + public static final String PROPERTY_ITEMS = "items"; + public static final String PROPERTY_METADATA = "metadata"; + } +} diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Outputs.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Outputs.java new file mode 100644 index 0000000000..d697dffe02 --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Outputs.java @@ -0,0 +1,47 @@ +/* + * (c) Copyright 2021 Micro Focus, L.P. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License v2.0 which accompany this distribution. + * + * The Apache License is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.cloudslang.content.redhat.utils; + +import io.cloudslang.content.constants.OutputNames; + +public final class Outputs extends OutputNames { + + public static class OutputNames { + + public static final String STATUS_CODE = "statusCode"; + public static final String EXCEPTION = "exception"; + public static final String AUTH_TOKEN = "authToken"; + + //Get Deployment Status + public static final String NAME_OUTPUT = "name"; + public static final String DOCUMENT_OUTPUT = "document"; + public static final String NAMESPACE_OUTPUT = "namespace"; + public static final String UID_OUTPUT = "uid"; + public static final String KIND_OUTPUT = "kind"; + public static final String OBSERVED_GENERATION_OUTPUT = "observedGeneration"; + public static final String REPLICAS_OUTPUT = "replicas"; + public static final String UPDATED_REPLICAS_OUTPUT = "updatedReplicas"; + public static final String UNAVAILABLE_REPLICAS_OUTPUT = "unavailableReplicas"; + public static final String CONDITIONS_OUTPUT = "conditions"; + + //Get Pod List + + public static final String POD_LIST = "podList"; + public static final String POD_ARRAY = "podArray"; + + } +} + diff --git a/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Utils.java b/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Utils.java new file mode 100644 index 0000000000..69c6b55402 --- /dev/null +++ b/cs-openshift/src/main/java/io/cloudslang/content/redhat/utils/Utils.java @@ -0,0 +1,5 @@ +package io.cloudslang.content.redhat.utils; + +public class Utils { + +} diff --git a/pom.xml b/pom.xml index 03a9ad3b63..f711267340 100644 --- a/pom.xml +++ b/pom.xml @@ -359,6 +359,7 @@ cs-winrm cs-xml cs-cyberark + cs-openshift