go-credentials

module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: MIT

README

go-credentials

GitHub release (latest SemVer) GitHub go.mod Go version GoDoc License
Build Quality Gate Status Coverage Go Report Card

Welcome to go-credentials!

This project is being built out of a need for a library to manage credentials files (similar to AWS credentials), their attributes, sessions, and environment variables.

go-credentials logo

The Credential API is broken down into two pieces, each with their own functionality:

  1. Factory: responsible for setting variables that are global to your application, and;
    • Set alternate keys for username/password (e.g. ACCESS_TOKEN/SECRET_KEY).
    • Set the output type of the credentials (environment, ini, and json supported).
    • Responsible for logging.
  2. Credential: represents a user's credentials.
    • Username/Password defined on model.
    • Can have a profile.
    • Save and Load Credentials (and Profiles).
  3. Profile: represents a profile, containing variables specific to a profile.
    • Username/Password defined on model.
    • Set Attributes (including sections).
    • Get Attributes (including sections).

To get started, is all you need to do is create the following files.

~/.gcea/credentials

[default]
username = test@engi.fyi
password = !my_test_pass==word

main.go

package main

import (
    "github.com/engi-fyi/go-credentials/credential"
    "github.com/engi-fyi/go-credentials/factory"
    "fmt" 
    "time"
)

func main() {
	myFact, _ := factory.New("gcea", false) // go-credentials-example-application
	myFact.ModifyLogger("trace", true) // let's see under the hood and make it pretty.
	myCredential, _ := credential.Load(myFact)

	fmt.Printf("Username: %s\n", myCredential.Username)
	fmt.Printf("Password: %s\n\n", myCredential.Password)

	myCredential.SetSectionAttribute("metadata", "last_updated", time.Now().Format("02/01/2006 15:04:05"))
	myCredential.Save()
	myCredential = nil

	yourCredential, _ := credential.Load(myFact)

	fmt.Printf("Username: %s\n", yourCredential.Username)
	fmt.Printf("Password: %s\n", yourCredential.Password)

	lastUpdated, _ := yourCredential.GetSectionAttribute("metadata", "last_updated")
	fmt.Printf("Last Updated: %s\n", lastUpdated)
}

Directories

Path Synopsis
Package credential provides the base implementation detail for the go-credentials library.
Package credential provides the base implementation detail for the go-credentials library.
Package factory provides an API for managing application-level credential details.
Package factory provides an API for managing application-level credential details.
Package global contains constants, test variables, and some minor utility functions.
Package global contains constants, test variables, and some minor utility functions.
Package profile contains all of the code for managing multiple credential files.
Package profile contains all of the code for managing multiple credential files.
Package serializer is responsible for de/serializing Credential and Profile objects into different file formats.
Package serializer is responsible for de/serializing Credential and Profile objects into different file formats.

Jump to

Keyboard shortcuts

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