passwork

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: MIT Imports: 10 Imported by: 0

README

passwork-client-go

REST Client for the Password Manager Passwork written in Go.

The client can currently perform CRUD operations on passwords, folders and vaults.

Example usage

package main

import "github.com/lupa95/passwork-client-go"

func main() {
	host := "https://my-passwork-instance.com/api/v4"
	apiKey := "my-secret-api-key"
	timeout := time.Second * 30

	// Create a new client and log in
	client := passwork.NewClient(host, apiKey, timeout)
	client.Login()

	// Create a vault
	vaultRequest := VaultAddRequest{
		Name:         "example-vault",
		IsPrivate:    true,
		PasswordHash: "example-hash",
		Salt:         "example-salt",
		MpCrypted:    "example-mp",
	}
	vaultResponse, _ := client.AddVault(vaultRequest)

	// Create a password
	passwordRequest := PasswordRequest{
		Name:            "example-password",
		VaultId:         vaultResponse.Data,
		Login:           "example-login",
		CryptedPassword: "ZXhhbXBsZS1wYXNzd29yZAo=", // Password must be base64 encoded
		Description:     "example-description",
		Url:             "https://example.com",
		Color:           1,
		Tags:            []string{"example", "tag"},
	}
	client.AddPassword(passwordRequest)

	// Logout
	client.Logout()
}

Running tests

export PASSWORK_API_KEY="api-key"
export PASSWORK_HOST="https://my-passwork-instance/api/v4"
export PASSWORK_VAULT_ID="vault-id"

go test

// More elaborate
go test -v -cover

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL string

	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL, apiKey string, timeout time.Duration) *Client

func (*Client) AddFolder

func (c *Client) AddFolder(folderRequest FolderRequest) (FolderResponse, error)

func (*Client) AddPassword

func (c *Client) AddPassword(pwRequest PasswordRequest) (PasswordResponse, error)

func (*Client) AddVault

func (c *Client) AddVault(vaultRequest VaultAddRequest) (VaultOperationResponse, error)

func (*Client) DeleteFolder

func (c *Client) DeleteFolder(folderId string) (DeleteResponse, error)

func (*Client) DeletePassword

func (c *Client) DeletePassword(pwId string) (DeleteResponse, error)

func (*Client) DeleteVault

func (c *Client) DeleteVault(vaultId string) (DeleteResponse, error)

func (*Client) EditFolder

func (c *Client) EditFolder(folderId string, request FolderRequest) (FolderResponse, error)

func (*Client) EditPassword

func (c *Client) EditPassword(pwId string, request PasswordRequest) (PasswordResponse, error)

func (*Client) EditVault

func (c *Client) EditVault(vaultId string, request VaultEditRequest) (VaultOperationResponse, error)

func (*Client) GetFolder

func (c *Client) GetFolder(folderId string) (FolderResponse, error)

func (*Client) GetPassword

func (c *Client) GetPassword(pwId string) (PasswordResponse, error)

Get a password by ID

func (*Client) GetVault

func (c *Client) GetVault(vaultId string) (VaultResponse, error)

func (*Client) Login

func (c *Client) Login() error

Perform Login Request and set session Token in struct

func (*Client) Logout added in v0.2.0

func (c *Client) Logout() error

func (*Client) SearchFolder

func (c *Client) SearchFolder(request FolderSearchRequest) (FolderSearchResponse, error)

func (*Client) SearchPassword

func (c *Client) SearchPassword(request PasswordSearchRequest) (PasswordSearchResponse, error)

Search for password by name

type DeleteResponse

type DeleteResponse struct {
	Status string
	Code   string
	Data   string
}

type FolderDeleteResponse

type FolderDeleteResponse struct {
	Status string
	Code   string
	Data   string // folderDeleted
}

type FolderRequest

type FolderRequest struct {
	VaultId  string `json:"vaultId,omitempty"`
	Name     string `json:"name"`
	ParentId string `json:"parentId,omitempty"`
}

type FolderResponse

type FolderResponse struct {
	Status string
	Code   string // folderCreated, folderRenamed
	Data   FolderResponseData
}

type FolderResponseData

type FolderResponseData struct {
	VaultId         string
	Name            string
	Id              string
	ParentId        string
	Path            []PathData
	FoldersAmount   int
	PasswordsAmount int
	ShortcutsAmount int
	Access          int
}

type FolderSearchRequest

type FolderSearchRequest struct {
	Query   string `json:"query"`
	VaultId string `json:"vaultId"`
}

