MCPcopy Index your code
hub / github.com/kopia/kopia / run

Method run

cli/command_policy_import.go:38–112  ·  view source on GitHub ↗
(ctx context.Context, rep repo.RepositoryWriter)

Source from the content-addressed store, hash-verified

36}
37
38func (c *commandPolicyImport) run(ctx context.Context, rep repo.RepositoryWriter) error {
39 var input io.Reader
40
41 var err error
42
43 if c.filePath != "" {
44 file, err := os.Open(c.filePath)
45 if err != nil {
46 return errors.Wrap(err, "unable to read policy file")
47 }
48
49 defer file.Close() //nolint:errcheck
50
51 input = file
52 } else {
53 input = c.svc.stdin()
54 }
55
56 policies := make(map[string]*policy.Policy)
57 d := json.NewDecoder(input)
58
59 if !c.allowUnknownFields {
60 d.DisallowUnknownFields()
61 }
62
63 err = d.Decode(&policies)
64 if err != nil {
65 return errors.Wrap(err, "unable to decode policy file as valid json")
66 }
67
68 var targetLimit []snapshot.SourceInfo
69
70 if c.global || len(c.targets) > 0 {
71 targetLimit, err = c.policyTargets(ctx, rep)
72 if err != nil {
73 return err
74 }
75 }
76
77 shouldImportSource := func(target snapshot.SourceInfo) bool {
78 if targetLimit == nil {
79 return true
80 }
81
82 return slices.Contains(targetLimit, target)
83 }
84
85 importedSources := make([]string, 0, len(policies))
86
87 for ts, newPolicy := range policies {
88 target, err := snapshot.ParseSourceInfo(ts, rep.ClientOptions().Hostname, rep.ClientOptions().Username)
89 if err != nil {
90 return errors.Wrapf(err, "unable to parse source info: %q", ts)
91 }
92
93 if !shouldImportSource(target) {
94 continue
95 }

Callers

nothing calls this directly

Calls 9

ParseSourceInfoFunction · 0.92
SetPolicyFunction · 0.92
deleteOthersFunction · 0.85
policyTargetsMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65
stdinMethod · 0.65
ClientOptionsMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected