Skip to content

Commit

Permalink
[eas-cli] merge everything from actions/new to actions (#364)
Browse files Browse the repository at this point in the history
delete unused actions

delete old inner class

remove uneeded dist cert utils

merge dist cert utils

remove unused functions of pprofile utils

pop out new directory
  • Loading branch information
quinlanj authored Apr 26, 2021
1 parent 5bfaee9 commit 1a7edbe
Show file tree
Hide file tree
Showing 41 changed files with 437 additions and 1,148 deletions.
2 changes: 1 addition & 1 deletion packages/eas-cli/src/build/ios/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createCredentialsContextAsync } from '../../credentials/context';
import IosCredentialsProvider, {
IosCredentials,
} from '../../credentials/ios/IosCredentialsProvider';
import { getAppLookupParamsFromContext } from '../../credentials/ios/actions/new/BuildCredentialsUtils';
import { getAppLookupParamsFromContext } from '../../credentials/ios/actions/BuildCredentialsUtils';
import { AppLookupParams } from '../../credentials/ios/credentials';
import { CredentialsResult } from '../build';
import { BuildContext } from '../context';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
testCommonIosAppCredentialsFragment,
} from '../../__tests__/fixtures-ios';
import { getNewIosApiMockWithoutCredentials } from '../../__tests__/fixtures-new-ios';
import { getAppLookupParamsFromContext } from '../../ios/actions/new/BuildCredentialsUtils';
import { getAppLookupParamsFromContext } from '../../ios/actions/BuildCredentialsUtils';
import { updateAndroidCredentialsAsync, updateIosCredentialsAsync } from '../update';

