use of io.jenkins.plugins.casc.model.Scalar in project configuration-as-code-plugin by jenkinsci.
the class Attribute method describeForSchema.
/**
* This function is for the JSONSchemaGeneration
* @param instance Owner Instance
* @param context Context to be passed
* @return CNode object describing the structure of the node
*/
public CNode describeForSchema(Owner instance, ConfigurationContext context) {
final Configurator c = context.lookup(type);
if (c == null) {
return new Scalar("FAILED TO EXPORT\n" + instance.getClass().getName() + "#" + name + ": No configurator found for type " + type);
}
try {
Object o = getType();
if (o == null) {
return null;
}
// In Export we sensitive only those values which do not get rendered as secrets
boolean shouldBeMasked = isSecret(instance);
if (multiple) {
Sequence seq = new Sequence();
if (o.getClass().isArray())
o = Collections.singletonList(o);
if (o instanceof Iterable) {
for (Object value : (Iterable) o) {
seq.add(_describe(c, context, value, shouldBeMasked));
}
}
return seq;
}
return _describe(c, context, o, shouldBeMasked);
} catch (Exception e) {
// Don't fail the whole export, prefer logging this error
LOGGER.log(Level.WARNING, "Failed to export", e);
return new Scalar("FAILED TO EXPORT\n" + instance.getClass().getName() + "#" + name + ": " + printThrowable(e));
}
}
use of io.jenkins.plugins.casc.model.Scalar in project configuration-as-code-plugin by jenkinsci.
the class PrimitiveConfiguratorTest method _Integer.
@Test
public void _Integer() throws Exception {
Configurator c = registry.lookupOrFail(Integer.class);
final Object value = c.configure(new Scalar("123"), context);
assertEquals(123, (int) value);
}
use of io.jenkins.plugins.casc.model.Scalar in project configuration-as-code-plugin by jenkinsci.
the class PrimitiveConfiguratorTest method _string_env_default.
@Test
public void _string_env_default() throws Exception {
environment.set("NOT_THERE", "abc");
Configurator c = registry.lookupOrFail(String.class);
final Object value = c.configure(new Scalar("${ENV_FOR_TEST:-unsecured-token}"), context);
assertEquals("unsecured-token", value);
}
use of io.jenkins.plugins.casc.model.Scalar in project configuration-as-code-plugin by jenkinsci.
the class PrimitiveConfiguratorTest method _int.
@Test
public void _int() throws Exception {
Configurator c = registry.lookupOrFail(int.class);
final Object value = c.configure(new Scalar("123"), context);
assertEquals(123, (int) value);
}
use of io.jenkins.plugins.casc.model.Scalar in project configuration-as-code-plugin by jenkinsci.
the class PrimitiveConfiguratorTest method _enum.
@Test
public void _enum() throws Exception {
// Jenkins do register a StaplerConverter for it.
Configurator<Node.Mode> c = registry.lookupOrFail(Node.Mode.class);
final Node.Mode value = c.configure(new Scalar("NORMAL"), context);
assertEquals(Node.Mode.NORMAL, value);
}
Aggregations