다음을 통해 공유


JavaScript를 사용하여 Azure Key Vault에서 비밀 사용 및 사용 안 함

적절한 프로그래매틱 인증 자격 증명을 사용하여 SecretClient를 만든 다음, 클라이언트를 사용하여 Azure Key Vault에서 비밀을 사용하거나 사용하지 않도록 설정합니다.

비밀 사용

Azure Key Vault에서 비밀을 사용하도록 설정하려면 SecretClient 클래스의 updateSecretProperties 메서드를 사용합니다.

const name = 'mySecret';
const version= 'd9f2f96f120d4537ba7d82fecd913043'

const properties = await client.updateSecretProperties(
    secretName,
    version,
    { enabled: true }
);

// get secret value
const { value } = await client.getSecret(secretName, version);

이 메서드는 SecretProperties 개체를 반환합니다.

새 비밀 사용 안 함

비밀을 만들 때 사용하지 않도록 설정하려면 setSecret 메서드를 사용에 대한 옵션이 false로 설정된 상태에서 사용합니다.

const mySecretName = 'mySecret';
const mySecretValue = 'mySecretValue';

// Success
const { name, value, properties } = await client.setSecret(
    mySecretName, 
    mySecretValue, 
    { enabled: false }
);

// Can't read value of disabled secret
try{
    const secret = await client.getSecret(
        mySecretName, 
        properties.version
    );
} catch(err){
    // `Operation get is not allowed on a disabled secret.`
    console.log(err.message);
}

기존 비밀 사용 안 함

Azure Key Vault에서 기존 비밀을 사용하지 않도록 설정하려면 SecretClient 클래스의 updateSecretProperties 메서드를 사용합니다.

const name = 'mySecret';
const version= 'd9f2f96f120d4537ba7d82fecd913043';

// Success
const properties = await client.updateSecretProperties(
    secretName,
    version,
    { enabled: false }
);

// Can't read value of disabled secret
try{
    const { value } = await client.getSecret(secretName, version);
} catch(err){
    // `Operation get is not allowed on a disabled secret.`
    console.log(err.message);
}

이 메서드는 SecretProperties 개체를 반환합니다.

다음 단계