occson

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2021 License: MIT Imports: 7 Imported by: 0

README

go-occson

Go Reference

This package provides a client for the API of occson.com - a configuration control system.

Downloading a document's contents

import (
	occson "github.com/occson/go-occson"
)

func main() {
	// Not sure where to get these? Check out occson.com!
	uri := "ccs://golang-test.toml"
	token := "decafc0ffeebad"
	passphrase := "deadbeef"

	// Sets up the document struct using a helper
	doc := occson.NewDocument(uri, token, passphrase)

	// Performs the actual request and decryption
	decrypted, err := doc.Download()

	if err != nil {
		panic(err)
	}

	// Prints out plaintext of the document
	fmt.Println(string(decrypted))
}

Uploading new encrypted contents

import (
	occson "github.com/occson/go-occson"
)

func main() {
	uri := "ccs://golang-test.toml"
	token := "decafc0ffeebad"
	passphrase := "deadbeef"


	// Sets up the document struct using a helper
	doc := occson.NewDocument(uri, token, passphrase)

	// Our new plaintext contents
	blob := `
		[config]
		param = "some_param"
	`

	// Performs the encryption and upload of ciphertext
	doc.Upload(blob, true)
}

Documentation

Index

Constants

View Source
const API = "https://api.occson.com/"

API endpoint for Occson.

View Source
const SCHEME = "ccs://"

Defines the scheme which denotes a CCS URL.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	// URI of the document. Can and should begin with the "ccs://" schema.
	Uri string
	// Auth token of the appropriate workspace.
	Token string
	// Document passphrase.
	Passphrase string
	// contains filtered or unexported fields
}

func NewDocument

func NewDocument(uri, token, passphrase string) Document

Helper function to create a document struct quickly.

func (*Document) Download

func (doc *Document) Download() ([]byte, error)

Downloads the given document from Occson, returning its decrypted contents. Authentication uses the Token field, decryption uses the Passphrase field.

func (*Document) Upload

func (doc *Document) Upload(content string, force bool) error

Encrypts and uploads the given content, optionally overwriting the contents already in Occson. Authentication uses the Token field, encryption uses the Passphrase field.

type Request

type Request struct {
	// Encrypted content for upload.
	EncryptedContent string `json:"encrypted_content"`
	// Whether the document should be overwritten, even if it exists.
	Force string `json:"force"`
}

type Response

type Response struct {
	// Requested document's internal ID.
	Id string
	// Requested document's path.
	Path string
	// Requested document's encrypted content (before decryption).
	EncryptedContent string `json:"encrypted_content"`
	// Document's workspace internal ID.
	WorkspaceId string `json:"workspace_id"`
	// Document's creation time, in ISO8601 format.
	CreatedAt string `json:"created_at"`
	// Document's last update time, in ISO8601 format.
	UpdatedAt string `json:"updated_at"`
}

Jump to

Keyboard shortcuts

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