flatjson

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package flatjson contains facilities to extract credentials that are expressed as a single (flat) JSON object whose values are all strings.

This can be use to extract GCP service account keys, GCP API keys, etc.

Index

Constants

View Source
const (
	// DefaultMaxMatches is the default value for an Extractor's MaxMatches. It is
	// used to limit the number of matches to constrain runtime.
	DefaultMaxMatches = 20
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Extractor

type Extractor struct {

	// MaxMatches limits the number of matches to constrain runtime. The default
	// is 20 but it can be set arbitrarily, even to -1 in which case no limit is
	// applied.
	//
	// For example Although we're expecting only about 10 fields for GCP service
	// account keys, it makes sense to have a slightly larger limit, because
	// fields like "universe" get added to the key or people might add their own
	// metadata to the JSON structure.
	MaxMatches int
	// contains filtered or unexported fields
}

Extractor extracts key-value pairs with required or optional keys from an input. It assumes that the key-value pairs are contained in a flat JSON object as it is the case for e.g. GCP service account keys.

func NewExtractor

func NewExtractor(requiredKeys []string, optionalKeys []string) *Extractor

NewExtractor creates an Extractor that can be used to extract flat-JSON key-value pairs from an input. The requiredKeys take precedence; if a key is present in both requiredKeys and optionalKeys (although it really shouldn't be), it's considered required.

func (*Extractor) Extract

func (e *Extractor) Extract(data []byte) map[string]string

Extract extracts the required and optional keys alongside their values from the flat JSON object contained in data.

Jump to

Keyboard shortcuts

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