MCPcopy
hub / github.com/Place1/wg-access-server / DeleteDevice

Method DeleteDevice

internal/services/device_service.go:53–75  ·  view source on GitHub ↗
(ctx context.Context, req *proto.DeleteDeviceReq)

Source from the content-addressed store, hash-verified

51}
52
53func (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
77func (d *DeviceService) ListAllDevices(ctx context.Context, req *proto.ListAllDevicesReq) (*proto.ListAllDevicesRes, error) {
78 user, err := authsession.CurrentUser(ctx)

Callers

nothing calls this directly

Calls 4

CurrentUserFunction · 0.92
ContainsMethod · 0.80
DeleteDeviceMethod · 0.65
GetNameMethod · 0.45

Tested by

no test coverage detected