// Fetch and decode a namespace from pfconfig given a pfconfig compatible struct
// This will fetch the json representation from pfconfig and decode it into o
// o must be a pointer to the struct as this should be used by reference
760213
func FetchDecodeSocket(ctx context.Context, o PfconfigObject) error {
	ptrT := reflect.TypeOf(o)
	new := reflect.New(ptrT.Elem())
	newo := new.Interface().(PfconfigObject)

	transferMetadata(ctx, &o, &newo)

	reflect.ValueOf(o).Elem().Set(reflect.ValueOf(newo).Elem())

	query := createQuery(ctx, o)

	jsonResponse := FetchSocket(ctx, query.GetPayload())

	if query.method == "keys" {
		if cs, ok := o.(PfconfigKeysInt); ok {
			decodeInterface(ctx, query.encoding, jsonResponse, cs.GetKeys())
		} else {
			panic("Wrong struct type for keys. Required PfconfigKeysInt")
		}
	} else if metadataFromField(ctx, o, "PfconfigArray") == "yes" || metadataFromField(ctx, o, "PfconfigDecodeInElement") == "yes" {
		decodeInterface(ctx, query.encoding, jsonResponse, &o)
	} else {
		receiver := &PfconfigElementResponse{}
		decodeInterface(ctx, query.encoding, jsonResponse, receiver)
		if receiver.Element != nil {
			b, _ := receiver.Element.MarshalJSON()
			decodeInterface(ctx, query.encoding, b, &o)
		} else {
			return errors.New(fmt.Sprintf("Element in response was invalid. Response was: %s", jsonResponse))
		}
	}

	o.SetLoadedAt(time.Now())

	return nil
}
1369314
func (s *PresenceService) GetNamespace(name string) (*services.Namespace, error) {
	if name == "" {
		return nil, trace.BadParameter("missing namespace name")
	}
	item, err := s.Get(context.TODO(), backend.Key(namespacesPrefix, name, paramsPrefix))
	if err != nil {
		if trace.IsNotFound(err) {
			return nil, trace.NotFound("namespace %q is not found", name)
		}
		return nil, trace.Wrap(err)
	}
	return services.UnmarshalNamespace(
		item.Value, services.WithResourceID(item.ID), services.WithExpires(item.Expires))
}
532833
func (v *version) Namespaces() NamespaceInformer {
	return &namespaceInformer{factory: v.factory, tweakListOptions: v.tweakListOptions}
}
1274705
func getNamespaceByName(name string, ns *corev1.Namespace, client kubernetes.Interface) (*corev1.Namespace, error) {
	if ns != nil && name == ns.Name {
		return ns, nil
	}
	return client.CoreV1().Namespaces().Get(name, metav1.GetOptions{})
}
452580
func Namespace(c context.Context, namespace string) (context.Context, error) {
	if !validNamespace.MatchString(namespace) {
		return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", namespace, validNamespace)
	}
	n := &namespacedContext{
		ctx:       c,
		namespace: namespace,
	}
	return internal.WithNamespace(internal.WithCallOverride(c, n.call), namespace), nil
}
84847
func GetNamespaceEngine(config map[string]string) TSDSDBEngine {
	db := golkeyval.GetDBEngine(config["DBEngine"])
	db.Configure(config)
	db.CreateDB()

	ns := golkeyvalNS.GetNSDBEngine(config["NSEngine"])
	ns.Configure(db)

	tsds := GetTSDSDBEngine("namespace")
	tsds.Configure(ns)
	return tsds
}
1034543
func FetchKeys(ctx context.Context, name string) ([]string, error) {
	keys := PfconfigKeys{PfconfigNS: name}
	err := FetchDecodeSocket(ctx, &keys)
	if err != nil {
		return nil, err
	}

	return keys.Keys, nil
}
1074680
func (c *Client) NamespaceService() namespaces.Store {
	if c.namespaceStore != nil {
		return c.namespaceStore
	}
	c.connMu.Lock()
	defer c.connMu.Unlock()
	return NewNamespaceStoreFromClient(namespacesapi.NewNamespacesClient(c.conn))
}
35624
func FetchDecodeSocketCache(ctx context.Context, o PfconfigObject) (bool, error) {
	query := createQuery(ctx, o)
	ctx = log.AddToLogContext(ctx, "PfconfigObject", query.GetIdentifier())

	// If the resource is still valid and is already loaded
	if IsValid(ctx, o) {
		return false, nil
	}

	err := FetchDecodeSocket(ctx, o)
	return true, err
}
922494
func NamespaceKeyRootFunc(ctx context.Context, prefix string) string {
	key := prefix
	ns, ok := genericapirequest.NamespaceFrom(ctx)
	if ok && len(ns) > 0 {
		key = key + "/" + ns
	}
	return key
}
989895
func (s *namespaceLister) Get(name string) (*v1.Namespace, error) {
	obj, exists, err := s.indexer.GetByKey(name)
	if err != nil {
		return nil, err
	}
	if !exists {
		return nil, errors.NewNotFound(v1.Resource("namespace"), name)
	}
	return obj.(*v1.Namespace), nil
}
1060122
func GetStructValueByNamespace(object interface{}, ns []string) interface{} {
	// current level of namespace
	current := ns[0]

	fields, err := reflections.Fields(object)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not return fields for object{%v}\n", object)
		return nil
	}

	for _, field := range fields {
		tag, err := reflections.GetFieldTag(object, field, "json")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Could not find tag for field{%s}\n", field)
			return nil
		}

		// remove omitempty from tag
		tag = strings.Split(tag, ",")[0]

		if tag == current {
			val, err := reflections.GetField(object, field)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Could not retrieve field{%s}\n", field)
				return nil
			}
			// handling of special cases for slice and map
			switch reflect.TypeOf(val).Kind() {
			case reflect.Slice:
				idx, _ := strconv.Atoi(ns[1])
				val := reflect.ValueOf(val)
				if val.Index(idx).Kind() == reflect.Struct {
					return GetStructValueByNamespace(val.Index(idx).Interface(), ns[2:])
				} else {
					return val.Index(idx).Interface()
				}
			case reflect.Map:
				key := ns[1]

				if vi, ok := val.(map[string]uint64); ok {
					return vi[key]
				}

				val := reflect.ValueOf(val)
				kval := reflect.ValueOf(key)
				if reflect.TypeOf(val.MapIndex(kval).Interface()).Kind() == reflect.Struct {
					return GetStructValueByNamespace(val.MapIndex(kval).Interface(), ns[2:])
				}
			case reflect.Ptr:
				v := reflect.Indirect(reflect.ValueOf(val))
				if !v.IsValid() || !v.CanInterface() {
					// If reflect can't call Interface() on v, we can't go deeper even if
					// len(ns) > 1. Therefore, we should just return nil here.
					return nil
				}

				if len(ns) == 1 {
					return v.Interface()
				} else {
					return GetStructValueByNamespace(v.Interface(), ns[1:])
				}
			default:
				// last ns, return value found
				if len(ns) == 1 {
					return val
				} else {
					// or go deeper
					return GetStructValueByNamespace(val, ns[1:])
				}
			}
		}
	}
	return nil
}
1057114
func Convert_v1_Namespace_To_core_Namespace(in *v1.Namespace, out *core.Namespace, s conversion.Scope) error {
	return autoConvert_v1_Namespace_To_core_Namespace(in, out, s)
}
791731
func (u *Unit) GetSpaceForBinding(bindingName string) (string, error) {
	app, err := u.Application()
	if err != nil {
		return "", errors.Trace(err)
	}

	bindings, err := app.EndpointBindings()
	if err != nil {
		return "", errors.Trace(err)
	}
	boundSpace, known := bindings[bindingName]
	if !known {
		// If default binding is not explicitly defined we'll use default space
		if bindingName == environs.DefaultSpaceName {
			return environs.DefaultSpaceName, nil
		}
		return "", errors.NewNotValid(nil, fmt.Sprintf("binding name %q not defined by the unit's charm", bindingName))
	}
	return boundSpace, nil
}
940225
func Namespace(ctx context.Context) (string, bool) {
	namespace, ok := ctx.Value(namespaceKey{}).(string)
	if !ok {
		return fromGRPCHeader(ctx)
	}

	return namespace, ok
}
138159
func NewNamespace() Namespace {
	return &namespace{
		taken: make(map[string]struct{}),
		gave:  make(map[string][]string),
	}
}
102852
func (g *NamespaceGetter) Get(key uint64, setFunc func() (size int, value Value)) *Handle {
	return g.Cache.Get(g.NS, key, setFunc)
}