import { Flags } from '@oclif/core'; import { readFile } from 'node:fs/promises'; import type Limrun from '@limrun/api'; import { savedGoogleAccessToken } from './google-auth'; import { GOOGLE_PLAY_OAUTH_SECRET_NAME, LimrunSigningSecretStore } from './limrun-signing-store'; export const playSessionFlags = { 'access-token-file': Flags.string({ description: 'File containing a Google OAuth access token. Overrides the saved Play login.', }), 'secret-name': Flags.string({ description: 'Limrun secret holding the Play login saved by lim android play auth.', default: GOOGLE_PLAY_OAUTH_SECRET_NAME, }), }; /** An access token for Play actions that run on this computer, from a file or the saved login. */ export async function playAccessToken( client: Limrun, flags: { 'access-token-file'?: string; 'secret-name'?: string }, ): Promise { const token = flags['access-token-file'] ? (await readFile(flags['access-token-file'], 'utf8')).trim() : await savedGoogleAccessToken(new LimrunSigningSecretStore(client), fetch, flags['secret-name']); if (!token) throw new Error('Run lim android play auth first, or provide --access-token-file.'); return token; }