Packages

  • package root
    Definition Classes
    root
  • package args4c

    Args4c (arguments for configuration) is intended to add some helpers and utilities in obtaining a typesafe configuration from user arguments.

    Args4c (arguments for configuration) is intended to add some helpers and utilities in obtaining a typesafe configuration from user arguments.

    The core is simply to convert an Array[String] to a Config where the arguments are either paths to configuration resources or simple key=value pairs via args4c.configForArgs

    Left-most arguments take precedence. In this example, we assume 'prod.conf' is a resource on the classpath:

    MyApp foo.x=bar foo.x=ignored /opt/etc/overrides.conf prod.conf

    In addition to this core concept, this library also provides some additional configuration utilities via args4c.RichConfigOps which can be made available by extending args4c.LowPriorityArgs4cImplicits or importing args4c.implicits:

    import args4c.implicits._
    object MyApp {
       override def main(args : Array[String]) : Unit = {
         val config = args.asConfig()
         println("Starting MyApp with config:")
    
         // let's "log" our app's config on startup:
         val flatSummary : String = config.filter(_.startsWith("myapp")).summary()
         println(flatSummary) // "logging" our config
       }
    }

    Where the 'summary' will produce sorted args4c.StringEntry values with potentially sensitive entries (e.g. passwords) obscured and a source comment for some sanity as to where each entry comes from:

    myapp.foo : bar # command-line
    myapp.password : **** obscured **** # command-line
    myapp.saveTo : afile # file:/opt/etc/myapp/test.conf@3

    Also, when extracting user arguments into a configuration, an additional 'fallback' config is specified. Typically this would just be the ConfigFactory.load() configuration, but args4c uses the args4c.defaultConfig, which is essentially just the system environment variables converted from snake-caes to dotted lowercase values first, then falling back on ConfigFactory.load().

    Applications can elect to not have this behaviour and provide their own fallback configs when parsing args, but the default provides a convenience for system environment variables to override e.g. 'foo.bar.x=default' by specifying

    FOO_BAR_X=override

    as a system environment variable. Otherwise you may end up having to repeat this sort of thing all over you config:

    foo.bar=default
    foo.bar=$${?FOO_BAR}
    
    foo.bazz=default2
    foo.bazz=$${?FOO_BAZZ}
    
    ...

    Finally, args4c also provides a args4c.ConfigApp which provides some additional functionality to configuration-based applications.

    Definition Classes
    root
  • trait ConfigApp extends LowPriorityArgs4cImplicits

    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=<path>' 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.

    Definition Classes
    args4c
  • Result
  • RichArgs
  • RichString
  • SecureConfigDoesntExist
  • SecureConfigNotSpecified
  • SecureConfigParsed
  • SecureConfigState
c

args4c.ConfigApp

SecureConfigDoesntExist

case class SecureConfigDoesntExist(path: Path) extends SecureConfigState with Product with Serializable

Attributes
protected
Linear Supertypes
Serializable, Serializable, Product, Equals, SecureConfigState, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SecureConfigDoesntExist
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. SecureConfigState
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SecureConfigDoesntExist(path: Path)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. val configOpt: Option[Config]
    Definition Classes
    SecureConfigState
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  11. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  13. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  14. val path: Path
  15. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  16. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from SecureConfigState

Inherited from AnyRef

Inherited from Any

Ungrouped