Skip to content

Commit

Permalink
Upstream Changes fixes of OP-22069 to OES-1.33.x (#50)
Browse files Browse the repository at this point in the history
* OP-22069: using HttpMethod Enum.

* OP-22069: javadoc.
  • Loading branch information
rahul-chekuri authored Jun 27, 2024
1 parent 6af073c commit bdb984d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.netflix.spinnaker.fiat.model.resources.Role;
import com.netflix.spinnaker.orca.api.preconfigured.jobs.PreconfiguredStageParameter;
import com.netflix.spinnaker.orca.webhook.http.HttpMethod;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -29,7 +30,6 @@
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpMethod;

@ConfigurationProperties("webhook")
@Data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2024 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.orca.webhook.http;

import java.util.HashMap;
import java.util.Map;
import org.springframework.lang.Nullable;

/**
* OP-22069: As part of CVE fixes, spring-web has been upgraded. In the new package, HttpMethod is
* converted to a class from Enum. Due to this change, ObjectMapper cannot
* serialize @org.springframework.http.HttpMethod, so we created this Enum to support serialization.
*/
public enum HttpMethod {
GET,
HEAD,
POST,
PUT,
PATCH,
DELETE,
OPTIONS,
TRACE;

private static final Map<String, HttpMethod> mappings = new HashMap<>(16);

static {
for (HttpMethod httpMethod : values()) {
mappings.put(httpMethod.name(), httpMethod);
}
}

/**
* Resolve the given method value to an {@code HttpMethod}.
*
* @param method the method value as a String
* @return the corresponding {@code HttpMethod}, or {@code null} if not found
* @since 4.2.4
*/
@Nullable
public static HttpMethod resolve(@Nullable String method) {
return (method != null ? mappings.get(method) : null);
}

/**
* Determine whether this {@code HttpMethod} matches the given method value.
*
* @param method the HTTP method as a String
* @return {@code true} if it matches, {@code false} otherwise
* @since 4.2.4
*/
public boolean matches(String method) {
return name().equals(method);
}
}

0 comments on commit bdb984d

Please sign in to comment.