Skip to content

Commit

Permalink
update logs and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Mar 29, 2024
1 parent 57e7553 commit 4d4f1c8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ jobs:
env:
ETHEREUM_URL: ${{ secrets.ETHEREUM_URL }}
AZLE_USE_DOCKERFILE: ${{ matrix.azle_source == 'repo' }}
AZLE_PLAINTEXT_IDENTITY: true
strategy:
fail-fast: false # We want to see which example tests succeed and which ones fail, we don't want one example test to cancel the rest
matrix:
Expand Down
61 changes: 41 additions & 20 deletions dfx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,34 @@ type StorageMode = 'keyring' | 'password-protected' | 'plaintext';

export function generateIdentity(
name: string,
storageMode?: StorageMode
storageModeCool?: StorageMode
): Buffer {
console.info();
console.info(`Generating identity ${name}`);
const storageMode = determineStorageMode(storageModeCool);
if (storageMode === undefined) {
console.info(
`Generating identity "${name}". You may have to create a password for ${name}.`
);
return execSync(`dfx identity new ${name}`);
console.info(`You may be prompted to create a password for ${name}`);
console.info();
return execSync(`dfx identity new ${name}`, {
stdio: ['inherit', 'pipe', 'inherit']
});
}
if (storageMode === 'password-protected') {
console.info(
`Generating identity "${name}". You will have to create a password for ${name}.`
);
console.info(`You will be prompted to create a password for ${name}`);
console.info();
}
return execSync(`dfx identity new ${name} --storage-mode ${storageMode}`);
return execSync(`dfx identity new ${name} --storage-mode ${storageMode}`, {
stdio: ['inherit', 'pipe', 'inherit'] // TODO add todo here and aboe
});
}

function determineStorageMode(
storageMode?: StorageMode
): StorageMode | undefined {
if (process.env.AZLE_PLAINTEXT_IDENTITY === 'true') {
return 'plaintext';
}
return storageMode;
}

export function useIdentity(name: string) {
Expand Down Expand Up @@ -115,9 +129,10 @@ export async function getIdentityFromPemFile(
}

export function getPemKey(identityName: string = getIdentityName()): string {
console.info(
`Getting Pem Key for ${identityName}. The password for ${identityName} may be required`
);
console.info();
console.info(`Exporting PEM key for ${identityName}`);
console.info(`You may be prompted for ${identityName}'s password`);
console.info();
const cmd = `dfx identity export ${identityName}`;
const result = execSync(cmd, {
stdio: ['inherit', 'pipe', 'inherit'] // TODO I would prefer it to pipe the stderr but it will fail immediately if you do that
Expand All @@ -132,22 +147,28 @@ export function getIdentity(identityName?: string): Secp256k1KeyIdentity {
}

export function getPrincipal(identityName: string = getIdentityName()): string {
console.info(
`Getting Principal for ${identityName}. The password for ${identityName} may be required`
);
console.info();
console.info(`Getting principal for ${identityName}`);
console.info(`You may be prompted for ${identityName}'s password`);
console.info();
const cmd = `dfx identity get-principal --identity ${identityName}`;
return execSync(cmd, {
stdio: ['inherit', 'pipe', 'pipe']
stdio: ['inherit', 'pipe', 'inherit'] // TODO add todo
})
.toString()
.trim();
}

export function addController(canisterName: string, principal: string) {
export function addController(
canisterName: string,
identityName: string,
principal: string
) {
const currentIdentity = getIdentityName();
console.info(
`Adding controller. You may need to enter the password for ${currentIdentity} at this point.`
);
console.info();
console.info(`Adding ${identityName} as a controller for ${canisterName}`);
console.info(`You may be prompted for ${currentIdentity}'s password`);
console.info();
const cmd = `dfx canister update-settings ${canisterName} --add-controller ${principal}`;
return execSync(cmd, { stdio: ['inherit', 'pipe', 'inherit'] }); // TODO I would prefer it to pipe the stderr but it will fail immediately if you do that
}
4 changes: 2 additions & 2 deletions src/compiler/file_uploader/uploader_identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
identityExists
} from '../../../dfx';

export const AZLE_UPLOADER_IDENTITY_NAME = '__azle__fileUploaderIdentity';
export const AZLE_UPLOADER_IDENTITY_NAME = '_azle_file_uploader_identity';

export function generateUploaderIdentity(canisterName: string): string {
if (!identityExists(AZLE_UPLOADER_IDENTITY_NAME)) {
Expand All @@ -14,7 +14,7 @@ export function generateUploaderIdentity(canisterName: string): string {

const principal = getPrincipal(AZLE_UPLOADER_IDENTITY_NAME);

addController(canisterName, principal);
addController(canisterName, AZLE_UPLOADER_IDENTITY_NAME, principal);

return AZLE_UPLOADER_IDENTITY_NAME;
}

0 comments on commit 4d4f1c8

Please sign in to comment.