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
Allow configuring max aliases for a collection #1375
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1375 +/- ##
============================================
- Coverage 79.61% 79.52% -0.10%
- Complexity 804 806 +2
============================================
Files 66 66
Lines 2330 2344 +14
Branches 325 326 +1
============================================
+ Hits 1855 1864 +9
- Misses 375 380 +5
Partials 100 100
|
…ases config This needs to be a property/env since the context is not yet configurable as it has yet to read any YAML and it might be blocked due to alias limit. Adding the reading of the property/env to ConfigurationContext makes sense to avoid YamlUtils to constantly reading the property on every file read when it attempts to merge all the sources.
String prop = Util.fixEmptyAndTrim(System.getProperty( | ||
CASC_YAML_MAX_ALIASES_PROPERTY, | ||
System.getenv(CASC_YAML_MAX_ALIASES_ENV) | ||
)); | ||
yamlMaxAliasesForCollections = NumberUtils.toInt(prop, 50); |
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.
@timja Please see 57aebdd commit message for my reasoning to use a property.
This needs to be a property/env since the context is not yet configurable as it has yet to read any YAML
and it might be blocked due to alias limit.Adding the reading of the property/env to ConfigurationContext
makes sense to avoid YamlUtils to constantly reading the property on every file read
when it attempts to merge all the sources.
I would like to add tests for aliases and demo. |
No need for documentation it as the exception will tell them what to do. |
@@ -27,14 +26,14 @@ | |||
@Test | |||
public void testAMaxOfOneEnv() { | |||
env.set(ConfigurationContext.CASC_YAML_MAX_ALIASES_ENV, "1"); | |||
assertThrows(YAMLException.class, () -> | |||
assertThrows(ConfiguratorException.class, () -> |
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.
Worth checking the message here?
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.
assertThrows
does not allow for asserting the exception message.
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.
It returns the exception and then you can assert on it
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.
Oh it returns the exception so sure 😅
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.
The stack trace somewhat hides it but it is still visible.
io.jenkins.plugins.casc.ConfiguratorException: Failed to read YamlSource: file:/C:/git/code/configuration.as.code.plugin/test-harness/target/test-classes/io/jenkins/plugins/casc/maxAliasesLimit.yml
at io.jenkins.plugins.casc.yaml.YamlUtils.merge(YamlUtils.java:48)
at io.jenkins.plugins.casc.yaml.YamlUtils.loadFrom(YamlUtils.java:127)
at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:618)
at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:587)
at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:576)
at io.jenkins.plugins.casc.YamlMaxAliasesCollection.lambda$testAMaxOfOneProp$1(YamlMaxAliasesCollection.java:42)
at org.junit.Assert.assertThrows(Assert.java:1001)
at org.junit.Assert.assertThrows(Assert.java:981)
at io.jenkins.plugins.casc.YamlMaxAliasesCollection.testAMaxOfOneProp(YamlMaxAliasesCollection.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:597)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:288)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:282)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.jenkins.plugins.casc.ConfiguratorException: Number of aliases for non-scalar nodes exceeds the specified max=1
You can increase the maximum by setting an environment variable or property
ENV: CASC_YAML_MAX_ALIASES="100"
PROPERTY: -Dcasc.yaml.max.aliases="100"
at io.jenkins.plugins.casc.yaml.YamlUtils.read(YamlUtils.java:66)
at io.jenkins.plugins.casc.yaml.YamlUtils.merge(YamlUtils.java:38)
... 21 more
jacoco does not like assertThrows for code coverage 😓 |
fixes #1374
Your checklist for this pull request
🚨 Please review the guidelines for contributing to this repository.