Work accross sites?

This commit is contained in:
Owen
2025-09-11 11:42:37 -07:00
parent 90188d4358
commit 612446c3c9
4 changed files with 40 additions and 35 deletions

View File

@@ -29,18 +29,11 @@ def convert_and_send(file_path, url, headers):
# This will be used to ensure the YAML is valid before sending
parsed_yaml = yaml.safe_load(yaml_content)
# Create the JSON payload. The curl request shows the value
# of "blueprint" is a string, which means the raw YAML content
# should be sent as a string value for that key.
json_payload = {
"blueprint": yaml_content
}
# convert the parsed YAML to a JSON string
json_payload = json.dumps(parsed_yaml)
# Convert the payload to a JSON string
json_string = json.dumps(json_payload)
# Base64 encode the JSON string
encoded_json = base64.b64encode(json_string.encode('utf-8')).decode('utf-8')
# Encode the JSON string to Base64
encoded_json = base64.b64encode(json_payload.encode('utf-8')).decode('utf-8')
# Create the final payload with the base64 encoded data
final_payload = {

View File

@@ -1,10 +1,10 @@
resources:
resource-nice-id:
resource-nice-id-duce:
name: this is my resource
protocol: http
full-domain: level1.test3.example.com
# host-header: example.com
# tls-server-name: example.com
host-header: example.com
tls-server-name: example.com
auth:
pincode: 123456
password: sadfasdfadsf
@@ -16,22 +16,23 @@ resources:
whitelist-users:
- owen@fossorial.io
targets:
# - site: glossy-plains-viscacha-rat
# - hostname: localhost
# method: http
# port: 8000
# healthcheck:
# port: 8000
# hostname: localhost
# - site: glossy-plains-viscacha-rat
# - hostname: localhost
# method: http
# port: 8001
# resource-nice-id2:
# name: this is other resource
# protocol: tcp
# proxy-port: 3000
# targets:
# # - site: glossy-plains-viscacha-rat
# - hostname: localhost
# port: 3000
- site: lively-yosemite-toad
hostname: localhost
method: http
port: 8000
- site: slim-alpine-chipmunk
hostname: localhost
method: http
port: 8001
- site: glossy-plains-viscacha-rat
hostname: localhost
method: http
port: 8001
resource-nice-id2:
name: this is other resource
protocol: tcp
proxy-port: 3000
targets:
- site: glossy-plains-viscacha-rat
hostname: localhost
port: 3000

View File

@@ -247,11 +247,12 @@ export async function updateResources(
// Create new targets
for (const [index, targetData] of resourceData.targets.entries()) {
if (!targetData) {
if (!targetData || (typeof targetData === 'object' && Object.keys(targetData).length === 0)) {
// If targetData is null or an empty object, we can skip it
continue;
}
const existingTarget = existingResourceTargets[index];
if (existingTarget) {
let targetSiteId = targetData.site;
let site;
@@ -281,7 +282,7 @@ export async function updateResources(
)
.limit(1);
} else {
throw new Error(`Target site ID is required`);
throw new Error(`Target site is required`);
}
if (!site) {
@@ -336,7 +337,16 @@ export async function updateResources(
const targetsToDelete = existingResourceTargets.slice(
resourceData.targets.length
);
logger.debug(`Targets to delete: ${JSON.stringify(targetsToDelete)}`);
for (const target of targetsToDelete) {
if (!target) {
continue;
}
if (siteId && target.siteId !== siteId) {
logger.debug(`Skipping target ${target.targetId} for deletion. Site ID does not match filter.`);
continue; // only delete targets for the specified siteId
}
logger.debug(`Deleting target ${target.targetId}`);
await trx
.delete(targets)
.where(eq(targets.targetId, target.targetId));

View File

@@ -98,6 +98,7 @@ export async function applyBlueprint(
const decoded = Buffer.from(blueprint, "base64").toString("utf-8");
// then parse the json
const blueprintParsed = JSON.parse(decoded);
// Update the blueprint in the database
await applyBlueprintFunc(orgId, blueprintParsed);
} catch (error) {