(ctx context.Context, req *proto.DeleteDeviceReq)
| 51 | } |
| 52 | |
| 53 | func (d *DeviceService) DeleteDevice(ctx context.Context, req *proto.DeleteDeviceReq) (*empty.Empty, error) { |
| 54 | user, err := authsession.CurrentUser(ctx) |
| 55 | if err != nil { |
| 56 | return nil, status.Errorf(codes.PermissionDenied, "not authenticated") |
| 57 | } |
| 58 | |
| 59 | deviceOwner := user.Subject |
| 60 | |
| 61 | if req.Owner != nil { |
| 62 | if user.Claims.Contains("admin") { |
| 63 | deviceOwner = req.Owner.Value |
| 64 | } else { |
| 65 | return nil, status.Errorf(codes.PermissionDenied, "must be an admin") |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if err := d.DeviceManager.DeleteDevice(deviceOwner, req.GetName()); err != nil { |
| 70 | ctxlogrus.Extract(ctx).Error(err) |
| 71 | return nil, status.Errorf(codes.Internal, "failed to delete device") |
| 72 | } |
| 73 | |
| 74 | return &empty.Empty{}, nil |
| 75 | } |
| 76 | |
| 77 | func (d *DeviceService) ListAllDevices(ctx context.Context, req *proto.ListAllDevicesReq) (*proto.ListAllDevicesRes, error) { |
| 78 | user, err := authsession.CurrentUser(ctx) |
nothing calls this directly
no test coverage detected