(ctx context.Context, x struct{ Addr string })
| 13 | var errMissingAddr = errors.New("missing address") |
| 14 | |
| 15 | func (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 | } |
no test coverage detected