2019-01-12 04:58:27 +00:00
|
|
|
package wclayer
|
|
|
|
|
|
|
|
import (
|
2020-08-10 17:43:49 +00:00
|
|
|
"context"
|
|
|
|
|
2019-09-30 23:25:17 +00:00
|
|
|
"github.com/Microsoft/go-winio/pkg/guid"
|
2019-01-12 04:58:27 +00:00
|
|
|
"github.com/Microsoft/hcsshim/internal/hcserror"
|
2020-08-10 17:43:49 +00:00
|
|
|
"github.com/Microsoft/hcsshim/internal/oc"
|
|
|
|
"go.opencensus.io/trace"
|
2019-01-12 04:58:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NameToGuid converts the given string into a GUID using the algorithm in the
|
|
|
|
// Host Compute Service, ensuring GUIDs generated with the same string are common
|
|
|
|
// across all clients.
|
2020-08-10 17:43:49 +00:00
|
|
|
func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) {
|
2019-07-10 00:29:38 +00:00
|
|
|
title := "hcsshim::NameToGuid"
|
2021-07-20 17:59:04 +00:00
|
|
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
2020-08-10 17:43:49 +00:00
|
|
|
defer span.End()
|
|
|
|
defer func() { oc.SetSpanStatus(span, err) }()
|
|
|
|
span.AddAttributes(trace.StringAttribute("name", name))
|
2019-01-12 04:58:27 +00:00
|
|
|
|
2020-08-10 17:43:49 +00:00
|
|
|
var id guid.GUID
|
2019-01-12 04:58:27 +00:00
|
|
|
err = nameToGuid(name, &id)
|
|
|
|
if err != nil {
|
2020-08-10 17:43:49 +00:00
|
|
|
return guid.GUID{}, hcserror.New(err, title+" - failed", "")
|
2019-01-12 04:58:27 +00:00
|
|
|
}
|
2020-08-10 17:43:49 +00:00
|
|
|
span.AddAttributes(trace.StringAttribute("guid", id.String()))
|
|
|
|
return id, nil
|
2019-01-12 04:58:27 +00:00
|
|
|
}
|