Paul Hinze 8b5d4b8631
Update and address protobuf package deprecations
These changes address the following warning showing up on `go get`
operations:

    go: module github.com/golang/protobuf is deprecated: Use the
    "google.golang.org/protobuf" module instead.

All changes are made using the recommendations in the per-function
deprecation notices from the docs at
https://pkg.go.dev/github.com/golang/protobuf/ptypes
2022-06-08 11:51:19 -05:00

38 lines
1.0 KiB
Go

package server
import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
)
// NewStatus returns a new Status message with the given initial state.
func NewStatus(init vagrant_server.Status_State) *vagrant_server.Status {
return &vagrant_server.Status{
State: init,
StartTime: timestamppb.Now(),
}
}
// StatusSetError sets the error state on the status and marks the
// completion time.
func StatusSetError(s *vagrant_server.Status, err error) {
st, ok := status.FromError(err)
if !ok {
st = status.Newf(codes.Internal, "Non-status error %T: %s", err, err)
}
s.State = vagrant_server.Status_ERROR
s.Error = st.Proto()
s.CompleteTime = timestamppb.Now()
}
// StatusSetSuccess sets state of the status to success and marks the
// completion time.
func StatusSetSuccess(s *vagrant_server.Status) {
s.State = vagrant_server.Status_SUCCESS
s.CompleteTime = timestamppb.Now()
}