type FolderSearchResponse

type FolderSearchResponse struct {
	Status string
	Code   string
	Data   []FolderResponseData
}

type LoginResponse

type LoginResponse struct {
	Status string
	Data   LoginResponseData
}

type LoginResponseData

type LoginResponseData struct {
	Token                 string
	RefreshToken          string
	TokenTtl              int
	RefreshTokenTtl       int
	TokenExpiredAt        int
	RefreshTokenExpiredAt int
	User                  User
}

type LogoutResponse added in v0.2.0

type LogoutResponse struct {
	Status string
	Data   string
}

type PasswordAttachmentData

type PasswordAttachmentData struct {
	Name          string `json:"name,omitempty"`
	Id            string `json:"id,omitempty"`
	EncryptedKey  string `json:"encryptedKey,omitempty"`
	Hash          string `json:"hash,omitempty"`
	EncryptedData string `json:"encryptedData,omitempty"`
}

type PasswordCustomData

type PasswordCustomData struct {
	Name  string `json:"name,omitempty"`
	Value string `json:"value,omitempty"`
	Type  string `json:"type,omitempty"`
}

type PasswordRequest

type PasswordRequest struct {
	Name            string                   `json:"name"`
	Login           string                   `json:"login,omitempty"`
	CryptedPassword string                   `json:"cryptedPassword,omitempty"`
	Url             string                   `json:"url,omitempty"`
	Description     string                   `json:"description,omitempty"`
	Custom          []PasswordCustomData     `json:"custom,omitempty"`
	Color           int                      `json:"color,omitempty"`
	Attachments     []PasswordAttachmentData `json:"attachments,omitempty"`
	Tags            []string                 `json:"tags,omitempty"`
	MasterHash      string                   `json:"masterHash,omitempty"`
	VaultId         string                   `json:"vaultId"`
	FolderId        string                   `json:"folderId,omitempty"`
	ShortcutId      string                   `json:"shortcutId,omitempty"`
}

type PasswordResponse

type PasswordResponse struct {
	Status string
	Code   string // passwordNull, accessDenied
	Data   PasswordResponseData
}

type PasswordResponseData

type PasswordResponseData struct {
	VaultId            string
	FolderId           string
	Custom             []PasswordCustomData
	Id                 string
	Name               string
	Login              string
	CryptedPassword    string
	CryptedKey         string
	Description        string
	Url                string
	Color              int
	Attachments        []PasswordAttachmentData
	Tags               []string
	Path               []PathData
	Access             string
	AccessCode         int
	Shortcut           PasswordShortcutData
	LastPasswordUpdate int
	UpdatedAt          string
	IsFavorite         bool
}

type PasswordSearchRequest

type PasswordSearchRequest struct {
	Query         string   `json:"query"`
	VaultId       string   `json:"vaultId"`
	Colors        []int    `json:"colors,omitempty"`
	Tags          []string `json:"tags,omitempty"`
	IncludeShared bool     `json:"includeShared,omitempty"`
}

type PasswordSearchResponse

type PasswordSearchResponse struct {
	Status string
	Code   string
	Data   []PasswordResponseData
}

type PasswordShortcutData

type PasswordShortcutData struct {
	Id         string
	PasswordId string
	VaultId    string
	FolderId   string
	Access     string
	AccessCode int
	CryptedKey string
}

type PathData

type PathData struct {
	Order int
	Name  string
	Type  string // Allowed: vault, folder, inbox
	Id    string
}

type User

type User struct {
	Name  string
	Email string
}

type VaultAddRequest

type VaultAddRequest struct {
	Name            string `json:"name"`
	PasswordCrypted string `json:"passwordCrypted,omitempty"`
	PasswordHash    string `json:"passwordHash"`
	Salt            string `json:"salt"`
	IsPrivate       bool   `json:"isPrivate,omitempty"`
	MpCrypted       string `json:"mpCrypted"`
}

type VaultEditRequest

type VaultEditRequest struct {
	Name string `json:"name"`
}

type VaultOperationResponse

type VaultOperationResponse struct {
	Status string // success
	Code   string // always vaultUpdated
	Data   string // Id of the Vault
}

type VaultResponse

type VaultResponse struct {
	Status string
	Code   string
	Data   VaultResponseData
}

type VaultResponseData

type VaultResponseData struct {
	Id                   string
	Name                 string
	VaultPasswordCrypted string
	Access               string
	Scope                string
	Visible              bool // only present in response when IsPrivate = true
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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