Update dependencies to add service fabric mesh via new azure-sdk-go

This commit is contained in:
Jeremy Rickard
2018-08-03 11:57:00 -06:00
parent bcea8b955b
commit 636b4120f1
130 changed files with 9430 additions and 9975 deletions

View File

@@ -129,6 +129,10 @@ func (o *Operation) ID() string {
return o.id
}
func (o *Operation) Auditf(format string, args ...interface{}) {
o.Infof(format, args...)
}
func (o *Operation) Infof(format string, args ...interface{}) {
o.Info(fmt.Sprintf(format, args...))
}
@@ -213,13 +217,22 @@ func (o *Operation) Fatal(args ...interface{}) {
}
}
func (o *Operation) newChild(ctx context.Context, msg string) Operation {
child := newOperation(ctx, o.id, 4, msg)
func (o Operation) newChildCommon(ctx context.Context, opID string, msg string) Operation {
child := newOperation(ctx, opID, 5, msg)
child.t = append(child.t, o.t...)
child.Logger = o.Logger
return child
}
func (o Operation) newChild(ctx context.Context, msg string) Operation {
return o.newChildCommon(ctx, o.id, msg)
}
func (o Operation) newChildWithChainedID(ctx context.Context, msg string) Operation {
childOpID := fmt.Sprintf("%s.%d", o.id, atomic.AddUint64(&opCount, 1))
return o.newChildCommon(ctx, childOpID, msg)
}
func opID(opNum uint64) string {
return fmt.Sprintf("%d.%d", opIDPrefix, opNum)
}
@@ -233,6 +246,24 @@ func NewOperation(ctx context.Context, format string, args ...interface{}) Opera
return o
}
// NewOperationFromID returns a an Operation with the incoming ID if valid
// It creates a parent operation with the incoming ID and a child with
// the parent operation ID as a prefix and a monotonically incremented
// integer as the suffix
func NewOperationFromID(ctx context.Context, ID *string, format string, args ...interface{}) Operation {
var o Operation
if ID == nil || *ID == "" {
o = newOperation(ctx, opID(atomic.AddUint64(&opCount, 1)), 3, fmt.Sprintf(format, args...))
} else {
msg := fmt.Sprintf(format, args...)
o = newOperation(ctx, *ID, 3, msg).newChildWithChainedID(ctx, msg)
}
frame := o.t[0]
o.Debugf("[NewOperationFromID] %s [%s:%d]", o.header(), frame.funcName, frame.lineNo)
return o
}
// NewOperationWithLoggerFrom will return a new operation with operationID added as a value to the
// context and logging settings copied from the supplied operation.
//

View File

