Skip to content

Commit

Permalink
Merge pull request #70 from Peefy/add-more-flux-modules
Browse files Browse the repository at this point in the history
feat: add more validation modules about fluxcd
  • Loading branch information
Peefy authored Nov 13, 2023
2 parents 722f449 + 6468d24 commit 7d2dbcf
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 0 deletions.
7 changes: 7 additions & 0 deletions flux-check-buckets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Introduction

`flux-check-buckets` is a KCL validation module

## Resource

The Code source and documents are [here](https://github.com/kcl-lang/modules/tree/main/flux-check-buckets)
4 changes: 4 additions & 0 deletions flux-check-buckets/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "flux-check-buckets"
version = "0.1.1"
description = "`flux-check-buckets` is a KCL validation module"
13 changes: 13 additions & 0 deletions flux-check-buckets/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
endpoints: [str] = option("params")?.endpoints or []

# Define the validation function
validate = lambda item, endpoints: [str] {
if item.kind == "Bucket" and endpoints:
endpoint: str = item?.spec?.endpoint
assert any e in endpoints {
endpoint.endswith(e)
}, ".spec.endpoint must reference an address within the organizations ${endpoints}."
item
}
# Validate All resource
items = [validate(i, endpoints) for i in option("items") or []]
7 changes: 7 additions & 0 deletions flux-check-github-repositories/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Introduction

`flux-check-github-repositories` is a KCL validation module

## Resource

The Code source and documents are [here](https://github.com/kcl-lang/modules/tree/main/flux-check-github-repositories)
4 changes: 4 additions & 0 deletions flux-check-github-repositories/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "flux-check-github-repositories"
version = "0.1.1"
description = "`flux-check-github-repositories` is a KCL validation module"
13 changes: 13 additions & 0 deletions flux-check-github-repositories/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos: [str] = option("params")?.repos or []

# Define the validation function
validate = lambda item, repos: [str] {
if item.kind == "GitRepository" and repos:
url: str = item?.spec?.url
assert any r in repos {
url.startswith("https://github.com/${r}/") or url.startswith("ssh://[email protected]:${r}/")
}, ".spec.url must be from a repository within the myorg organization."
item
}
# Validate All resource
items = [validate(i, repos) for i in option("items") or []]
7 changes: 7 additions & 0 deletions flux-check-helm-repositories/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Introduction

`flux-check-helm-repositories` is a KCL validation module

## Resource

The Code source and documents are [here](https://github.com/kcl-lang/modules/tree/main/flux-check-helm-repositories)
4 changes: 4 additions & 0 deletions flux-check-helm-repositories/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "flux-check-helm-repositories"
version = "0.1.1"
description = "`flux-check-helm-repositories` is a KCL validation module"
15 changes: 15 additions & 0 deletions flux-check-helm-repositories/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import regex

repos: [str] = option("params")?.repos or []

# Define the validation function
validate = lambda item, repos: [str] {
if item.kind == "HelmRepository" and repos:
url: str = item?.spec?.url
assert any r in repos {
regex.match(url, "https://?*.${r}.com/*")
}, ".spec.url must be from a repository within the organizations ${repos}."
item
}
# Validate All resource
items = [validate(i, repos) for i in option("items") or []]
7 changes: 7 additions & 0 deletions flux-check-image-repositories/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Introduction

`flux-check-image-repositories` is a KCL validation module

## Resource

The Code source and documents are [here](https://github.com/kcl-lang/modules/tree/main/flux-check-image-repositories)
4 changes: 4 additions & 0 deletions flux-check-image-repositories/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "flux-check-image-repositories"
version = "0.1.1"
description = "`flux-check-image-repositories` is a KCL validation module"
13 changes: 13 additions & 0 deletions flux-check-image-repositories/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos: [str] = option("params")?.repos or []

# Define the validation function
validate = lambda item, repos: [str] {
if item.kind == "ImageRepository" and repos:
image: str = item?.spec?.image
assert any r in repos {
image.startswith(r)
}, ".spec.image must be from an image repository within the organizations ${repos}."
item
}
# Validate All resource
items = [validate(i, repos) for i in option("items") or []]
7 changes: 7 additions & 0 deletions flux-check-url/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Introduction

`flux-check-url` is a KCL validation module

## Resource

The Code source and documents are [here](https://github.com/kcl-lang/modules/tree/main/flux-check-url)
4 changes: 4 additions & 0 deletions flux-check-url/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "flux-check-url"
version = "0.1.1"
description = "`flux-check-url` is a KCL validation module"
16 changes: 16 additions & 0 deletions flux-check-url/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos: [str] = option("params")?.repos or []
urls: [str] = option("params")?.urls or []

# Define the validation function
validate = lambda item, repos: [str] {
if item.kind == "GitRepository" and urls and repos:
url: str = item?.spec?.url
assert any r in repos {
any u in urls {
url.startswith("${u}/${r}/")
}
}, ".spec.url must be from a repository within the urls ${urls} and repos ${repos}"
item
}
# Validate All resource
items = [validate(i, repos) for i in option("items") or []]

0 comments on commit 7d2dbcf

Please sign in to comment.