天蓝色以编程方式设置环境变量以禁用天蓝色功能 [英] azure set environment variable programmatically to disable an azure function

查看:66
本文介绍了天蓝色以编程方式设置环境变量以禁用天蓝色功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure API和一个Azure函数.当某些逻辑传递到API中时,我希望它禁用Azure功能.

这篇文章建议使用禁用该功能环境变量.这行得通,但就我而言,我无法通过手动干预禁用它,我需要使用api来设置此变量.

这可能吗?

解决方案

您的选项受到一些限制,并且需要修改一些启用或禁用功能的文件.

幸运的是,您可以使用 Kudu VFS API轻松地以编程方式实现此目的.

您可以使用两个文件来禁用或启用功能,从而为您提供支持不同模式的不同方法:

host.json

位于功能脚本文件根目录的 host.json 文件公开了 functions 属性,该属性是一个字符串数组,设置后将定义一个功能白名单.设置此属性后,运行时将仅启用和加载此数组中包含的函数.您可以在此处找到有关该设置的更多信息./p>

function.json

每个函数都有一个 function.json 文件,其中包含函数元数据.此元数据支持 disabled 属性,该属性设置为true时将禁用该功能.这使您能够分别管理每个功能,默认情况下会在应用程序中加载所有功能,但最终却不得不管理更多文件.

您可以在此处.

I have an azure API and an Azure function. When certain logic is passed into the API, I want it to disable the Azure function.

This post suggest disabling the function using environment variables. This works, but in my case, I cant disable this via manual intervention, I need the api to set this variable.

Is this possible ?

解决方案

Your options are somewhat limited and will entail modifying some files that will enable or disable your functions.

Fortunately, you can easily to this programmatically using the Kudu VFS API.

There are two files you can work with to disable or enable a function, offering you different approaches to support different patterns:

host.json

The host.json file, located on the root of your function script files, exposes a functions property, which is a string array that, when set, defines a functions white list. When this property is set, only the functions contained in this array will be enabled and loaded by the runtime. You can find more information about that setting here.

function.json

Each function has a function.json file that contains function metadata. This metadata supports a disabled property that, when set to true, disables that function. This gives you the ability to manage each function individually, which defaulting to loading all functions in the app, but you do end up having to manage more files.

You can find more information about this setting here.

这篇关于天蓝色以编程方式设置环境变量以禁用天蓝色功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