Skip to content

Commit

Permalink
Merge pull request #1734 from flexn-io/fix/tizen-change-certificates
Browse files Browse the repository at this point in the history
Being able to change tizen certificate from default RNV to custom ones
  • Loading branch information
Marius456 authored Oct 1, 2024
2 parents 2dd9ad8 + 3e0802f commit 9f9c2a0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/core/src/enums/taskName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ export const RnvTaskName = {
telemetryStatus: 'telemetry status',
config: 'config',
patchReset: 'patch reset',
tizenCertificate: 'tizen certificate',
} as const;
2 changes: 1 addition & 1 deletion packages/sdk-tizen/src/deviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export const createDevelopTizenCertificate = (c: RnvContext) =>
)
.then(() =>
addDevelopTizenCertificate(c, {
profileName: DEFAULTS.certificateProfile,
profileName: getConfigProp('certificateProfile') || DEFAULTS.certificateProfile,
certPath: path.join(certDirPath, `${certFilename}.p12`),
certPassword,
})
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk-tizen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ export * from './constants';
import taskTargetLaunch from './tasks/taskTargetLaunch';
import taskTargetList from './tasks/taskTargetList';
import taskSdkConfigure from './tasks/taskSdkConfigure';
import taskChangeCertificate from './tasks/taskChangeCertificate';
import { GetContextType, createRnvModule } from '@rnv/core';

const RnvModule = createRnvModule({
tasks: [taskTargetLaunch, taskTargetList, taskSdkConfigure] as const,
tasks: [taskTargetLaunch, taskTargetList, taskSdkConfigure, taskChangeCertificate] as const,
name: '@rnv/sdk-tizen',
type: 'internal',
});
Expand Down
7 changes: 5 additions & 2 deletions packages/sdk-tizen/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ const DEFAULT_CERTIFICATE_NAME_WITH_EXTENSION = `${DEFAULT_CERTIFICATE_NAME}.p12

export const checkTizenStudioCert = async (): Promise<boolean> => {
try {
await execCLI(CLI_TIZEN, `security-profiles list -n ${DEFAULTS.certificateProfile}`);
await execCLI(
CLI_TIZEN,
`security-profiles list -n ${getConfigProp('certificateProfile') || DEFAULTS.certificateProfile}`
);
return true;
} catch (e) {
return false;
Expand Down Expand Up @@ -74,7 +77,7 @@ export const configureTizenGlobal = () =>
const certPassword = '1234';

addDevelopTizenCertificate(c, {
profileName: DEFAULTS.certificateProfile,
profileName: getConfigProp('certificateProfile') || DEFAULTS.certificateProfile,
certPath: path.join(certDirPath, `${certFilename}.p12`),
certPassword,
})
Expand Down
51 changes: 51 additions & 0 deletions packages/sdk-tizen/src/tasks/taskChangeCertificate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createTask, inquirerPrompt, logInfo, RnvTaskName } from '@rnv/core';
import fs from 'fs';
import { checkTizenStudioCert } from '../runner';

export default createTask({
description: 'Change tizen certificate',
dependsOn: [RnvTaskName.appConfigure],
fn: async ({ ctx }) => {
for (const config of ctx.paths.appConfig.configs) {
if (config.includes('base')) {
const configFile = await JSON.parse(fs.readFileSync(config, 'utf-8'));
const { confirm } = await inquirerPrompt({
message:
'Tizen - used certificate change. NOTE: you must create the certificate first through the tizens certificate-manager. Continue?',
type: 'confirm',
name: 'confirm',
});
if (!confirm) {
return;
}
const { platform } = await inquirerPrompt({
message: 'For which platform do you want to set the new certificate?',
type: 'list',
name: 'platform',
choices: ['tizen', 'tizenwatch', 'tizenmobile'],
});
const { name } = await inquirerPrompt({
message: 'Enter the new certificate name:',
type: 'input',
name: 'name',
});
if (name === '') {
logInfo('No certificate name entered.');
return;
}

configFile.platforms[`${platform}`].certificateProfile = name;

fs.writeFileSync(config, JSON.stringify(configFile, null, 2));

await checkTizenStudioCert();

// if user inputs a certificate name that doesn't exist, it still sets the certificate name.
// This isn't a problem if running rnv run -p tizen, because it will create the certificate, but that isn't ideal, so should be fixed.
return;
}
}
},
task: RnvTaskName.tizenCertificate,
isGlobalScope: true,
});

0 comments on commit 9f9c2a0

Please sign in to comment.