Skip to content

Commit

Permalink
fix(grafanaplane): validate Stack slug
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic committed Dec 23, 2024
1 parent f9a598f commit b57f8c3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions grafanaplane/main.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,22 @@ local raw = import './raw.libsonnet';

cloud: {
local this = self,
local validStackSlug(slug) =
xtd.ascii.isLower(slug[0])
&& std.all(
std.map(
function(c)
xtd.ascii.isNumber(c)
|| xtd.ascii.isLower(c),
std.stringChars(slug)
)
),

stack: {
new(name, namespace, cloudProviderConfigName, secretName=name + '-providerConfigToken'): {
stack:
assert validStackSlug(name) :
'The slug/name needs to be a valid subdomain. One word. Only lowercase letters and numbers allowed. Must start with a letter. No dots, dashes, underscores, or spaces.';
raw.cloud.v1alpha1.stack.new(name)
+ raw.cloud.v1alpha1.stack.spec.parameters.providerConfigRef.withName(cloudProviderConfigName)
+ raw.cloud.v1alpha1.stack.spec.parameters.withExternalName(name)
Expand Down

0 comments on commit b57f8c3

Please sign in to comment.