Skip to content

Commit aeeeae2

Browse files
committed
Adds proper type for GUIDs in Cloud Foundry;
1 parent 3029ed8 commit aeeeae2

File tree

4 files changed

+66
-34
lines changed

4 files changed

+66
-34
lines changed

devbox.lock

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -601,37 +601,6 @@
601601
}
602602
}
603603
},
604-
"github:NixOS/nixpkgs/nixpkgs-unstable": {
605-
"resolved": "github:NixOS/nixpkgs/b3582c75c7f21ce0b429898980eddbbf05c68e55?lastModified=1746576598&narHash=sha256-FshoQvr6Aor5SnORVvh%2FZdJ1Sa2U4ZrIMwKBX5k2wu0%3D"
606-
},
607-
"glibcLocales@latest": {
608-
"last_modified": "2025-05-06T08:06:31Z",
609-
"resolved": "github:NixOS/nixpkgs/1cb1c02a6b1b7cf67e3d7731cbbf327a53da9679#glibcLocales",
610-
"source": "devbox-search",
611-
"version": "2.40-66",
612-
"systems": {
613-
"aarch64-linux": {
614-
"outputs": [
615-
{
616-
"name": "out",
617-
"path": "/nix/store/7af0gzp82zy3g8gn9khxwj60npcsmbvh-glibc-locales-2.40-66",
618-
"default": true
619-
}
620-
],
621-
"store_path": "/nix/store/6k49f7lzfvbfwx995xfz1n7nhjnzwdx2-ginkgo-2.23.4"
622-
},
623-
"x86_64-linux": {
624-
"outputs": [
625-
{
626-
"name": "out",
627-
"path": "/nix/store/szgq7mx93ihzlhv8jxb9fcb2l5ad22fy-ginkgo-2.23.4",
628-
"default": true
629-
}
630-
],
631-
"store_path": "/nix/store/szgq7mx93ihzlhv8jxb9fcb2l5ad22fy-ginkgo-2.23.4"
632-
}
633-
}
634-
},
635604
"gnumake@4.4": {
636605
"last_modified": "2025-05-20T08:00:33Z",
637606
"resolved": "github:NixOS/nixpkgs/2f9173bde1d3fbf1ad26ff6d52f952f9e9da52ea#gnumake",
@@ -1290,7 +1259,7 @@
12901259
},
12911260
"mysql@10.6.12": {
12921261
"last_modified": "2023-02-24T09:01:09Z",
1293-
"plugin_version": "0.0.4",
1262+
"plugin_version": "0.0.3",
12941263
"resolved": "github:NixOS/nixpkgs/7d0ed7f2e5aea07ab22ccb338d27fbe347ed2f11#mysql",
12951264
"source": "devbox-search",
12961265
"version": "10.6.12"
@@ -1534,7 +1503,7 @@
15341503
},
15351504
"python@3.13.3": {
15361505
"last_modified": "2025-05-16T20:19:48Z",
1537-
"plugin_version": "0.0.4",
1506+
"plugin_version": "0.0.3",
15381507
"resolved": "github:NixOS/nixpkgs/12a55407652e04dcf2309436eb06fef0d3713ef3#python313",
15391508
"source": "devbox-search",
15401509
"version": "3.13.3",

src/autoscaler/api/binding_request/clean_parser/json-structure.go

Whitespace-only changes.

src/autoscaler/api/binding_request/legacy_parser/json-structure.go

Whitespace-only changes.

src/autoscaler/models/app.go

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
package models
22

3-
import "time"
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"fmt"
7+
"os"
8+
"regexp"
9+
"text/template/parse"
10+
"time"
11+
)
412

513
type ScalingType int
614
type ScalingStatus int
@@ -45,3 +53,58 @@ type AppScalingResult struct {
4553
Adjustment int `json:"adjustment"`
4654
CooldownExpiredAt int64 `json:"cool_down_expired_at"`
4755
}
56+
57+
// Globally unique identifier in the context of a “Cloud Foundry” installation;
58+
type CfGuid string
59+
60+
func (g CfGuid) String() string {
61+
return string(g)
62+
}
63+
64+
type CfGuidParser struct {
65+
regexp *regexp.Regexp
66+
}
67+
68+
func NewCfGuidParser() CfGuidParser {
69+
filePath := "../../../schema/json/shared_definitions.json"
70+
jsonData, err := os.ReadFile(filePath)
71+
if err != nil {
72+
// fmt.Errorf("Could not read file \"%s\"\nError: %w", filePath, err)
73+
panic(`Assumed guid-schema not found.
74+
This is a programming-error as the file must be on the hardcorded location.`)
75+
}
76+
77+
type Schema struct {
78+
Schemas struct {
79+
Guid struct {
80+
Pattern string `json:"pattern"`
81+
} `json:"guid"`
82+
} `json:"schemas"`
83+
}
84+
var schema Schema
85+
json.Unmarshal(jsonData, schema)
86+
pattern := schema.Schemas.Guid.Pattern
87+
88+
r, err := regexp.CompilePOSIX(pattern)
89+
if err != nil {
90+
panic(`The provided pattern is invalid.
91+
This is a programming-error as the pattern must be a valid POSIX-regexp.`)
92+
}
93+
94+
return CfGuidParser{regexp: r}
95+
}
96+
97+
func (p CfGuidParser) Parse(rawGuid string) (CfGuid, error) {
98+
matched := p.regexp.MatchString(rawGuid) // regexp.MatchString(p.regexp, rawGuid)
99+
if ! matched {
100+
msg := fmt.Sprintf("The provided string does not look like a Cloud Foundry GUID: %s", rawGuid)
101+
return "<guid-parsing-error>", errors.New(msg)
102+
}
103+
104+
return CfGuid(rawGuid), nil
105+
}
106+
107+
func ParseGuid(rawGuid string) (CfGuid, error) {
108+
p := NewCfGuidParser()
109+
return p.Parse(rawGuid)
110+
}

0 commit comments

Comments
 (0)