MCPcopy Create free account
hub / github.com/chain/Core / addAllowedMember

Method addAllowedMember

core/membership.go:15–55  ·  view source on GitHub ↗
(ctx context.Context, x struct{ Addr string })

Source from the content-addressed store, hash-verified

13var errMissingAddr = errors.New("missing address")
14
15func (a *API) addAllowedMember(ctx context.Context, x struct{ Addr string }) error {
16 if x.Addr == "" {
17 return errMissingAddr
18 }
19 err := a.raftDB.AddAllowedMember(ctx, x.Addr)
20 if err != nil {
21 return errors.Wrap(err)
22 }
23
24 hostname, _, err := net.SplitHostPort(x.Addr)
25 if err != nil {
26 return errors.Wrap(err)
27 }
28
29 // only create a grant if we're using TLS
30 if !a.useTLS {
31 return nil
32 }
33
34 data := map[string]interface{}{
35 "subject": map[string]string{
36 "CN": hostname,
37 },
38 }
39
40 guardData, err := json.Marshal(data)
41 if err != nil {
42 return errors.Wrap(err)
43 }
44
45 grant := authz.Grant{
46 Policy: "internal",
47 GuardType: "x509",
48 GuardData: guardData,
49 CreatedAt: time.Now().UTC().Format(time.RFC3339),
50 Protected: true,
51 }
52
53 _, err = authz.StoreGrant(ctx, a.raftDB, grant, GrantPrefix)
54 return errors.Wrap(err)
55}

Callers 2

RunUnconfiguredFunction · 0.95
RunFunction · 0.95

Calls 2

AddAllowedMemberMethod · 0.80
FormatMethod · 0.80

Tested by

no test coverage detected