Skip to content

Commit

Permalink
Use Identity instance containing name and hash
Browse files Browse the repository at this point in the history
  • Loading branch information
sethlu committed Jun 1, 2017
1 parent 686aeb3 commit 97eb5fa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
6 changes: 5 additions & 1 deletion flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const debugwarn = util.debugwarn
const execFileAsync = util.execFileAsync
const validateOptsAppAsync = util.validateOptsAppAsync
const validateOptsPlatformAsync = util.validateOptsPlatformAsync
const Identity = require('./util-identities').findIdentitiesAsync
const findIdentitiesAsync = require('./util-identities').findIdentitiesAsync

/**
Expand Down Expand Up @@ -55,7 +56,7 @@ function validateFlatOptsAsync (opts) {
function flatApplicationAsync (opts) {
var args = [
'--component', opts.app, opts.install,
'--sign', opts.identity,
'--sign', opts.identity.name,
opts.pkg
]
if (opts.keychain) {
Expand All @@ -82,6 +83,9 @@ var flatAsync = module.exports.flatAsync = function (opts) {
var promise
if (opts.identity) {
debuglog('`identity` passed in arguments.')
if (opts['identity-validation'] === false || opts.identity instanceof Identity) {
return Promise.resolve()
}
promise = findIdentitiesAsync(opts, opts.identity)
} else {
debugwarn('No `identity` passed in arguments...')
Expand Down
10 changes: 5 additions & 5 deletions sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const execFileAsync = util.execFileAsync
const validateOptsAppAsync = util.validateOptsAppAsync
const validateOptsPlatformAsync = util.validateOptsPlatformAsync
const walkAsync = util.walkAsync
const Identity = require('./util-identities').Identity
const findIdentitiesAsync = require('./util-identities').findIdentitiesAsync
const ProvisioningProfile = require('./util-provisioning-profiles').ProvisioningProfile
const preEmbedProvisioningProfile = require('./util-provisioning-profiles').preEmbedProvisioningProfile
const preAutoEntitlements = require('./util-entitlements').preAutoEntitlements

Expand Down Expand Up @@ -47,8 +49,6 @@ function validateOptsBinariesAsync (opts) {
* @returns {Promise} Promise.
*/
function validateSignOptsAsync (opts) {
const ProvisioningProfile = require('./util-provisioning-profiles').ProvisioningProfile

if (opts.ignore) {
if (typeof opts.ignore !== 'function' && typeof opts.ignore !== 'string') return Promise.reject(new Error('Ignore filter should be either a function or a string.'))
}
Expand Down Expand Up @@ -134,7 +134,7 @@ function signApplicationAsync (opts) {
if (opts.binaries) childPaths = childPaths.concat(opts.binaries)

var args = [
'--sign', opts.identity,
'--sign', opts.identity.hash || opts.identity.name,
'--force'
]
if (opts.keychain) {
Expand Down Expand Up @@ -222,7 +222,7 @@ var signAsync = module.exports.signAsync = function (opts) {
var promise
if (opts.identity) {
debuglog('`identity` passed in arguments.')
if (opts['identity-validation'] === false) {
if (opts['identity-validation'] === false || opts.identity instanceof Identity) {
return Promise.resolve()
}
promise = findIdentitiesAsync(opts, opts.identity)
Expand All @@ -244,7 +244,7 @@ var signAsync = module.exports.signAsync = function (opts) {
return promise
.then(function (identities) {
if (identities.length > 0) {
// Provisioning profile(s) found
// Identity(/ies) found
if (identities.length > 1) {
debugwarn('Multiple identities found, will use the first discovered.')
} else {
Expand Down
2 changes: 1 addition & 1 deletion util-entitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports.preAutoEntitlements = function (opts) {
appInfo.ElectronTeamID = opts['provisioning-profile'].message.Entitlements['com.apple.developer.team-identifier']
debuglog('`ElectronTeamID` not found in `Info.plist`, use parsed from provisioning profile: ' + appInfo.ElectronTeamID)
} else {
appInfo.ElectronTeamID = opts.identity.substring(opts.identity.indexOf('(') + 1, opts.identity.lastIndexOf(')'))
appInfo.ElectronTeamID = opts.identity.name.substring(opts.identity.name.indexOf('(') + 1, opts.identity.name.lastIndexOf(')'))
debuglog('`ElectronTeamID` not found in `Info.plist`, use parsed from signing identity: ' + appInfo.ElectronTeamID)
}
return writeFileAsync(appInfoPath, plist.build(appInfo), 'utf8')
Expand Down
12 changes: 11 additions & 1 deletion util-identities.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ const debuglog = util.debuglog
const flatList = util.flatList
const execFileAsync = util.execFileAsync

/**
* @constructor
* @param {string} name - Name of the signing identity.
* @param {String} hash - SHA-1 hash of the identity.
*/
var Identity = module.exports.Identity = function (name, hash) {
this.name = name
this.hash = hash
}

/**
* This function returns a promise checking the indentity proposed and updates the identity option to a exact finding from results.
* @function
Expand Down Expand Up @@ -37,7 +47,7 @@ module.exports.findIdentitiesAsync = function (opts, identity) {
debuglog('Identity:', '\n',
'> Name:', identityFound, '\n',
'> Hash:', identityHashFound)
return identityHashFound
return new Identity(identityFound, identityHashFound)
}
})
})
Expand Down

0 comments on commit 97eb5fa

Please sign in to comment.