Home

git-age @1143ef4bfd45527cbf9faa94cc69c557bc00579b - refs - log -
-
https://git.jolheiser.com/git-age.git
git-crypt, but with age
git-age / cmd / config.go
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd

import (
	"fmt"
	"os"

	"filippo.io/age"
	"filippo.io/age/agessh"
	"gopkg.in/yaml.v3"
)

// Config is the configuration for git-age
type Config map[string]Recipients

type Recipients []string

// Recipients parses age recipients from recipient strings
func (r Recipients) Recipients() ([]age.Recipient, error) {
	var recipients []age.Recipient
	for _, rstr := range r {
		var rec age.Recipient
		rec, err := age.ParseX25519Recipient(rstr)
		if err != nil {
			if debug {
				fmt.Fprintf(os.Stderr, "could not parse recipient %q with age, trying ssh next: %v\n", rstr, err)
			}
			rec, err = agessh.ParseRecipient(rstr)
			if err != nil {
				return recipients, err
			}
		}
		recipients = append(recipients, rec)
	}
	return recipients, nil
}

// LoadConfig decodes .git-age.yaml into an AgeConfig
func LoadConfig() (Config, error) {
	var cfg Config
	fi, err := os.Open(".git-age.yaml")
	if err != nil {
		return cfg, err
	}
	defer fi.Close()
	return cfg, yaml.NewDecoder(fi).Decode(&cfg)
}