要求时打印苛刻的天蓝色密钥库secret.name

问题描述

我检查了所有相关问题,但没有找到合适的答案。

我成功设置了一个密钥库密钥,并且可以使用以下代码使用python毫无问题地访问并将其解析到我的ArcGIS在线服务中;

from arcgis.gis import GIS
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient

credential = DefaultAzureCredential()
secret_client = SecretClient(vault_url="vaulturl",credential=credential)
secret = secret_client.get_secret("papa-mama-Secret")

gis = GIS("urlGIS","AGOLaccountname",secret.value)

问题是当我打印secret.value时,会显示密钥。我不希望出于安全原因而发生这种情况。是否有地方确保可以将其传递到服务中,但是在打印时,密钥以特殊字符“ *****”或“ ####”的形式出现?

解决方法

似乎您不能仅为secret.value更改打印方法。因此,禁用print方法会更好。

您可以使用blockPrint()来禁用print

def blockPrint():
    sys.stdout = open(os.devnull,'w')

enter image description here

,

这是一个代码示例,用于打印出您的秘密值。

## CALL TO KEY VAULT TO GET SECRET
secret = client.get_secret("test").value

## OUTPUT SECRET VALUE TO CONSOLE
print(secret)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...