|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
| 6 | +import * as crypto from 'crypto'; |
6 | 7 | import * as fs from 'fs'; |
7 | 8 | import * as os from 'os'; |
8 | 9 | import * as util from './common'; |
@@ -33,6 +34,34 @@ export class LinuxDistribution { |
33 | 34 | return `name=${this.name}, version=${this.version}`; |
34 | 35 | } |
35 | 36 |
|
| 37 | + /** |
| 38 | + * Returns a string representation of LinuxDistribution that only returns the |
| 39 | + * distro name if it appears on an allowed list of known distros. Otherwise, |
| 40 | + * it returns 'other'. |
| 41 | + */ |
| 42 | + public toTelemetryString(): string { |
| 43 | + const allowedList = [ |
| 44 | + 'antergos', 'arch', 'centos', 'debian', 'deepin', 'elementary', 'fedora', |
| 45 | + 'galliumos', 'gentoo', 'kali', 'linuxmint', 'manjoro', 'neon', 'opensuse', |
| 46 | + 'parrot', 'rhel', 'ubuntu', 'zorin' |
| 47 | + ]; |
| 48 | + |
| 49 | + if (this.name === unknown || allowedList.indexOf(this.name) >= 0) { |
| 50 | + return this.toString(); |
| 51 | + } |
| 52 | + else { |
| 53 | + // Having a hash of the name will be helpful to identify spikes in the 'other' |
| 54 | + // bucket when a new distro becomes popular and needs to be added to the |
| 55 | + // allowed list above. |
| 56 | + const hash = crypto.createHash('sha256'); |
| 57 | + hash.update(this.name); |
| 58 | + |
| 59 | + const hashedName = hash.digest('hex'); |
| 60 | + |
| 61 | + return `other (${hashedName})`; |
| 62 | + } |
| 63 | + } |
| 64 | + |
36 | 65 | private static FromFilePath(filePath: string): Promise<LinuxDistribution> { |
37 | 66 | return new Promise<LinuxDistribution>((resolve, reject) => { |
38 | 67 | fs.readFile(filePath, 'utf8', (error, data) => { |
|
0 commit comments