@@ -108,7 +108,7 @@ func newTrace(msg string, skip int, opID string) *Message {
// Begin starts the trace. Msg is the msg to log.
// context provided to allow tracing of operationID
// context added as optional to avoid breaking current usage
func Begin(msg string, ctx ...context.Context) *Message {
func begin(msg string, ctx ...context.Context) *Message {
if tracingEnabled && Logger.Level >= logrus.DebugLevel {
var opID string
// populate operationID if provided
@@ -117,7 +117,7 @@ func Begin(msg string, ctx ...context.Context) *Message {
opID = id
}
}
if t := newTrace(msg, 2, opID); t != nil {
if t := newTrace(msg, 3, opID); t != nil {
if msg == "" {
Logger.Debugf("[BEGIN] %s [%s:%d]", t.operationID, t.funcName, t.lineNo)
} else {
@@ -130,6 +130,19 @@ func Begin(msg string, ctx ...context.Context) *Message {
return nil
}
func Begin(msg string, ctx ...context.Context) *Message {
return begin(msg, ctx...)
}
// Audit is a wrapper around Begin which logs an Audit message after
func Audit(msg string, op Operation) *Message {
m := begin(msg, op)
if len(op.t) > 0 { // We expect an operation to always have at least one frame, but check for safety
op.Auditf(op.t[0].msg)
}
return m
}
// End ends the trace.
func End(t *Message) {
if t == nil {

View File

@@ -60,7 +60,7 @@ func init() {
// decode is the generic switcher that decides which decoder to use for a field
func decode(src DataSource, dest reflect.Value, prefix string, depth recursion) (reflect.Value, error) {
// if depth has reached zero, we skip decoding entirely
if depth.depth == 0 {
if depth.depth == 0 || depth.skipDecode {
return dest, nil
}
depth.depth--
@@ -445,7 +445,7 @@ func Decode(src DataSource, dest interface{}) interface{} {
}
// #nosec: Errors unhandled.
value, _ := decode(src, reflect.ValueOf(dest), DefaultPrefix, Unbounded)
value, _ := decode(src, reflect.ValueOf(dest), "", Unbounded)
return value.Interface()
}

View File

@@ -42,7 +42,7 @@ func GuestInfoSourceWithPrefix(prefix string) (DataSource, error) {
source := func(key string) (string, error) {
if key != GuestInfoSecretKey {
key = addPrefixToKey(DefaultGuestInfoPrefix, prefix, key)
key = addPrefixToKey(defaultGuestInfoPrefix(), prefix, key)
}
value, err := guestinfo.String(key, "")

View File

@@ -62,7 +62,7 @@ func init() {
// decode is the generic switcher that decides which decoder to use for a field
func encode(sink DataSink, src reflect.Value, prefix string, depth recursion) {
// if depth has reached zero, we skip encoding entirely
if depth.depth == 0 {
if depth.depth == 0 || depth.skipEncode {
return
}
depth.depth--
@@ -258,7 +258,7 @@ type DataSink func(string, string) error
// Encode serializes the given type to the supplied data sink
func Encode(sink DataSink, src interface{}) {
encode(sink, reflect.ValueOf(src), DefaultPrefix, Unbounded)
encode(sink, reflect.ValueOf(src), "", Unbounded)
}
// EncodeWithPrefix serializes the given type to the supplied data sink, using

View File

@@ -47,7 +47,7 @@ func GuestInfoSinkWithPrefix(prefix string) (DataSink, error) {
return nil
}
key = addPrefixToKey(DefaultGuestInfoPrefix, prefix, key)
key = addPrefixToKey(defaultGuestInfoPrefix(), prefix, key)
if value == "" {
value = "<nil>"

View File

@@ -27,23 +27,64 @@ import (
)
const (
// DefaultTagName value
// GuestInfoPrefix is dictated by vSphere
GuestInfoPrefix = "guestinfo."
// ScopeTag is the tag name used for declaring scopes for a field
ScopeTag = "scope"
// KeyTag is the tag name by which to override default key naming based on field name
KeyTag = "key"
// RecurseTag is the tag name with which different recursion properties are declared
RecurseTag = "recurse"
// HiddenScope means the key is hidden from the guest and will not have a GuestInfoPrefix
HiddenScope = "hidden"
// ReadOnlyScope means the key is read-only from the guest
ReadOnlyScope = "read-only"
// ReadWriteScope means the key may be read and modified by the guest
ReadWriteScope = "read-write"
// VolatileScope means that the value is expected to change and should be refreshed on use
VolatileScope = "volatile"
// SecretSuffix means the value should be encrypted in the vmx.
SecretSuffix = "secret"
// NonPersistentSuffix means the key should only be written if the key will be deleted on guest power off.
NonPersistentSuffix = "non-persistent"
// RecurseDepthProperty controls how deep to recuse into a structure field from this level. A value of zero
// prevents both encode and decode of that field. This is provided to control recursion into unannotated structures.
// This is unbounded if not specified.
RecurseDepthProperty = "depth"
// RecurseFollowProperty instructs encode and decode to follow pointers.
RecurseFollowProperty = "follow"
// RecurseNoFollowProperty instructs encode and decode not to follow pointers.
RecurseNoFollowProperty = "nofollow"
// RecurseSkipEncodeProperty causes the marked field and subfields to be skipped when encoding.
RecurseSkipEncodeProperty = "skip-encode"
// RecurseSkipDecodeProperty causes the marked field and subfields to be skipped when decoding.
RecurseSkipDecodeProperty = "skip-decode"
)
// TODO: this entire section of variables should be turned into a config struct
// that can be passed to Encode and Decode, or that Encode and Decode are method on
var (
// DefaultTagName is the annotation tag name we use for basic semantic version. Not currently used.
DefaultTagName = "vic"
// DefaultPrefix value
DefaultPrefix = ""
// DefaultGuestInfoPrefix value
DefaultGuestInfoPrefix = "guestinfo.vice."
// DefaultPrefix is prepended to generated key paths for basic namespacing
DefaultPrefix = "vice."
//Separator for slice values and map keys
Separator = "|"
// suffix separator character
suffixSeparator = "@"
// secret suffix
secretSuffix = "secret"
// non-persistent suffix
nonpersistentSuffix = "non-persistent"
)
func defaultGuestInfoPrefix() string {
return GuestInfoPrefix + DefaultPrefix
}
const (
// Invalid value
Invalid = 1 << iota
@@ -51,6 +92,8 @@ const (
Hidden
// ReadOnly value
ReadOnly
// WriteOnly value
WriteOnly
// ReadWrite value
ReadWrite
// NonPersistent value
@@ -66,6 +109,10 @@ type recursion struct {
depth int
// follow controls whether we follow pointers
follow bool
// set to skip decode of a field but still allow encode
skipDecode bool
// set to skip encode of a field but still allow decode
skipEncode bool
}
// Unbounded is the value used for unbounded recursion
@@ -103,17 +150,17 @@ func calculateScope(scopes []string) uint {
for _, v := range scopes {
switch v {
case "hidden":
case HiddenScope:
scope |= Hidden
case "read-only":
case ReadOnlyScope:
scope |= ReadOnly
case "read-write":
case ReadWriteScope:
scope |= ReadWrite
case nonpersistentSuffix:
scope |= NonPersistent
case "volatile":
case VolatileScope:
scope |= Volatile
case secretSuffix:
case NonPersistentSuffix:
scope |= NonPersistent
case SecretSuffix:
scope |= Secret | ReadOnly
default:
return Invalid
@@ -130,7 +177,7 @@ func isSecret(key string) bool {
}
for i := range suffix[1:] {
if suffix[i+1] == secretSuffix {
if suffix[i+1] == SecretSuffix {
return true
}
}
@@ -146,7 +193,7 @@ func isNonPersistent(key string) bool {
}
for i := range suffix[1:] {
if suffix[i+1] == nonpersistentSuffix {
if suffix[i+1] == NonPersistentSuffix {
return true
}
}
@@ -157,22 +204,22 @@ func isNonPersistent(key string) bool {
func calculateScopeFromKey(key string) []string {
scopes := []string{}
if !strings.HasPrefix(key, DefaultGuestInfoPrefix) {
scopes = append(scopes, "hidden")
if !strings.HasPrefix(key, GuestInfoPrefix) {
scopes = append(scopes, HiddenScope)
}
if strings.Contains(key, "/") {
scopes = append(scopes, "read-only")
scopes = append(scopes, ReadOnlyScope)
} else {
scopes = append(scopes, "read-write")
scopes = append(scopes, ReadWriteScope)
}
if isSecret(key) {
scopes = append(scopes, secretSuffix)
scopes = append(scopes, SecretSuffix)
}
if isNonPersistent(key) {
scopes = append(scopes, nonpersistentSuffix)
scopes = append(scopes, NonPersistentSuffix)
}
return scopes
@@ -202,21 +249,21 @@ func calculateKeyFromField(field reflect.StructField, prefix string, depth recur
// do we have DefaultTagName?
if tags.Get(DefaultTagName) != "" {
// get the scopes
scopes = strings.Split(tags.Get("scope"), ",")
scopes = strings.Split(tags.Get(ScopeTag), ",")
logger.Debugf("Scopes: %#v", scopes)
// get the keys and split properties from it
key = tags.Get("key")
key = tags.Get(KeyTag)
logger.Debugf("Key specified: %s", key)
// get the keys and split properties from it
recurse := tags.Get("recurse")
recurse := tags.Get(RecurseTag)
if recurse != "" {
props := strings.Split(recurse, ",")
// process properties
for _, prop := range props {
// determine recursion depth
if strings.HasPrefix(prop, "depth") {
if strings.HasPrefix(prop, RecurseDepthProperty) {
parts := strings.Split(prop, "=")
if len(parts) != 2 {
logger.Warnf("Skipping field with incorrect recurse property: %s", prop)
@@ -229,10 +276,14 @@ func calculateKeyFromField(field reflect.StructField, prefix string, depth recur
return "", skip
}
fdepth.depth = int(val)
} else if prop == "nofollow" {
} else if prop == RecurseNoFollowProperty {
fdepth.follow = false
} else if prop == "follow" {
} else if prop == RecurseFollowProperty {
fdepth.follow = true
} else if prop == RecurseSkipDecodeProperty {
fdepth.skipDecode = true
} else if prop == RecurseSkipEncodeProperty {
fdepth.skipEncode = true
} else {
logger.Warnf("Ignoring unknown recurse property %s (%s)", key, prop)
continue
@@ -278,7 +329,7 @@ func calculateKey(scope uint, prefix string, key string) string {
hide := scope&Hidden != 0
write := scope&ReadWrite != 0
visible := strings.HasPrefix(prefix, DefaultGuestInfoPrefix)
visible := strings.HasPrefix(prefix, GuestInfoPrefix)
if !hide && write {
oldSep = "/"
@@ -298,7 +349,7 @@ func calculateKey(scope uint, prefix string, key string) string {
}
if scope&Secret != 0 {
out += suffixSeparator + secretSuffix
out += suffixSeparator + SecretSuffix
}
if scope&NonPersistent != 0 {
@@ -306,7 +357,7 @@ func calculateKey(scope uint, prefix string, key string) string {
logger.Debugf("Unable to combine non-persistent and hidden scopes")
return ""
}
out += suffixSeparator + nonpersistentSuffix
out += suffixSeparator + NonPersistentSuffix
}
// we don't care about existing separators when hiden
@@ -316,7 +367,7 @@ func calculateKey(scope uint, prefix string, key string) string {
}
// strip the prefix and the leading r/w signifier
return out[len(DefaultGuestInfoPrefix)+1:]
return out[len(defaultGuestInfoPrefix())+1:]
}
// ensure that separators are correct
@@ -324,11 +375,11 @@ func calculateKey(scope uint, prefix string, key string) string {
// Assemble the base that controls key publishing in guest
if !visible {
return DefaultGuestInfoPrefix + newSep + out
return defaultGuestInfoPrefix() + newSep + out
}
// prefix will have been mangled by strings.Replace
return DefaultGuestInfoPrefix + out[len(DefaultGuestInfoPrefix):]
return defaultGuestInfoPrefix() + out[len(defaultGuestInfoPrefix()):]
}
// utility function to allow adding of arbitrary prefix into key
@@ -508,3 +559,14 @@ func calculateKeys(v reflect.Value, field string, prefix string) []string {
func CalculateKeys(obj interface{}, field string, prefix string) []string {
return calculateKeys(reflect.ValueOf(obj), field, prefix)
}
// CalculateKey is a specific case of CalculateKeys that will panic if more than one key
// matches the field pattern passed in.
func CalculateKey(obj interface{}, field string, prefix string) string {
keys := calculateKeys(reflect.ValueOf(obj), field, prefix)
if len(keys) != 1 {
panic("CalculateKey should only ever return one key")
}
return keys[0]
}

View File

@@ -27,7 +27,7 @@ import (
// The value of this key is hidden from API requests, but visible within the guest
// #nosec: Potential hardcoded credentials
const GuestInfoSecretKey = "guestinfo.ovfEnv"
const GuestInfoSecretKey = GuestInfoPrefix + "ovfEnv"
// SecretKey provides helpers to encrypt/decrypt extraconfig values
type SecretKey struct {

View File

@@ -226,6 +226,9 @@ func (s *Session) Connect(ctx context.Context) (*Session, error) {
}
soapClient.UserAgent = s.UserAgent
if s.UserAgent == "" {
op.Debug("DEVNOTICE: Session created with default user agent.")
}
soapClient.SetThumbprint(soapURL.Host, s.Thumbprint)
@@ -366,10 +369,46 @@ func (s *Session) Populate(ctx context.Context) (*Session, error) {
op.Debugf("Cached pool: %s", s.PoolPath)
}
err = s.setDatacenterFolders(op)
if err != nil {
errs = append(errs, fmt.Sprintf("Failure finding folders (%s): %s", s.DatacenterPath, err.Error()))
}
if len(errs) > 0 {
op.Debugf("Error count populating vSphere cache: (%d)", len(errs))
return nil, errors.New(strings.Join(errs, "\n"))
}
op.Debug("vSphere resource cache populated...")
return s, nil
}
func (s *Session) SetDatacenter(op trace.Operation, datacenter *object.Datacenter) error {
s.Datacenter = datacenter
s.Finder.SetDatacenter(datacenter)
if datacenter == nil {
s.DatacenterPath = ""
return nil
}
s.DatacenterPath = datacenter.InventoryPath
// Do what Populate would have done if datacenterPath were set
err := s.setDatacenterFolders(op)
if err != nil {
return err
}
return nil
}
func (s *Session) setDatacenterFolders(op trace.Operation) error {
var err error
if s.Datacenter != nil {
folders, err := s.Datacenter.Folders(op)
if err != nil {
errs = append(errs, fmt.Sprintf("Failure finding folders (%s): %s", s.DatacenterPath, err.Error()))
folders, e := s.Datacenter.Folders(op)
if e != nil {
err = e
} else {
op.Debugf("Cached folders: %s", s.DatacenterPath)
}
@@ -384,12 +423,7 @@ func (s *Session) Populate(ctx context.Context) (*Session, error) {
s.VCHFolder = folders.VmFolder
}
if len(errs) > 0 {
op.Debugf("Error count populating vSphere cache: (%d)", len(errs))
return nil, errors.New(strings.Join(errs, "\n"))
}
op.Debug("vSphere resource cache populated...")
return s, nil
return err
}
func (s *Session) logEnvironmentInfo(op trace.Operation) {