Skip to content

Commit ac44c6f

Browse files
authored
Added experimental support for reflections to FortiOS devices (#27)
1 parent 9932108 commit ac44c6f

File tree

7 files changed

+411
-1
lines changed

7 files changed

+411
-1
lines changed

ES.Kubernetes.Reflector.CertManager/SecretEtcher.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ void MatchAnnotations(Dictionary<string, string> pairs)
136136
{
137137
Annotations.CertManagerCertificate.SecretReflectionAutoNamespaces,
138138
Annotations.Reflection.AutoNamespaces
139+
},
140+
{
141+
Annotations.CertManagerCertificate.SecretFortiEnabled,
142+
Annotations.Reflection.FortiEnabled
143+
},
144+
{
145+
Annotations.CertManagerCertificate.SecretFortiHosts,
146+
Annotations.Reflection.FortiHosts
147+
},
148+
{
149+
Annotations.CertManagerCertificate.SecretFortiCertificate,
150+
Annotations.Reflection.FortiCertificate
139151
}
140152
});
141153

ES.Kubernetes.Reflector.Core/Constants/Annotations.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public static class Reflection
1414
public static string AutoNamespaces => $"{Prefix}/reflection-auto-namespaces";
1515

1616

17+
public static string FortiEnabled => $"{Prefix}/reflection-forti-enabled";
18+
public static string FortiHosts => $"{Prefix}/reflection-forti-hosts";
19+
public static string FortiCertificate => $"{Prefix}/reflection-forti-certificate";
20+
21+
1722
public static string AutoReflects => $"{Prefix}/auto-reflects";
1823
public static string Reflects => $"{Prefix}/reflects";
1924
public static string ReflectedVersion => $"{Prefix}/reflected-version";
@@ -27,6 +32,10 @@ public static class CertManagerCertificate
2732

2833
public static string SecretReflectionAutoEnabled => $"{Prefix}/secret-reflection-auto-enabled";
2934
public static string SecretReflectionAutoNamespaces => $"{Prefix}/secret-reflection-auto-namespaces";
35+
36+
public static string SecretFortiEnabled => $"{Prefix}/secret-reflection-forti-enabled";
37+
public static string SecretFortiHosts => $"{Prefix}/secret-reflection-forti-hosts";
38+
public static string SecretFortiCertificate => $"{Prefix}/secret-reflection-forti-certificate";
3039
}
3140
}
3241
}

ES.Kubernetes.Reflector.Core/Extensions/MetadataExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,31 @@ private static bool PatternListMatch(string patternList, string value)
112112
.Select(pattern => Regex.Match(value, pattern))
113113
.Any(match => match.Success && match.Value.Length == value.Length);
114114
}
115+
116+
public static bool FortiReflectionEnabled(this V1ObjectMeta metadata)
117+
{
118+
if (metadata.SafeAnnotations().TryGetValue(Annotations.Reflection.FortiEnabled, out var raw) &&
119+
bool.TryParse(raw, out var value))
120+
return value;
121+
return false;
122+
}
123+
124+
public static string[] FortiReflectionHosts(this V1ObjectMeta metadata)
125+
{
126+
return metadata.SafeAnnotations().TryGetValue(Annotations.Reflection.FortiHosts, out var raw)
127+
? string.IsNullOrWhiteSpace(raw) ? Array.Empty<string>() :
128+
raw.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries)
129+
.Where(s => !string.IsNullOrWhiteSpace(s))
130+
.Select(s => s.Trim()).Distinct().ToArray()
131+
: Array.Empty<string>();
132+
}
133+
134+
public static string FortiCertificate(this V1ObjectMeta metadata)
135+
{
136+
return metadata.SafeAnnotations().TryGetValue(Annotations.Reflection.FortiCertificate, out var raw)
137+
? string.IsNullOrWhiteSpace(raw) ? null : raw
138+
: null;
139+
}
140+
115141
}
116142
}

ES.Kubernetes.Reflector.Secrets/ES.Kubernetes.Reflector.Secrets.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<PackageReference Include="SSH.NET" Version="2016.1.0" />
9+
</ItemGroup>
10+
711
<ItemGroup>
812
<ProjectReference Include="..\ES.Kubernetes.Reflector.Core\ES.Kubernetes.Reflector.Core.csproj" />
913
</ItemGroup>

0 commit comments

Comments
 (0)