jest.mock('fs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createCtxMock } from '../../__tests__/fixtures-context';
import { testIosAppCredentialsWithBuildCredentialsQueryResult } from '../../__tests__/fixtures-ios';
import { getNewIosApiMockWithoutCredentials } from '../../__tests__/fixtures-new-ios';
import IosCredentialsProvider from '../IosCredentialsProvider';
import { getAppLookupParamsFromContext } from '../actions/new/BuildCredentialsUtils';
import { getAppLookupParamsFromContext } from '../actions/BuildCredentialsUtils';

jest.mock('fs');
jest.mock('../validators/validateProvisioningProfile', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppleTeamFragment } from '../../../../graphql/generated';
import { Context } from '../../../context';
import { AppLookupParams } from '../../api/GraphqlClient';
import { AppleTeamFragment } from '../../../graphql/generated';
import { Context } from '../../context';
import { AppLookupParams } from '../api/GraphqlClient';

export async function resolveAppleTeamIfAuthenticatedAsync(
ctx: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import {
AppleTeamFragment,
IosDistributionType as GraphQLIosDistributionType,
IosAppBuildCredentialsFragment,
} from '../../../../graphql/generated';
import {
getProjectAccountName,
getProjectConfigDescription,
} from '../../../../project/projectUtils';
import { findAccountByName } from '../../../../user/Account';
import { Context } from '../../../context';
import { AppLookupParams } from '../../api/GraphqlClient';
} from '../../../graphql/generated';
import { getProjectAccountName, getProjectConfigDescription } from '../../../project/projectUtils';
import { findAccountByName } from '../../../user/Account';
import { Context } from '../../context';
import { AppLookupParams } from '../api/GraphqlClient';
import { resolveAppleTeamIfAuthenticatedAsync } from './AppleTeamUtils';

export async function getAllBuildCredentialsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,109 @@ import assert from 'assert';
import chalk from 'chalk';
import ora from 'ora';

import {
AppleDistributionCertificateFragment,
AppleProvisioningProfileFragment,
} from '../../../graphql/generated';
import Log from '../../../log';
import { Action, CredentialsManager } from '../../CredentialsManager';
import { Context } from '../../context';
import {
DistributionCertificate,
ProvisioningProfileStoreInfo,
} from '../appstore/Credentials.types';
import { AppLookupParams } from '../credentials';
import { selectProvisioningProfileFromAppleAsync } from './ProvisioningProfileUtils';

export class UseExistingProvisioningProfile implements Action {
constructor(private app: AppLookupParams) {}

public async runAsync(manager: CredentialsManager, ctx: Context): Promise<void> {
const selected = await selectProvisioningProfileFromAppleAsync(ctx, this.app.bundleIdentifier);
if (selected) {
const distCert = await ctx.ios.getDistributionCertificateAsync(this.app);
assert(distCert, 'missing distribution certificate');
import { AppLookupParams } from '../api/GraphqlClient';
import { AppleProvisioningProfileMutationResult } from '../api/graphql/mutations/AppleProvisioningProfileMutation';
import { ProvisioningProfileStoreInfo } from '../appstore/Credentials.types';
import { AuthCtx } from '../appstore/authenticate';
import { MissingCredentialsNonInteractiveError } from '../errors';

await manager.runActionAsync(new ConfigureProvisioningProfile(this.app));
}
}
}
export class ConfigureProvisioningProfile {
constructor(
private app: AppLookupParams,
private distributionCertificate: AppleDistributionCertificateFragment,
private originalProvisioningProfile: AppleProvisioningProfileFragment
) {}

export class ConfigureProvisioningProfile implements Action {
constructor(private app: AppLookupParams) {}

public async runAsync(manager: CredentialsManager, ctx: Context): Promise<void> {
const profile = await ctx.ios.getProvisioningProfileAsync(this.app);
if (!profile) {
throw new Error('No provisioning profile to configure');
public async runAsync(ctx: Context): Promise<AppleProvisioningProfileMutationResult | null> {
if (ctx.nonInteractive) {
throw new MissingCredentialsNonInteractiveError(
'Configuring Provisioning Profiles is only supported in interactive mode.'
);
}

if (!profile.provisioningProfileId) {
Log.warn("The provisioning profile we have on file cannot be validated on Apple's servers.");
return;
const { developerPortalIdentifier, provisioningProfile } = this.originalProvisioningProfile;
if (!developerPortalIdentifier && !provisioningProfile) {
Log.warn("The provisioning profile we have on file cannot be configured on Apple's servers.");
return null;
}

if (ctx.appStore.authCtx) {
const distCert = await ctx.ios.getDistributionCertificateAsync(this.app);
if (!distCert) {
Log.warn('There is no distribution certificate for this app.');
return;
}
const profilesFromApple = await ctx.appStore.listProvisioningProfilesAsync(
this.app.bundleIdentifier
);
const profilesWithMatchingId = profilesFromApple.filter(
appleInfo => appleInfo.provisioningProfileId === profile.provisioningProfileId
);
if (!profilesWithMatchingId || profilesWithMatchingId.length < 1) {
Log.warn('This profile is no longer valid on Apple Developer Portal.');
}

await this.configureAndUpdateAsync(ctx, this.app, distCert, profilesWithMatchingId[0]);
} else {
if (!ctx.appStore.authCtx) {
Log.warn(
"Without access to your Apple account we can't configure provisioning profiles for you."
);
Log.warn('Make sure to recreate the profile if you selected a new distribution certificate.');
return null;
}

const profilesFromApple = await ctx.appStore.listProvisioningProfilesAsync(
this.app.bundleIdentifier
);
const [matchingProfile] = profilesFromApple.filter(appleInfo =>
developerPortalIdentifier
? appleInfo.provisioningProfileId === developerPortalIdentifier
: appleInfo.provisioningProfile === provisioningProfile
);
if (!matchingProfile) {
Log.warn(
`Profile ${
developerPortalIdentifier ? `${developerPortalIdentifier} ` : ''
}not found on Apple Developer Portal.`
);
return null;
}

return await this.configureAndUpdateAsync(ctx, ctx.appStore.authCtx, this.app, matchingProfile);
}

private async configureAndUpdateAsync(
ctx: Context,
authCtx: AuthCtx,
app: AppLookupParams,
distCert: DistributionCertificate,
profileFromApple: ProvisioningProfileStoreInfo
) {
): Promise<AppleProvisioningProfileMutationResult> {
const {
developerPortalIdentifier,
certificateP12,
certificatePassword,
serialNumber,
} = this.distributionCertificate;
assert(
certificateP12 && certificatePassword,
'Distribution Certificate P12 and Password is required'
);
// configure profile on Apple's Server to use our distCert
const updatedProfile = await ctx.appStore.useExistingProvisioningProfileAsync(
app.bundleIdentifier,
profileFromApple,
distCert
{
certId: developerPortalIdentifier ?? undefined,
certP12: certificateP12,
certPassword: certificatePassword,
distCertSerialNumber: serialNumber,
teamId: authCtx.appleId,
}
);

const bundleIdTag = `(${app.bundleIdentifier})`;
const slugTag = `@${app.accountName}/${app.projectName}`;
const slugTag = `@${app.account.name}/${app.projectName}`;
const projectTag = `${chalk.bold(slugTag)} ${chalk.dim(bundleIdTag)}`;

const spinner = ora(`Updating Expo profile for ${projectTag}`).start();
try {
// Update profile on EAS servers
await ctx.ios.updateProvisioningProfileAsync(app, updatedProfile);
const configuredProvisioningProfile = await ctx.newIos.updateProvisioningProfileAsync(
this.originalProvisioningProfile.id,
{
appleProvisioningProfile: updatedProfile.provisioningProfile,
developerPortalIdentifier: updatedProfile.provisioningProfileId,
}
);
spinner.succeed(`Updated Expo profile for ${projectTag}`);
return configuredProvisioningProfile;
} catch (error) {
spinner.fail();
throw error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
import assert from 'assert';

import Log from '../../../log';
import { Action, CredentialsManager } from '../../CredentialsManager';
import { Account } from '../../../user/Account';
import { Context } from '../../context';
import { IosDistCredentials } from '../credentials';
import { displayIosUserCredentials } from '../utils/printCredentials';
import { AppleDistributionCertificateMutationResult } from '../api/graphql/mutations/AppleDistributionCertificateMutation';
import { provideOrGenerateDistributionCertificateAsync } from './DistributionCertificateUtils';

export class CreateDistributionCertificateStandaloneManager implements Action {
constructor(private accountName: string) {}

public async runAsync(manager: CredentialsManager, ctx: Context): Promise<void> {
const action = new CreateDistributionCertificate(this.accountName);
await manager.runActionAsync(action);

Log.newLine();
displayIosUserCredentials(action.distCredentials);
Log.newLine();
}
}

export class CreateDistributionCertificate implements Action {
private _distCredentials?: IosDistCredentials;

constructor(private accountName: string) {}

public get distCredentials(): IosDistCredentials {
assert(this._distCredentials, 'distCredentials can be accessed only after runAsync');
return this._distCredentials;
}
export class CreateDistributionCertificate {
constructor(private account: Account) {}

public async runAsync(manager: CredentialsManager, ctx: Context): Promise<void> {
const distCert = await provideOrGenerateDistributionCertificateAsync(ctx, this.accountName);
this._distCredentials = await ctx.ios.createDistributionCertificateAsync(
this.accountName,
distCert
);
public async runAsync(ctx: Context): Promise<AppleDistributionCertificateMutationResult> {
const distCert = await provideOrGenerateDistributionCertificateAsync(ctx, this.account.name);
const result = await ctx.newIos.createDistributionCertificateAsync(this.account, distCert);
Log.succeed('Created distribution certificate');
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import assert from 'assert';
import nullthrows from 'nullthrows';

import { AppleDistributionCertificateFragment } from '../../../../graphql/generated';
import Log from '../../../../log';
import { Context } from '../../../context';
import { askForUserProvidedAsync } from '../../../utils/promptForCredentials';
import { AppLookupParams } from '../../api/GraphqlClient';
import { AppleProvisioningProfileMutationResult } from '../../api/graphql/mutations/AppleProvisioningProfileMutation';
import { ProvisioningProfile } from '../../appstore/Credentials.types';
import { AuthCtx } from '../../appstore/authenticate';
import { provisioningProfileSchema } from '../../credentials';
import { MissingCredentialsNonInteractiveError } from '../../errors';
import { generateProvisioningProfileAsync } from '../ProvisioningProfileUtils';
import { AppleDistributionCertificateFragment } from '../../../graphql/generated';
import Log from '../../../log';
import { Context } from '../../context';
import { askForUserProvidedAsync } from '../../utils/promptForCredentials';
import { AppLookupParams } from '../api/GraphqlClient';
import { AppleProvisioningProfileMutationResult } from '../api/graphql/mutations/AppleProvisioningProfileMutation';
import { ProvisioningProfile } from '../appstore/Credentials.types';
import { AuthCtx } from '../appstore/authenticate';
import { provisioningProfileSchema } from '../credentials';
import { MissingCredentialsNonInteractiveError } from '../errors';
import { resolveAppleTeamIfAuthenticatedAsync } from './AppleTeamUtils';
import { generateProvisioningProfileAsync } from './ProvisioningProfileUtils';

export class CreateProvisioningProfile {
constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppleDevice, AppleDeviceFragment } from '../../../../graphql/generated';
import { APPLE_DEVICE_CLASS_LABELS } from '../../../../graphql/types/credentials/AppleDevice';
import { promptAsync } from '../../.././../prompts';
import { AppleDevice, AppleDeviceFragment } from '../../../graphql/generated';
import { APPLE_DEVICE_CLASS_LABELS } from '../../../graphql/types/credentials/AppleDevice';
import { promptAsync } from '../.././../prompts';

export async function chooseDevices(
allDevices: AppleDeviceFragment[],
Expand Down
Loading

0 comments on commit 1a7edbe

Please sign in to comment.