1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict'
|
6 |
|
7 | const util = require('./util')
|
8 | const debuglog = util.debuglog
|
9 | const flatList = util.flatList
|
10 | const execFileAsync = util.execFileAsync
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var Identity = module.exports.Identity = function (name, hash) {
|
18 | this.name = name
|
19 | this.hash = hash
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | module.exports.findIdentitiesAsync = function (opts, identity) {
|
30 |
|
31 |
|
32 |
|
33 | var args = [
|
34 | 'find-identity',
|
35 | '-v'
|
36 | ]
|
37 | if (opts.keychain) {
|
38 | args.push(opts.keychain)
|
39 | }
|
40 |
|
41 | return execFileAsync('security', args)
|
42 | .then(function (result) {
|
43 | return result.split('\n').map(function (line) {
|
44 | if (line.indexOf(identity) >= 0) {
|
45 | var identityFound = line.substring(line.indexOf('"') + 1, line.lastIndexOf('"'))
|
46 | var identityHashFound = line.substring(line.indexOf(')') + 2, line.indexOf('"') - 1)
|
47 | debuglog('Identity:', '\n',
|
48 | '> Name:', identityFound, '\n',
|
49 | '> Hash:', identityHashFound)
|
50 | return new Identity(identityFound, identityHashFound)
|
51 | }
|
52 | })
|
53 | })
|
54 | .then(flatList)
|
55 | }
|