copyServiceAccountKey method
Copy service account key to server
Implementation
Future<void> copyServiceAccountKey() async {
if (!config.createServer) return;
if (config.serviceAccountKeyPath == null) {
warn('No service account key path provided');
return;
}
final File sourceFile = File(config.serviceAccountKeyPath!);
if (!sourceFile.existsSync()) {
error('Service account key not found: ${config.serviceAccountKeyPath}');
return;
}
info('Copying service account key...');
final String destPath = p.join(serverPath, 'service-account.json');
final String sourcePath = p.normalize(sourceFile.path);
final String normalizedDestPath = p.normalize(destPath);
if (sourcePath == normalizedDestPath) {
info('Service account key already in place: $destPath');
return;
}
final File destFile = File(destPath);
if (destFile.existsSync()) {
await _rotateServiceAccountBackups(destFile);
}
await sourceFile.copy(destPath);
// Add to gitignore
final File gitignore = File(p.join(serverPath, '.gitignore'));
if (gitignore.existsSync()) {
String content = await gitignore.readAsString();
if (!content.contains('*.json')) {
content += '\n# Service account keys\n*.json\n';
await gitignore.writeAsString(content);
}
}
success('Service account key copied');
}