decrypt

package
v3.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MPL-2.0 Imports: 7 Imported by: 36

Documentation

Overview

Package decrypt is the external API other Go programs can use to decrypt SOPS files. It is the only package in SOPS with a stable API.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Data

func Data(data []byte, format string) (cleartext []byte, err error)

Data is a helper that takes encrypted data and a format string, decrypts the data and returns its cleartext in an []byte. The format string can be `json`, `yaml`, `ini`, `dotenv` or `binary`. If the format string is empty, binary format is assumed.

func DataWithFormat

func DataWithFormat(data []byte, format Format) (cleartext []byte, err error)

DataWithFormat is a helper that takes encrypted data, and a format enum value, decrypts the data and returns its cleartext in an []byte.

func File

func File(path, format string) (cleartext []byte, err error)

File is a wrapper around Data that reads a local encrypted file and returns its cleartext data in an []byte

Example
package main

import (
	"encoding/json"

	"github.com/getsops/sops/v3/logging"

	"github.com/sirupsen/logrus"
)

var log *logrus.Logger

func init() {
	log = logging.NewLogger("DECRYPT")
}

type configuration struct {
	FirstName string  `json:"firstName"`
	LastName  string  `json:"lastName"`
	Age       float64 `json:"age"`
	Address   struct {
		City          string `json:"city"`
		PostalCode    string `json:"postalCode"`
		State         string `json:"state"`
		StreetAddress string `json:"streetAddress"`
	} `json:"address"`
	PhoneNumbers []struct {
		Number string `json:"number"`
		Type   string `json:"type"`
	} `json:"phoneNumbers"`
	AnEmptyValue string `json:"anEmptyValue"`
}

func main() {
	var (
		confPath string = "./example.json"
		cfg      configuration
		err      error
	)
	confData, err := File(confPath, "json")
	if err != nil {
		log.Fatalf("cleartext configuration marshalling failed with error: %v", err)
	}
	err = json.Unmarshal(confData, &cfg)
	if err != nil {
		log.Fatalf("cleartext configuration unmarshalling failed with error: %v", err)
	}
	if cfg.FirstName != "John" ||
		cfg.LastName != "Smith" ||
		cfg.Age != 25.4 ||
		cfg.PhoneNumbers[1].Number != "646 555-4567" {
		log.Fatalf("configuration does not contain expected values: %+v", cfg)
	}
	log.Printf("%+v", cfg)
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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