-
-
Notifications
You must be signed in to change notification settings - Fork 197
Kddimitrov/track command options #4181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
189f3f0
feat: add tracking for command options
KristianDD 97684f2
chroe: remove split object logic as we can't get reliable data.
KristianDD ee05e03
chore: fix comments
KristianDD 8abd9e3
chore: fix tests
KristianDD a521f36
feat: add private flag to some options to skip tracking for them
KristianDD d69244b
chore: fix comments
KristianDD 225c06c
chore: make hasSensitiveValue mandatory field
KristianDD 14901e2
chore: fix tests
KristianDD 26435cf
chore: mark some more options as sensitive
KristianDD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import * as path from "path"; | ||
import { TrackActionNames } from "../constants"; | ||
|
||
export class OptionsTracker { | ||
public static PASSWORD_DETECTION_STRING = "password"; | ||
public static PRIVATE_REPLACE_VALUE = "private"; | ||
public static PATH_REPLACE_VALUE = "_localpath"; | ||
public static SIZE_EXEEDED_REPLACE_VALUE = "sizeExceeded"; | ||
|
||
constructor( | ||
private $analyticsService: IAnalyticsService) { | ||
} | ||
|
||
public async trackOptions(options: IOptions) { | ||
const trackObject = this.getTrackObject(options); | ||
|
||
await this.$analyticsService.trackEventActionInGoogleAnalytics({ | ||
action: TrackActionNames.Options, | ||
additionalData: JSON.stringify(trackObject) | ||
}); | ||
} | ||
|
||
private getTrackObject(options: IOptions): IDictionary<any> { | ||
const optionsArgvCopy = _.cloneDeep(options.argv); | ||
|
||
return this.sanitizeTrackObject(optionsArgvCopy, options); | ||
} | ||
|
||
private sanitizeTrackObject(data: IDictionary<any>, options?: IOptions): IDictionary<any> { | ||
const shorthands = options ? options.shorthands : []; | ||
const optionsDefinitions = options ? options.options : {}; | ||
|
||
_.forEach(data, (value, key) => { | ||
if (this.shouldSkipProperty(key, value, shorthands, optionsDefinitions)) { | ||
delete data[key]; | ||
} else { | ||
if (options && optionsDefinitions[key] && optionsDefinitions[key].private) { | ||
value = OptionsTracker.PRIVATE_REPLACE_VALUE; | ||
} else if (key.toLowerCase().indexOf(OptionsTracker.PASSWORD_DETECTION_STRING) >= 0) { | ||
value = OptionsTracker.PRIVATE_REPLACE_VALUE; | ||
} else if (_.isString(value) && value !== path.basename(value)) { | ||
value = OptionsTracker.PATH_REPLACE_VALUE; | ||
} else if (_.isObject(value) && !_.isArray(value)) { | ||
value = this.sanitizeTrackObject(value); | ||
} | ||
|
||
data[key] = value; | ||
} | ||
}); | ||
|
||
return data; | ||
} | ||
|
||
private shouldSkipProperty(key: string, value: any, shorthands: string[] = [], options: IDictionary<IDashedOption> = {}): Boolean { | ||
if (shorthands.indexOf(key) >= 0) { | ||
return true; | ||
} | ||
|
||
if (key.indexOf("-") >= 0) { | ||
return true; | ||
} | ||
|
||
if (key === "_") { | ||
return true; | ||
} | ||
|
||
const optionDef = options[key]; | ||
if (optionDef && optionDef.type === OptionType.Boolean) { | ||
if (optionDef.default !== true && value === false || optionDef.default === true && value === true) { | ||
return true; | ||
} | ||
} | ||
|
||
if (_.isUndefined(value)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
$injector.register("optionsTracker", OptionsTracker); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private -> hasSensitiveValue