public static ReflectorProperties GetReflectionProperties(this V1ObjectMeta metadata)
    {
        return(new ReflectorProperties
        {
            Version = metadata.ResourceVersion,

            Allowed = metadata.SafeAnnotations()
                      .TryGet(Annotations.Reflection.Allowed, out bool allowed) && allowed,
            AllowedNamespaces = metadata.SafeAnnotations()
                                .TryGet(Annotations.Reflection.AllowedNamespaces, out string?allowedNamespaces)
                ? allowedNamespaces ?? string.Empty
                : string.Empty,
            AutoEnabled = metadata.SafeAnnotations()
                          .TryGet(Annotations.Reflection.AutoEnabled, out bool autoEnabled) && autoEnabled,
            AutoNamespaces = metadata.SafeAnnotations()
                             .TryGet(Annotations.Reflection.AutoNamespaces, out string?autoNamespaces)
                ? autoNamespaces ?? string.Empty
                : string.Empty,
            Reflects = metadata.SafeAnnotations()
                       .TryGet(Annotations.Reflection.Reflects, out string?metaReflects)
                ? string.IsNullOrWhiteSpace(metaReflects) ? KubeRef.Empty :
                       KubeRef.TryParse(metaReflects, out var metaReflectsRef) ? metaReflectsRef.Namespace == string.Empty
                    ? new KubeRef(metadata.NamespaceProperty, metaReflectsRef.Name)
                    : metaReflectsRef : KubeRef.Empty
                : KubeRef.Empty,
            IsAutoReflection = metadata.SafeAnnotations()
                               .TryGet(Annotations.Reflection.MetaAutoReflects, out bool metaAutoReflects) && metaAutoReflects,
            ReflectedVersion = metadata.SafeAnnotations()
                               .TryGet(Annotations.Reflection.MetaReflectedVersion, out string?reflectedVersion)
                ? string.IsNullOrWhiteSpace(reflectedVersion) ? string.Empty : reflectedVersion
                : string.Empty
        });
Ejemplo n.º 2
0
 public static bool ReflectionAutoEnabled(this V1ObjectMeta metadata)
 {
     if (metadata.SafeAnnotations().TryGetValue(Annotations.Reflection.AutoEnabled, out var raw) &&
         bool.TryParse(raw, out var value))
     {
         return(value);
     }
     return(false);
 }
Ejemplo n.º 3
0
 public static string[] FortiReflectionHosts(this V1ObjectMeta metadata)
 {
     return(metadata.SafeAnnotations().TryGetValue(Annotations.Reflection.FortiHosts, out var raw)
         ? string.IsNullOrWhiteSpace(raw) ? Array.Empty <string>() :
            raw.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
            .Where(s => !string.IsNullOrWhiteSpace(s))
            .Select(s => s.Trim()).Distinct().ToArray()
         : Array.Empty <string>());
 }
Ejemplo n.º 4
0
        public static KubernetesObjectId AutoReflects(this V1ObjectMeta metadata)
        {
            if (metadata.SafeAnnotations().TryGetValue(Annotations.Reflection.AutoReflects, out var raw) &&
                KubernetesObjectId.TryParse(raw, out var value))
            {
                if (value.Namespace == null)
                {
                    return(new KubernetesObjectId(metadata.NamespaceProperty, value.Name));
                }
                return(value);
            }

            return(KubernetesObjectId.Empty);
        }
Ejemplo n.º 5
0
 public static string ReflectionAllowedNamespaces(this V1ObjectMeta metadata)
 {
     return(metadata.SafeAnnotations().TryGetValue(Annotations.Reflection.AllowedNamespaces, out var raw)
         ? string.IsNullOrWhiteSpace(raw) ? null : raw
         : null);
 }
Ejemplo n.º 6
0
 public static string FortiCertificate(this V1ObjectMeta metadata)
 {
     return(metadata.SafeAnnotations().TryGetValue(Annotations.Reflection.FortiCertificate, out var raw)
         ? string.IsNullOrWhiteSpace(raw) ? null : raw
         : null);
 }