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

View File

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

View File

@@ -247,11 +247,12 @@ export async function updateResources(
// Create new targets // Create new targets
for (const [index, targetData] of resourceData.targets.entries()) { 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 // If targetData is null or an empty object, we can skip it
continue; continue;
} }
const existingTarget = existingResourceTargets[index]; const existingTarget = existingResourceTargets[index];
if (existingTarget) { if (existingTarget) {
let targetSiteId = targetData.site; let targetSiteId = targetData.site;
let site; let site;
@@ -281,7 +282,7 @@ export async function updateResources(
) )
.limit(1); .limit(1);
} else { } else {
throw new Error(`Target site ID is required`); throw new Error(`Target site is required`);
} }
if (!site) { if (!site) {
@@ -336,7 +337,16 @@ export async function updateResources(
const targetsToDelete = existingResourceTargets.slice( const targetsToDelete = existingResourceTargets.slice(
resourceData.targets.length resourceData.targets.length
); );
logger.debug(`Targets to delete: ${JSON.stringify(targetsToDelete)}`);
for (const target of 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 await trx
.delete(targets) .delete(targets)
.where(eq(targets.targetId, target.targetId)); .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"); const decoded = Buffer.from(blueprint, "base64").toString("utf-8");
// then parse the json // then parse the json
const blueprintParsed = JSON.parse(decoded); const blueprintParsed = JSON.parse(decoded);
// Update the blueprint in the database // Update the blueprint in the database
await applyBlueprintFunc(orgId, blueprintParsed); await applyBlueprintFunc(orgId, blueprintParsed);
} catch (error) { } catch (error) {