-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KubernetesAttributesExtractor is not testing anything #977
Changes from all commits
61dbc7e
29e2080
feac0ed
cce4b66
dccac49
942c376
5fd578c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,22 +28,25 @@ | |
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class KubernetesAttributesExtractor implements AttributeExtractor<HasMetadata> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(KubernetesAttributesExtractor.class); | ||
|
||
public static final String KIND = "kind"; | ||
public static final String NAME = "name"; | ||
public static final String NAMESPACE = "namespace"; | ||
|
||
private static final String VERSION_GROUP = "(?<version>[a-zA-z0-9-_\\/]+)"; | ||
private static final String KIND_GROUP = "(?<kind>[^/]+)"; | ||
private static final String NAME_GROUP = "(?<name>[^/]+)"; | ||
private static final String NAMESPACE_GROUP = "(?<namespace>[^/]+)"; | ||
|
||
protected static final Pattern NAMESPACED_NAMED_PATH = Pattern.compile("/api[s]?/" + VERSION_GROUP + "/namespaces/" + NAMESPACE_GROUP + "/" + KIND_GROUP + "/" + NAME_GROUP + "[^ ]*"); | ||
protected static final Pattern NON_NAMESPACED_NAMED_PATH = Pattern.compile("/api[s]?/" + "/" + KIND_GROUP + "/" + NAME_GROUP + "[^ ]*"); | ||
private static final String API_GROUP = "/api[s]?(/extensions)?"; | ||
private static final String VERSION_GROUP = "(/(?<version>[a-zA-z0-9-_]+))?"; | ||
private static final String KIND_GROUP = "/(?<kind>[^/?]+)"; | ||
private static final String NAME_GROUP = "(/(?<name>[^/?]+))?"; | ||
private static final String NAMESPACE_GROUP = "(/namespaces/(?<namespace>[^/]+))?"; | ||
private static final String END_GROUP = "[^ /]*"; | ||
|
||
protected static final Pattern NAMESPACED_CREATE_PATH = Pattern.compile("/api[s]?/" + VERSION_GROUP + "/namespaces/" + NAMESPACE_GROUP + "/" + KIND_GROUP + "[^ ]*"); | ||
protected static final Pattern NON_NAMESPACED_CREATE_PATH = Pattern.compile("/api[s]?/" + "/" + KIND_GROUP + "[^ ]*"); | ||
protected static final Pattern PATTERN = Pattern.compile(API_GROUP + VERSION_GROUP + NAMESPACE_GROUP + KIND_GROUP + NAME_GROUP + END_GROUP); | ||
|
||
@Override | ||
public AttributeSet fromPath(String s) { | ||
|
@@ -52,25 +55,11 @@ public AttributeSet fromPath(String s) { | |
} | ||
|
||
//Get paths | ||
Matcher m = NAMESPACED_NAMED_PATH.matcher(s); | ||
if (m.matches()) { | ||
return extract(m); | ||
} | ||
|
||
m = NON_NAMESPACED_NAMED_PATH.matcher(s); | ||
Matcher m = PATTERN.matcher(s); | ||
if (m.matches()) { | ||
return extract(m); | ||
} | ||
|
||
//Create paths | ||
m = NAMESPACED_CREATE_PATH.matcher(s); | ||
if (m.matches()) { | ||
return extract(m); | ||
} | ||
|
||
m = NON_NAMESPACED_CREATE_PATH.matcher(s); | ||
if (m.matches()) { | ||
return extract(m); | ||
AttributeSet set = extract(m); | ||
LOGGER.debug("fromPath {} : {}", s, set); | ||
return set; | ||
} | ||
return new AttributeSet(); | ||
} | ||
|
@@ -102,26 +91,13 @@ public AttributeSet extract(String s) { | |
} | ||
|
||
//Get paths | ||
Matcher m = NAMESPACED_NAMED_PATH.matcher(s); | ||
if (m.matches()) { | ||
return extract(m); | ||
} | ||
|
||
m = NON_NAMESPACED_NAMED_PATH.matcher(s); | ||
if (m.matches()) { | ||
return extract(m); | ||
} | ||
|
||
//Create paths | ||
m = NAMESPACED_CREATE_PATH.matcher(s); | ||
if (m.matches()) { | ||
return extract(m); | ||
} | ||
|
||
m = NON_NAMESPACED_CREATE_PATH.matcher(s); | ||
Matcher m = PATTERN.matcher(s); | ||
if (m.matches()) { | ||
return extract(m); | ||
AttributeSet set = extract(m); | ||
LOGGER.debug("extract {} : {}", s, set); | ||
return set; | ||
} | ||
LOGGER.debug("extract {} : no attributes", s); | ||
return new AttributeSet(); | ||
} | ||
|
||
|
@@ -150,7 +126,9 @@ private static AttributeSet extract(Matcher m) { | |
if (!Strings.isNullOrEmpty(kind)) { | ||
|
||
//Poor mans to singular. | ||
if (kind.endsWith("s")) { | ||
if (kind.endsWith("ses")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe its time to use a real utility for converting to singular like: https://github.com/sundrio/sundrio/blob/95c2b11f7b842bdaa04f61e8e338aea60fb38f70/codegen/src/main/java/io/sundr/codegen/functions/Singularize.java There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But for now this will do. |
||
kind = kind.substring(0, kind.length() - 2); | ||
} else if (kind.endsWith("s")) { | ||
kind = kind.substring(0, kind.length() - 1); | ||
} | ||
attributes = attributes.add(new Attribute(KIND, kind)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1