State handles state requests
(ctx context.Context)
| 1293 | |
| 1294 | // State handles state requests |
| 1295 | func (s *Server) State(ctx context.Context) (*api.Response, error) { |
| 1296 | if ctx.Err() != nil { |
| 1297 | return nil, ctx.Err() |
| 1298 | } |
| 1299 | |
| 1300 | if err := AuthorizeGuardians(ctx); err != nil { |
| 1301 | return nil, err |
| 1302 | } |
| 1303 | |
| 1304 | ms := worker.GetMembershipState() |
| 1305 | if ms == nil { |
| 1306 | return nil, errors.Errorf("No membership state found") |
| 1307 | } |
| 1308 | |
| 1309 | if err := filterTablets(ctx, ms); err != nil { |
| 1310 | return nil, err |
| 1311 | } |
| 1312 | |
| 1313 | m := protojson.MarshalOptions{EmitUnpopulated: true} |
| 1314 | jsonState, err := m.Marshal(ms) |
| 1315 | if err != nil { |
| 1316 | return nil, errors.Errorf("Error marshalling state information to JSON") |
| 1317 | } |
| 1318 | |
| 1319 | return &api.Response{Json: jsonState}, nil |
| 1320 | } |
| 1321 | |
| 1322 | func getAuthMode(ctx context.Context) AuthMode { |
| 1323 | if auth := ctx.Value(Authorize); auth == nil || auth.(bool) { |
no test coverage detected