args4c

package args4c

Type members

Classlikes

A convenience mix-in utility for a main entry point.

A convenience mix-in utility for a main entry point.

It parsed the user arguments using the default config (which is ConfigFactory.load() but w/ system environment variables overlaid)

If the config has a 'show=' in it, then that path will be printed out and the program with return.

e.g. MyAppWhichExtendsConfigApp show=myapp.database.url

will display the value of myapp.database.url

It also interprets a single '--setup' to enable the configuration of sensitive configuration entries into a locally encrypted file.

Subsequent runs of your application would then use '--secure=path/to/encrypted.conf' to load that encrypted configuration and either take the password from an environment variable or standard input.

For example, running 'MyApp --setup' would then prompt like this:

Save secure config to (/opt/etc/myapp/.config/secure.conf):config/secure.conf
Config Permissions (defaults to rwx------): rwxrw----
Add config path in the form <key>=<value> (leave blank when finished):myapp.secure.password=hi
Add config path in the form <key>=<value> (leave blank when finished):myapp.another.config.entry=123
Add config path in the form <key>=<value> (leave blank when finished):
Config Password:password

Then, running 'MyApp --secure=config/secure.conf -myapp.whocares=visible -show=myapp'

would prompt for the password from standard input, then produce the following, hiding the values which were present in the secure config:

myapp.another.config.entry : **** obscured **** # secure.conf: 1
myapp.secure.password : **** obscured **** # secure.conf: 1
myapp.whocares : visible # command-line

NOTE: even though the summary obscures the values, they ARE present as PLAIN TEXT STRINGS in the configuration, so take care in limiting the scope of where the configuration is used, either by filtering back out those values, otherwise separating the secure config from the remaining config, or just ensuring to limit the scope of the config itself.

object Encryption
sealed
trait PasswordPrompt extends Prompt
sealed
trait Prompt

Represents a request for user input when configuring the 'sensitive configurations'

Represents a request for user input when configuring the 'sensitive configurations'

Companion
object
object Prompt
Companion
class
case
class PromptForExistingPassword(configPath: Path) extends PasswordPrompt
case
case
class ReadNextKeyValuePair(requiredConfigPath: String, secureConfig: Config) extends Prompt
case
class ReadNextKeyValuePairAfterError(previousInvalidEntry: String) extends Prompt
class RichConfig(val config: Config) extends RichConfigOps

Adds some scala utility around a typesafe config

Adds some scala utility around a typesafe config

Companion
object
object RichConfig
Companion
class
trait RichConfigOps extends Dynamic with LowPriorityArgs4cImplicits

Exposes new operations on a 'config'

Exposes new operations on a 'config'

case
class SaveSecretPrompt(configPath: Path) extends Prompt

Makes available a means to initialize a sensitive, encrypted config file via SecureConfig.setupSecureConfig and ConfigApp.secureConfigForArgs

Makes available a means to initialize a sensitive, encrypted config file via SecureConfig.setupSecureConfig and ConfigApp.secureConfigForArgs

The idea is that a (service) user-only readable, password-protected AES encrypted config file can be set up via reading entries from standard input, and an application an use those configuration entries thereafter by taking the password from standard input.

Companion
class
case
class SecureConfig(promptForInput: UserInput)
Companion
object
case
class Selected(value: ConfigValue) extends Dynamic

An object returned from a dynamic select

An object returned from a dynamic select

Companion
object
object Selected
Companion
class
case
class StringEntry(comments: List[String], origin: String, key: String, value: String)

Exposes the entry point for using a RichConfig,

Exposes the entry point for using a RichConfig,

mostly for converting user-args into a config

Types

type UserInput = Prompt => String

A means to get a values from user prompts in order to set up a secure configuration

A means to get a values from user prompts in order to set up a secure configuration

Value members

Concrete methods

def configForArgs(args: Array[String], fallback: Config, onUnrecognizedArg: String => Config): Config

Given the user arguments, produce a loaded configuration which interprets the user-args from left to right as:

Given the user arguments, produce a loaded configuration which interprets the user-args from left to right as:

$ a configuration file on the classpath or file system $ a key=value pair

Left-most values take precedence over right

Value Params
args

the user command-line arguments

fallback

the default configuration to fall back to

onUnrecognizedArg

the handler for unrecognized user arguments

Returns

a parsed configuration

def configForMap(confMap: Map[String, String]): Config
Returns

a config for this map

def defaultConfig(): Config
Returns

ConfigFactory.load()

def env(key: String): Option[String]
def envOrProp(key: String): Option[String]
def obscurePassword(configPath: String, value: String, blacklist: Set[String], obscuredValue: String): String
Value Params
blacklist

a 'blacklist' which, if any of the entries are found anywhere in the configPath, then the value will be obscured

configPath

the config key (e.g. foo.bar.bazz)

value

the config value, as a string

Returns

the

def passwordBlacklist: Set[String]
def pathAsFile(path: String): Option[Path]
def pathAsUrl(path: String): Option[URL]
def prop(key: String): Option[String]
def unquote(str: String): String

trims and unquotes a string (the single quotes is mine - added to demonstrate the full text):

trims and unquotes a string (the single quotes is mine - added to demonstrate the full text):

'"quoted"'     becomes: 'quoted'
'  "quoted"  ' becomes: 'quoted'
'quoted"  '    is unchanged: 'quoted"  '
'"quoted '     is unchanged: 'quoted"  '
Value Params
str

the string to unquote

Returns

either the string unchanged or the single quotes removed as trimming whitespace around the quotes

Concrete fields