-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fcmv1] Manage FCM V1 Google Service Account Key in CLI
# Why NOTE: DO NOT LAND THIS UNTIL GRAPHQL CHANGES LAND IN WWW We're adding support for FCM V1 credentials, as Google is shutting down the FCM Legacy API for sending Android notifications in June. # How Add new prompts and refactor existing prompts to match this schematic: # Test Plan Verified all functionality e2e:
- Loading branch information
1 parent
0b71812
commit 99510f4
Showing
19 changed files
with
356 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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
33 changes: 33 additions & 0 deletions
33
packages/eas-cli/src/credentials/android/actions/AssignGoogleServiceAccountKeyForFcmV1.ts
This file contains 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,33 @@ | ||
import { | ||
CommonAndroidAppCredentialsFragment, | ||
GoogleServiceAccountKeyFragment, | ||
} from '../../../graphql/generated'; | ||
import Log from '../../../log'; | ||
import { CredentialsContext } from '../../context'; | ||
import { AppLookupParams } from '../api/GraphqlClient'; | ||
|
||
export class AssignGoogleServiceAccountKeyForFcmV1 { | ||
constructor(private app: AppLookupParams) {} | ||
|
||
public async runAsync( | ||
ctx: CredentialsContext, | ||
googleServiceAccountKey: GoogleServiceAccountKeyFragment | ||
): Promise<CommonAndroidAppCredentialsFragment> { | ||
const appCredentials = | ||
await ctx.android.createOrGetExistingAndroidAppCredentialsWithBuildCredentialsAsync( | ||
ctx.graphqlClient, | ||
this.app | ||
); | ||
const updatedAppCredentials = await ctx.android.updateAndroidAppCredentialsAsync( | ||
ctx.graphqlClient, | ||
appCredentials, | ||
{ | ||
googleServiceAccountKeyForFcmV1Id: googleServiceAccountKey.id, | ||
} | ||
); | ||
Log.succeed( | ||
`Google Service Account Key assigned to ${this.app.androidApplicationIdentifier} for FCM V1` | ||
); | ||
return updatedAppCredentials; | ||
} | ||
} |
This file contains 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 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
87 changes: 87 additions & 0 deletions
87
packages/eas-cli/src/credentials/android/actions/SetUpGoogleServiceAccountKeyForFcmV1.ts
This file contains 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,87 @@ | ||
import nullthrows from 'nullthrows'; | ||
|
||
import { AssignGoogleServiceAccountKeyForFcmV1 } from './AssignGoogleServiceAccountKeyForFcmV1'; | ||
import { CreateGoogleServiceAccountKey } from './CreateGoogleServiceAccountKey'; | ||
import { UseExistingGoogleServiceAccountKey } from './UseExistingGoogleServiceAccountKey'; | ||
import { | ||
CommonAndroidAppCredentialsFragment, | ||
GoogleServiceAccountKeyFragment, | ||
} from '../../../graphql/generated'; | ||
import Log from '../../../log'; | ||
import { promptAsync } from '../../../prompts'; | ||
import { CredentialsContext } from '../../context'; | ||
import { MissingCredentialsNonInteractiveError } from '../../errors'; | ||
import { AppLookupParams } from '../api/GraphqlClient'; | ||
|
||
export class SetUpGoogleServiceAccountKeyForFcmV1 { | ||
constructor(private app: AppLookupParams) {} | ||
|
||
public async runAsync(ctx: CredentialsContext): Promise<CommonAndroidAppCredentialsFragment> { | ||
const isKeySetup = await this.isGoogleServiceAccountKeySetupAsync(ctx); | ||
if (isKeySetup) { | ||
Log.succeed('Google Service Account Key for FCM V1 already set up.'); | ||
return nullthrows( | ||
await ctx.android.getAndroidAppCredentialsWithCommonFieldsAsync( | ||
ctx.graphqlClient, | ||
this.app | ||
), | ||
'androidAppCredentials cannot be null if google service account key is already set up' | ||
); | ||
} | ||
if (ctx.nonInteractive) { | ||
throw new MissingCredentialsNonInteractiveError( | ||
'Google Service Account Keys cannot be set up in --non-interactive mode.' | ||
); | ||
} | ||
|
||
const keysForAccount = await ctx.android.getGoogleServiceAccountKeysForAccountAsync( | ||
ctx.graphqlClient, | ||
this.app.account | ||
); | ||
let googleServiceAccountKey = null; | ||
if (keysForAccount.length === 0) { | ||
googleServiceAccountKey = await new CreateGoogleServiceAccountKey(this.app.account).runAsync( | ||
ctx | ||
); | ||
} else { | ||
googleServiceAccountKey = await this.createOrUseExistingKeyAsync(ctx); | ||
} | ||
return await new AssignGoogleServiceAccountKeyForFcmV1(this.app).runAsync( | ||
ctx, | ||
googleServiceAccountKey | ||
); | ||
} | ||
|
||
private async isGoogleServiceAccountKeySetupAsync(ctx: CredentialsContext): Promise<boolean> { | ||
const appCredentials = await ctx.android.getAndroidAppCredentialsWithCommonFieldsAsync( | ||
ctx.graphqlClient, | ||
this.app | ||
); | ||
return !!appCredentials?.googleServiceAccountKeyForFcmV1; | ||
} | ||
|
||
private async createOrUseExistingKeyAsync( | ||
ctx: CredentialsContext | ||
): Promise<GoogleServiceAccountKeyFragment> { | ||
const { action } = await promptAsync({ | ||
type: 'select', | ||
name: 'action', | ||
message: 'Select the Google Service Account Key to use for FCM V1:', | ||
choices: [ | ||
{ | ||
title: '[Choose an existing key]', | ||
value: 'CHOOSE_EXISTING', | ||
}, | ||
{ title: '[Upload a new service account key]', value: 'GENERATE' }, | ||
], | ||
}); | ||
|
||
if (action === 'GENERATE') { | ||
return await new CreateGoogleServiceAccountKey(this.app.account).runAsync(ctx); | ||
} | ||
return ( | ||
(await new UseExistingGoogleServiceAccountKey(this.app.account).runAsync(ctx)) ?? | ||
(await this.createOrUseExistingKeyAsync(ctx)) | ||
); | ||
} | ||
} |
This file contains 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 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 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 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 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 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
Oops, something went wrong.