Skip to content

Commit

Permalink
chore: add item name to script to update single destination (#1837)
Browse files Browse the repository at this point in the history
  • Loading branch information
koladilip authored Dec 12, 2024
1 parent 391b43d commit 52f9bf2
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 57 deletions.
116 changes: 59 additions & 57 deletions scripts/deployToDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,67 @@
from constants import CONFIG_DIR


ALL_SELECTORS = ["destination", "source", "wht-lib-project"]


def get_command_line_arguments():
parser = argparse.ArgumentParser(description="Script to deploy config files to DB.")
parser.add_argument("control_plane_url", nargs="?", help="Control plane URL")
parser.add_argument("username", nargs="?", help="Control plane admin username")
parser.add_argument("password", nargs="?", help="Control plane admin password")
parser.add_argument(
"selector",
nargs="?",
help="Specify destination, source or wht-lib-project",
default=None,
)
parser.add_argument(
"item_name", nargs="?", help="Specific item name to update.", default=None
)

args = parser.parse_args()

control_plane_url = args.control_plane_url or os.getenv("CONTROL_PLANE_URL")
username = args.username or os.getenv("API_USER")
password = args.password or os.getenv("API_PASSWORD")
selector = args.selector or os.getenv("SELECTOR")
item_name = args.item_name or os.getenv("ITEM_NAME")

missing_args = []
invalid_args = []

if control_plane_url is None:
missing_args.append(
"1st positional argument or CONTROL_PLANE_URL environment variable"
invalid_args.append(
"1st positional argument or CONTROL_PLANE_URL environment variable is missing"
)
if username is None:
missing_args.append("2nd positional argument or API_USER environment variable")
invalid_args.append(
"2nd positional argument or API_USER environment variable is missing"
)
if password is None:
missing_args.append(
"3rd positional argument or API_PASSWORD environment variable"
invalid_args.append(
"3rd positional argument or API_PASSWORD environment variable is missing"
)
if selector is None:
SELECTORS = ALL_SELECTORS
elif selector not in ALL_SELECTORS:
invalid_args.append(
"4th positional argument or SELECTOR environment variable is invalid"
)
else:
SELECTORS = [selector]

if missing_args:
print("Error: Missing the following arguments or environment variables:")
for arg in missing_args:
if invalid_args:
print("Error: The following arguments or environment variables are invalid:")
for arg in invalid_args:
print(arg)
sys.exit(1)

return control_plane_url, username, password
return control_plane_url, username, password, SELECTORS, item_name


CONTROL_PLANE_URL, USERNAME, PASSWORD = get_command_line_arguments()
CONTROL_PLANE_URL, USERNAME, PASSWORD, SELECTORS, ITEM_NAME = (
get_command_line_arguments()
)

# CONSTANTS
HEADER = {"Content-Type": "application/json"}
Expand Down Expand Up @@ -139,11 +165,16 @@ def update_config(data_diff, selector):
return json.dumps(results, indent=2)


def update_diff_db(selector):
def update_diff_db(selector, item_name=None):
final_report = []

## data sets
current_items = os.listdir(f"./{CONFIG_DIR}/{selector}s")
if item_name:
current_items = [item_name]
else:
current_items = os.listdir(f"./{CONFIG_DIR}/{selector}s")

print(f"Current items: {current_items}")

for item in current_items:
# check if item is a directory
Expand Down Expand Up @@ -203,47 +234,18 @@ def get_stale_data(selector, report):


if __name__ == "__main__":
print("\n")
print("#" * 50)
print("Running Destination Definitions Updates")
dest_final_report = update_diff_db("destination")

print("\n")
print("#" * 50)
print("Destination Definition Update Report")
print(get_formatted_json(dest_final_report))

print("\n")
print("#" * 50)
print("Stale Destinations Report")
print(get_formatted_json(get_stale_data("destination", dest_final_report)))

print("\n")
print("#" * 50)
print("Running Source Definitions Updates")
src_final_report = update_diff_db("source")

print("\n")
print("#" * 50)
print("Source Definition Update Report")
print(get_formatted_json(src_final_report))

print("\n")
print("#" * 50)
print("Stale Sources Report")
print(get_formatted_json(get_stale_data("source", src_final_report)))

print("\n")
print("#" * 50)
print("Running Wht Lib Project Definitions Updates")
wht_final_report = update_diff_db("wht-lib-project")

print("\n")
print("#" * 50)
print("Wht Lib Project Definition Update Report")
print(get_formatted_json(wht_final_report))

print("\n")
print("#" * 50)
print("Stale Wht Lib Projects Report")
print(get_formatted_json(get_stale_data("wht-lib-project", wht_final_report)))
for selector in SELECTORS:
print("\n")
print("#" * 50)
print("Running {} Definitions Updates".format(selector.capitalize()))
final_report = update_diff_db(selector, ITEM_NAME)

print("\n")
print("#" * 50)
print("{} Definition Update Report".format(selector.capitalize()))
print(get_formatted_json(final_report))

print("\n")
print("#" * 50)
print("Stale {}s Report".format(selector.capitalize()))
print(get_formatted_json(get_stale_data(selector, final_report)))
48 changes: 48 additions & 0 deletions scripts/listJsonMapperDestinations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');

const destinationsDir = path.join(__dirname, '../src/configurations/destinations');

function findJsonMapperDestinations() {
try {
if (!fs.existsSync(destinationsDir)) {
throw new Error(`Destinations directory not found: ${destinationsDir}`);
}
return fs
.readdirSync(destinationsDir)
.map((destination) => {
try {
const destinationsFilePath = path.join(destinationsDir, destination, 'db-config.json');
if (!fs.existsSync(destinationsFilePath)) {
console.warn(`Skipping ${destination}: Missing configuration file`);
return null;
}
const destinationsContent = fs.readFileSync(destinationsFilePath, 'utf8');
const destinationDefinition = JSON.parse(destinationsContent);
if (!destinationDefinition.name) {
console.warn(`Skipping ${destination}: Missing name`);
return null;
}
return {
name: destinationDefinition.name,
config: destinationDefinition.config,
};
} catch (err) {
console.error(`Error processing ${destination}:`, err.message);
return null;
}
})
.filter(Boolean)
.filter(
(destination) =>
!destination.config?.disableJsonMapper && !destination.config?.supportsVisualMapper,
)
.map((destination) => destination.name);
} catch (err) {
console.error('Failed to process destinations:', err.message);
return [];
}
}

console.log(findJsonMapperDestinations().join('\n'));

0 comments on commit 52f9bf2

Please sign in to comment.