software.amazon.awssdk.services.codepipeline.model.WebhookDefinition Maven / Gradle / Ivy
Show all versions of codepipeline Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.services.codepipeline.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Represents information about a webhook and its definition.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class WebhookDefinition implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField NAME_FIELD = SdkField. builder(MarshallingType.STRING).memberName("name")
.getter(getter(WebhookDefinition::name)).setter(setter(Builder::name))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("name").build()).build();
private static final SdkField TARGET_PIPELINE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("targetPipeline").getter(getter(WebhookDefinition::targetPipeline))
.setter(setter(Builder::targetPipeline))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("targetPipeline").build()).build();
private static final SdkField TARGET_ACTION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("targetAction").getter(getter(WebhookDefinition::targetAction)).setter(setter(Builder::targetAction))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("targetAction").build()).build();
private static final SdkField> FILTERS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("filters")
.getter(getter(WebhookDefinition::filters))
.setter(setter(Builder::filters))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("filters").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(WebhookFilterRule::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField AUTHENTICATION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("authentication").getter(getter(WebhookDefinition::authenticationAsString))
.setter(setter(Builder::authentication))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("authentication").build()).build();
private static final SdkField AUTHENTICATION_CONFIGURATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("authenticationConfiguration")
.getter(getter(WebhookDefinition::authenticationConfiguration))
.setter(setter(Builder::authenticationConfiguration))
.constructor(WebhookAuthConfiguration::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("authenticationConfiguration")
.build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(NAME_FIELD,
TARGET_PIPELINE_FIELD, TARGET_ACTION_FIELD, FILTERS_FIELD, AUTHENTICATION_FIELD, AUTHENTICATION_CONFIGURATION_FIELD));
private static final Map> SDK_NAME_TO_FIELD = memberNameToFieldInitializer();
private static final long serialVersionUID = 1L;
private final String name;
private final String targetPipeline;
private final String targetAction;
private final List filters;
private final String authentication;
private final WebhookAuthConfiguration authenticationConfiguration;
private WebhookDefinition(BuilderImpl builder) {
this.name = builder.name;
this.targetPipeline = builder.targetPipeline;
this.targetAction = builder.targetAction;
this.filters = builder.filters;
this.authentication = builder.authentication;
this.authenticationConfiguration = builder.authenticationConfiguration;
}
/**
*
* The name of the webhook.
*
*
* @return The name of the webhook.
*/
public final String name() {
return name;
}
/**
*
* The name of the pipeline you want to connect to the webhook.
*
*
* @return The name of the pipeline you want to connect to the webhook.
*/
public final String targetPipeline() {
return targetPipeline;
}
/**
*
* The name of the action in a pipeline you want to connect to the webhook. The action must be from the source
* (first) stage of the pipeline.
*
*
* @return The name of the action in a pipeline you want to connect to the webhook. The action must be from the
* source (first) stage of the pipeline.
*/
public final String targetAction() {
return targetAction;
}
/**
* For responses, this returns true if the service returned a value for the Filters property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasFilters() {
return filters != null && !(filters instanceof SdkAutoConstructList);
}
/**
*
* A list of rules applied to the body/payload sent in the POST request to a webhook URL. All defined rules must
* pass for the request to be accepted and the pipeline started.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasFilters} method.
*
*
* @return A list of rules applied to the body/payload sent in the POST request to a webhook URL. All defined rules
* must pass for the request to be accepted and the pipeline started.
*/
public final List filters() {
return filters;
}
/**
*
* Supported options are GITHUB_HMAC, IP, and UNAUTHENTICATED.
*
*
*
* When creating CodePipeline webhooks, do not use your own credentials or reuse the same secret token across
* multiple webhooks. For optimal security, generate a unique secret token for each webhook you create. The secret
* token is an arbitrary string that you provide, which GitHub uses to compute and sign the webhook payloads sent to
* CodePipeline, for protecting the integrity and authenticity of the webhook payloads. Using your own credentials
* or reusing the same token across multiple webhooks can lead to security vulnerabilities.
*
*
*
* If a secret token was provided, it will be redacted in the response.
*
*
*
* -
*
* For information about the authentication scheme implemented by GITHUB_HMAC, see Securing your webhooks on the GitHub Developer
* website.
*
*
* -
*
* IP rejects webhooks trigger requests unless they originate from an IP address in the IP range whitelisted in the
* authentication configuration.
*
*
* -
*
* UNAUTHENTICATED accepts all webhook trigger requests regardless of origin.
*
*
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #authentication}
* will return {@link WebhookAuthenticationType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is
* available from {@link #authenticationAsString}.
*
*
* @return Supported options are GITHUB_HMAC, IP, and UNAUTHENTICATED.
*
* When creating CodePipeline webhooks, do not use your own credentials or reuse the same secret token
* across multiple webhooks. For optimal security, generate a unique secret token for each webhook you
* create. The secret token is an arbitrary string that you provide, which GitHub uses to compute and sign
* the webhook payloads sent to CodePipeline, for protecting the integrity and authenticity of the webhook
* payloads. Using your own credentials or reusing the same token across multiple webhooks can lead to
* security vulnerabilities.
*
*
*
* If a secret token was provided, it will be redacted in the response.
*
*
*
* -
*
* For information about the authentication scheme implemented by GITHUB_HMAC, see Securing your webhooks on the GitHub Developer
* website.
*
*
* -
*
* IP rejects webhooks trigger requests unless they originate from an IP address in the IP range whitelisted
* in the authentication configuration.
*
*
* -
*
* UNAUTHENTICATED accepts all webhook trigger requests regardless of origin.
*
*
* @see WebhookAuthenticationType
*/
public final WebhookAuthenticationType authentication() {
return WebhookAuthenticationType.fromValue(authentication);
}
/**
*
* Supported options are GITHUB_HMAC, IP, and UNAUTHENTICATED.
*
*
*
* When creating CodePipeline webhooks, do not use your own credentials or reuse the same secret token across
* multiple webhooks. For optimal security, generate a unique secret token for each webhook you create. The secret
* token is an arbitrary string that you provide, which GitHub uses to compute and sign the webhook payloads sent to
* CodePipeline, for protecting the integrity and authenticity of the webhook payloads. Using your own credentials
* or reusing the same token across multiple webhooks can lead to security vulnerabilities.
*
*
*
* If a secret token was provided, it will be redacted in the response.
*
*
*
* -
*
* For information about the authentication scheme implemented by GITHUB_HMAC, see Securing your webhooks on the GitHub Developer
* website.
*
*
* -
*
* IP rejects webhooks trigger requests unless they originate from an IP address in the IP range whitelisted in the
* authentication configuration.
*
*
* -
*
* UNAUTHENTICATED accepts all webhook trigger requests regardless of origin.
*
*
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #authentication}
* will return {@link WebhookAuthenticationType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is
* available from {@link #authenticationAsString}.
*
*
* @return Supported options are GITHUB_HMAC, IP, and UNAUTHENTICATED.
*
* When creating CodePipeline webhooks, do not use your own credentials or reuse the same secret token
* across multiple webhooks. For optimal security, generate a unique secret token for each webhook you
* create. The secret token is an arbitrary string that you provide, which GitHub uses to compute and sign
* the webhook payloads sent to CodePipeline, for protecting the integrity and authenticity of the webhook
* payloads. Using your own credentials or reusing the same token across multiple webhooks can lead to
* security vulnerabilities.
*
*
*
* If a secret token was provided, it will be redacted in the response.
*
*
*
* -
*
* For information about the authentication scheme implemented by GITHUB_HMAC, see Securing your webhooks on the GitHub Developer
* website.
*
*
* -
*
* IP rejects webhooks trigger requests unless they originate from an IP address in the IP range whitelisted
* in the authentication configuration.
*
*
* -
*
* UNAUTHENTICATED accepts all webhook trigger requests regardless of origin.
*
*
* @see WebhookAuthenticationType
*/
public final String authenticationAsString() {
return authentication;
}
/**
*
* Properties that configure the authentication applied to incoming webhook trigger requests. The required
* properties depend on the authentication type. For GITHUB_HMAC, only the SecretToken
property must be
* set. For IP, only the AllowedIPRange
property must be set to a valid CIDR range. For
* UNAUTHENTICATED, no properties can be set.
*
*
* @return Properties that configure the authentication applied to incoming webhook trigger requests. The required
* properties depend on the authentication type. For GITHUB_HMAC, only the SecretToken
property
* must be set. For IP, only the AllowedIPRange
property must be set to a valid CIDR range. For
* UNAUTHENTICATED, no properties can be set.
*/
public final WebhookAuthConfiguration authenticationConfiguration() {
return authenticationConfiguration;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(name());
hashCode = 31 * hashCode + Objects.hashCode(targetPipeline());
hashCode = 31 * hashCode + Objects.hashCode(targetAction());
hashCode = 31 * hashCode + Objects.hashCode(hasFilters() ? filters() : null);
hashCode = 31 * hashCode + Objects.hashCode(authenticationAsString());
hashCode = 31 * hashCode + Objects.hashCode(authenticationConfiguration());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof WebhookDefinition)) {
return false;
}
WebhookDefinition other = (WebhookDefinition) obj;
return Objects.equals(name(), other.name()) && Objects.equals(targetPipeline(), other.targetPipeline())
&& Objects.equals(targetAction(), other.targetAction()) && hasFilters() == other.hasFilters()
&& Objects.equals(filters(), other.filters())
&& Objects.equals(authenticationAsString(), other.authenticationAsString())
&& Objects.equals(authenticationConfiguration(), other.authenticationConfiguration());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("WebhookDefinition").add("Name", name()).add("TargetPipeline", targetPipeline())
.add("TargetAction", targetAction()).add("Filters", hasFilters() ? filters() : null)
.add("Authentication", authenticationAsString())
.add("AuthenticationConfiguration", authenticationConfiguration()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "name":
return Optional.ofNullable(clazz.cast(name()));
case "targetPipeline":
return Optional.ofNullable(clazz.cast(targetPipeline()));
case "targetAction":
return Optional.ofNullable(clazz.cast(targetAction()));
case "filters":
return Optional.ofNullable(clazz.cast(filters()));
case "authentication":
return Optional.ofNullable(clazz.cast(authenticationAsString()));
case "authenticationConfiguration":
return Optional.ofNullable(clazz.cast(authenticationConfiguration()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
@Override
public final Map> sdkFieldNameToField() {
return SDK_NAME_TO_FIELD;
}
private static Map> memberNameToFieldInitializer() {
Map> map = new HashMap<>();
map.put("name", NAME_FIELD);
map.put("targetPipeline", TARGET_PIPELINE_FIELD);
map.put("targetAction", TARGET_ACTION_FIELD);
map.put("filters", FILTERS_FIELD);
map.put("authentication", AUTHENTICATION_FIELD);
map.put("authenticationConfiguration", AUTHENTICATION_CONFIGURATION_FIELD);
return Collections.unmodifiableMap(map);
}
private static Function