keyring

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 13 Imported by: 8

README

Launchr Keyring

Keyring is a launchr plugin and a service providing a password storage functionality encrypted with age. The storage is encrypted with a passphrase.

How to use

To add a new item with an interactive shell:

launchr login

If an interactive shell is not available, credentials may be provided with flags:

launchr login \
  --url=https://your.gitlab.com \
  --username=USER \
  --password=SECRETPASSWORD \
  --keyring-passphrase=YOURPASSHRPASE

Flag --keyring-passphrase is available for all launchr commands, for example:

launchr compose --keyring-passphrase=YOURPASSHRPASE

To delete an item from the keyring:

launchr logout URL

The file is created in .launchr/keyring.yaml.age.
The content may be viewed/edited with age cli:

age -d .launchr/keyring.yaml.age
age -p .launchr/keyring.yaml > .launchr/keyring.yaml.age

In code

Add a module dependency:

go get -u github.com/launchrctl/keyring

To use the keyring in code, get the service from the app:

package main

import (
	"github.com/launchrctl/keyring"
	"github.com/launchrctl/launchr"
)

func GetPassword(app *launchr.App, url string) (keyring.CredentialsItem, error) {
	// Get the service by type from the app.
	k := launchr.GetService[keyring.Keyring](app)
	// Get by url. Error if the keyring could not be unlocked.
	// Error keyring.ErrNotFound is returned if an item was not found.
	creds, err := k.GetForURL(url)
	if err != nil {
		return keyring.CredentialsItem{}, err
	}
	return creds, nil
}

Include with launchr build:

launchr build -p github.com/launchrctl/keyring

Documentation

Overview

Package keyring provides password store functionality.

Index

Constants

View Source
const ID = "keyring"

ID is a plugin id.

Variables

View Source
var (
	ErrNotFound    = errors.New("credential item not found")  // ErrNotFound if an item was not found
	ErrEmptyFields = errors.New("credentials can't be empty") // ErrEmptyFields if fields are empty
)

Functions

This section is empty.

Types

type AskPass

type AskPass interface {
	GetPass() (string, error)
	NewPass() (string, error)
}

AskPass defines basic interface to retrieve passphrase.

type AskPassConstFlow

type AskPassConstFlow string

AskPassConstFlow implements AskPass and returns constant.

func (AskPassConstFlow) GetPass

func (a AskPassConstFlow) GetPass() (string, error)

GetPass implements AskPass interface.

func (AskPassConstFlow) NewPass

func (a AskPassConstFlow) NewPass() (string, error)

NewPass implements AskPass interface.

type AskPassWithTerminal

type AskPassWithTerminal struct{}

AskPassWithTerminal implements AskPass and uses tty to retrieve passphrase. @todo support pipe and stdin

func (AskPassWithTerminal) GetPass

func (a AskPassWithTerminal) GetPass() (string, error)

GetPass implements AskPass interface.

func (AskPassWithTerminal) NewPass

func (a AskPassWithTerminal) NewPass() (string, error)

NewPass implements AskPass interface.

type CredentialsFile

type CredentialsFile interface {
	io.ReadWriteCloser
	Open(flag int, perm os.FileMode) error
}

CredentialsFile is an interface to open and edit credentials file.

type CredentialsItem

type CredentialsItem struct {
	URL      string `yaml:"url"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

CredentialsItem stores credentials.

type CredentialsStore

type CredentialsStore interface {
	// GetForURL returns a credentials item by a URL.
	// Error is returned if either the keyring could not be unlocked
	// Error ErrNotFound if the credentials were not found.
	GetForURL(url string) (CredentialsItem, error)
	// AddItem adds a new credential item.
	// Error is returned if the vault couldn't be unlocked.
	// Error ErrEmptyFields is returned if item is empty.
	AddItem(CredentialsItem) error
	// RemoveItem deletes an item by url.
	// Error is returned if the vault couldn't be unlocked.
	// Error ErrNotFound if the credentials were not found.
	RemoveItem(url string) error
	// Save saves the content to the persistent storage.
	Save() error
}

CredentialsStore provides password storage functionality.

type Keyring

type Keyring interface {
	launchr.Service
	CredentialsStore
}

Keyring is a launchr.Service providing password store functionality.

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin is launchr plugin providing web ui.

func (*Plugin) CobraAddCommands

func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error

CobraAddCommands implements launchr.CobraPlugin interface to provide web functionality.

func (*Plugin) InitApp

func (p *Plugin) InitApp(app *launchr.App) error

InitApp implements launchr.Plugin interface.

func (*Plugin) PluginInfo

func (p *Plugin) PluginInfo() launchr.PluginInfo

PluginInfo implements launchr.Plugin interface.

Directories

Path Synopsis
cmd
launchr command
Package executes Launchr application.
Package executes Launchr application.

Jump to

Keyboard shortcuts

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