Skip to content

Instantly share code, notes, and snippets.

@shukebeta
Last active March 15, 2020 04:38
We sometimes need to import user-secrets from one project to another, especially in the same solution. Though it may be not a good practice, requirements are requirements.
#!/usr/bin/php
<?php
if (sizeof($_SERVER['argv']) != 3) {
exit("Usage: {$_SERVER['argv'][0]} from_project_path to_project_path");
}
$pwd = getcwd();
if (!chdir($_SERVER['argv'][1])) {
exit("cd {$_SERVER['argv'][1]} failed");
}
$secrets_list = `dotnet user-secrets list`;
if ($secrets_list == '') {
exit("No secrets found in source project.");
}
if (!chdir($pwd)) {
exit("cd $pwd failed");
}
if (!chdir($_SERVER['argv'][2])) {
exit("cd {$_SERVER['argv'][2]} failed");
}
$secrets_list = preg_split('/\r?\n/', $secrets_list);
foreach($secrets_list as $line) {
if (!trim($line)) {
continue;
}
$line = explode(' = ', $line);
`dotnet user-secrets set $line[0] $line[1]`;
}
echo "success!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment