mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user