Module org.github.gestalt.core
Package org.github.gestalt.config.source
Class EnvironmentConfigSource
- java.lang.Object
-
- org.github.gestalt.config.source.EnvironmentConfigSource
-
- All Implemented Interfaces:
ConfigSource
public final class EnvironmentConfigSource extends java.lang.Object implements ConfigSource
Convert the Environment Variables to a property file. Apply the supplied transforms as we convert it. Then write that as an input stream for the next stage in the parsing.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringENV_VARSFormat for the EnvironmentConfigSource.
-
Constructor Summary
Constructors Constructor Description EnvironmentConfigSource()Default constructor for EnvironmentConfigSource.EnvironmentConfigSource(boolean failOnErrors)constructor for EnvironmentConfigSource.EnvironmentConfigSource(java.lang.String prefix)Specify if you want to only parse the Environment variables that have a prefix.EnvironmentConfigSource(java.lang.String prefix, boolean removePrefix)Specify if you want to only parse the Environment variables that have a prefix.EnvironmentConfigSource(java.lang.String prefix, boolean removePrefix, boolean failOnErrors, Tags tags)Specify if you want to only parse the Environment variables that have a prefix.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)booleanfailOnErrors()If the source should fail on errors.java.lang.Stringformat()The format of the config source, for example this can be envVars, the extension of a file (properties, json, ect).TagsgetTags()A source can have a set of tags that apply to all nodes in the source.inthashCode()booleanhasList()If this config source provides a list of config values.booleanhasStream()If this config source has a stream to load from.java.util.UUIDid()Id that represents this source as unique.java.util.List<Pair<java.lang.String,java.lang.String>>loadList()gets the Environment Variables and converts them to a list of pairs.java.io.InputStreamloadStream()If this config source has a stream, this will return the stream of data.java.lang.Stringname()human-readable name for logging.
-
-
-
Field Detail
-
ENV_VARS
public static final java.lang.String ENV_VARS
Format for the EnvironmentConfigSource.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EnvironmentConfigSource
public EnvironmentConfigSource()
Default constructor for EnvironmentConfigSource. By default, it will not fail on errors while loading Env Vars since they are often uncontrolled and may not follow expected conventions of this library.
-
EnvironmentConfigSource
public EnvironmentConfigSource(boolean failOnErrors)
constructor for EnvironmentConfigSource.- Parameters:
failOnErrors- Do not fail on errors while loading Env Vars since they are often uncontrolled and may not follow expected conventions of this library.
-
EnvironmentConfigSource
public EnvironmentConfigSource(java.lang.String prefix, boolean removePrefix)Specify if you want to only parse the Environment variables that have a prefix. By default it will remove the prefix from the output.- Parameters:
prefix- only use the Environment variables that have a prefix.removePrefix- if we should remove the prefix
-
EnvironmentConfigSource
public EnvironmentConfigSource(java.lang.String prefix)
Specify if you want to only parse the Environment variables that have a prefix. By default it will remove the prefix from the output.- Parameters:
prefix- only use the Environment variables that have a prefix.
-
EnvironmentConfigSource
public EnvironmentConfigSource(java.lang.String prefix, boolean removePrefix, boolean failOnErrors, Tags tags)Specify if you want to only parse the Environment variables that have a prefix.- Parameters:
prefix- only use the Environment variables that have a prefix.removePrefix- If you should remove the prefix from the outputfailOnErrors- Do not fail on errors while loading Env Vars since they are often uncontrolled and may not follow expected conventions of this library.tags- set of tags associated with this source.
-
-
Method Detail
-
failOnErrors
public boolean failOnErrors()
Description copied from interface:ConfigSourceIf the source should fail on errors.- Specified by:
failOnErrorsin interfaceConfigSource- Returns:
- If the source should fail on errors
-
hasStream
public boolean hasStream()
Description copied from interface:ConfigSourceIf this config source has a stream to load from.- Specified by:
hasStreamin interfaceConfigSource- Returns:
- if this config source has a stream to load from
-
loadStream
public java.io.InputStream loadStream() throws GestaltExceptionDescription copied from interface:ConfigSourceIf this config source has a stream, this will return the stream of data. Or if not supported it will throw an exception.- Specified by:
loadStreamin interfaceConfigSource- Returns:
- input stream of data
- Throws:
GestaltException- if there are any IO or if this is an unsupported operation
-
hasList
public boolean hasList()
Description copied from interface:ConfigSourceIf this config source provides a list of config values.- Specified by:
hasListin interfaceConfigSource- Returns:
- if this config source provides a list of config values
-
loadList
public java.util.List<Pair<java.lang.String,java.lang.String>> loadList()
gets the Environment Variables and converts them to a list of pairs. The first is the key and the second the value.- Specified by:
loadListin interfaceConfigSource- Returns:
- list of environment variables.
-
format
public java.lang.String format()
Description copied from interface:ConfigSourceThe format of the config source, for example this can be envVars, the extension of a file (properties, json, ect).- Specified by:
formatin interfaceConfigSource- Returns:
- The format of the config source
-
name
public java.lang.String name()
Description copied from interface:ConfigSourcehuman-readable name for logging.- Specified by:
namein interfaceConfigSource- Returns:
- human-readable name for logging.
-
id
public java.util.UUID id()
Description copied from interface:ConfigSourceId that represents this source as unique.- Specified by:
idin interfaceConfigSource- Returns:
- id
-
getTags
public Tags getTags()
Description copied from interface:ConfigSourceA source can have a set of tags that apply to all nodes in the source.- Specified by:
getTagsin interfaceConfigSource- Returns:
- tags assigned to the source
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-