seconf

package module
v0.0.0-...-c26dd81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2017 License: MIT Imports: 13 Imported by: 2

README

seconf

This library creates, detects, and reads non-plaintext configuration files.

GoDoc

(Example)

seconf saves the configuration file as a :::: separated list. for the encryption, i chose (nacl/secretbox). theres a simple default pad that allows "empty" passwords. we use bgentry/speakeasy for accepting user input for fields that contain "pass" or "key".

Secretbox uses XSalsa20 and Poly1305 to encrypt and authenticate messages with secret-key cryptography.

Future versions will store the values differently, using new functions, but the legacy functions will remain.

  • go-quitter for user, password, node URL.
  • secenv for user environment export seconf variables to shell
  • My contact form server, cosgo, uses seconf to store SMTP API keys and configuration fields.

Attention

This project has not been reviewed by security professionals. Its internals, data formats, and interfaces may change at any time in the future without warning.


The MIT License (MIT)

Copyright (c) 2016 aerth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Overview

Package seconf allows your software to store non-plaintext configuration files.

Example
package main

import (
	"fmt"
	"os"

	"github.com/aerth/seconf"
)

func main() {
	// Here is the new implementation using JSON
	filename := "se.conf"
	header := "Seconf"
	// []string of fields, they are both the prompt and key for looking the fields back up.
	fields := map[string]string{
		"name":           "What is your name?",
		"favorite-color": "What is your favorite color?",
		"lol":            "You lol tho?",
		"password":       "What is your password? Will not echo",
	}

	if !seconf.Detect(filename) {
		seconf.LockJSON(filename, header, fields) // Ask user for values
		return
	}

	c, err := seconf.ReadJSON(filename)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Printf("%s's favorite color is %q!\n", c.Fields["name"], c.Fields["favorite-color"])

}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var NoBlank bool = false

NoBlank can be toggled to require a non-blank string for each field.

Functions

func AskForConfirmation

func AskForConfirmation() bool

AskForConfirmation returns true if the user types one of the "okayResponses" See also: ConfirmChoice() https://gist.github.com/albrow/5882501

func ConfirmChoice

func ConfirmChoice(prompt string, def bool) bool

ConfirmChoice is like AskForConfirmation but with a default answer.

func Create

func Create(secustom string, servicename string, arg ...string)

Create initializes a new configuration file, at $HOME/secustom with the title servicename and as many fields as needed. Any field starting with "pass" will be assumed a password and input will not be echoed. Don't use Create(), use Lock() instead.

func Destroy

func Destroy(secustom string) error

func Detect

func Detect(secustom string) bool

Detect returns TRUE if a seconf file exists.

func Exists

func Exists(secustom string) bool

Exists returns TRUE if a seconf file exists. (absolute or relative path)

func Locate

func Locate(secustom string) (location string)

Locate uses returnHome to produce the location of the config file

func Lock

func Lock(secustom string, servicename string, arg ...string) error

Lock() is the new version of Create(), It returns any errors during the process instead of using os.Exit()

func LockJSON

func LockJSON(secustom string, servicename string, field map[string]string, fixedkey ...[1][]byte) error

LockJSON is the new version of Create(), It returns any errors during the process instead of using os.Exit()

func LockUnsafe

func LockUnsafe(path string, configbytes []byte, key []byte) (n int, err error)

LockUnsafe Allow an application to store config with default/no password.

func Pad

func Pad(s string)

Pad sets the default pad, used to increase password length.

func Prompt

func Prompt(prompt string) string

Prompt the user for the particular field.

func Read

func Read(secustom string) (config string, err error)

func UnLockUnsafe

func UnLockUnsafe(path string, key []byte) ([]byte, error)

UnLockUnsafe Allow an application to store config with default/no password.

Types

type Config

type Config struct {
	Fields map[string]interface{} `json:",string,omitempty"`
}

func ReadJSON

func ReadJSON(secustom string) (configger Config, err error)

ReadJSON returns the decoded configuration file, or an error.

type Seconf

type Seconf struct {
	ID     int64
	Path   string
	Args   []string
	Fields map[string]string
}

Seconf is the struct for the seconf pathname and fields.

Directories

Path Synopsis
_examples
new

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL