Skip to content

Commit

Permalink
fix(cli): don't create config.json files if none was present during t…
Browse files Browse the repository at this point in the history
…elemetry
  • Loading branch information
DanielMSchmidt committed Sep 21, 2021
1 parent 0c7464e commit 5e515ae
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/cdktf-cli/lib/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,31 @@ export async function sendTelemetry(
function getId(
filePath: string,
key: string,
forceCreation = false,
explanatoryComment?: string
): string {
// If the file doesn't exist, we don't have an ID. So we create a file with the ID for next time
const _uuid = uuidv4();
const _idFile = {} as Record<string, string>;
if (explanatoryComment) {
_idFile["//"] = explanatoryComment.replace(/\n/g, " ");
}
_idFile[key] = _uuid;
const _uuid = uuidv4(); // create a new UUID in case we don't find one

let jsonFile;
try {
jsonFile = require(filePath);
jsonFile = require(filePath); // we found the file
} catch {
fs.writeFileSync(filePath, JSON.stringify(_idFile, null, 2));
// we found no file, create one if we're forcing a creation
if (forceCreation) {
const _idFile = {} as Record<string, string>; // compose JSON id file in case we don't find one
if (explanatoryComment) {
_idFile["//"] = explanatoryComment.replace(/\n/g, " ");
}
_idFile[key] = _uuid;
fs.writeFileSync(filePath, JSON.stringify(_idFile, null, 2));
}
return _uuid;
}

if (jsonFile[key]) {
return jsonFile[key];
return jsonFile[key]; // we found an id
} else {
// we found no id, we add it to the file for future use
fs.writeFileSync(
filePath,
JSON.stringify({ ...jsonFile, [key]: _uuid }, null, 2)
Expand All @@ -122,6 +126,7 @@ function getUserId(): string {
return getId(
path.resolve(os.homedir(), ".cdktf", "config.json"),
"userId",
true,
`This signature is a randomly generated UUID used to anonymously differentiate users in telemetry data order to inform product direction.
This signature is random, it is not based on any personally identifiable information.
To create a new signature, you can simply delete this file at any time.
Expand Down

0 comments on commit 5e515ae

Please sign in to comment.