feat: use v2 API for agent lifecycle updates (#12278)

Agent uses the v2 API to post lifecycle updates.

Part of #10534
This commit is contained in:
Spike Curtis
2024-02-23 15:24:28 +04:00
committed by GitHub
parent ee7828a166
commit aa7a9f5cc4
5 changed files with 100 additions and 57 deletions
+19
View File
@@ -311,3 +311,22 @@ func ProtoFromLog(log Log) (*proto.Log, error) {
Level: proto.Log_Level(lvl),
}, nil
}
func ProtoFromLifecycle(req PostLifecycleRequest) (*proto.Lifecycle, error) {
s, ok := proto.Lifecycle_State_value[strings.ToUpper(string(req.State))]
if !ok {
return nil, xerrors.Errorf("unknown lifecycle state: %s", req.State)
}
return &proto.Lifecycle{
State: proto.Lifecycle_State(s),
ChangedAt: timestamppb.New(req.ChangedAt),
}, nil
}
func LifecycleStateFromProto(s proto.Lifecycle_State) (codersdk.WorkspaceAgentLifecycle, error) {
caps, ok := proto.Lifecycle_State_name[int32(s)]
if !ok {
return "", xerrors.Errorf("unknown lifecycle state: %d", s)
}
return codersdk.WorkspaceAgentLifecycle(strings.ToLower(caps)), nil
}