简体   繁体   English

Azure Batch客户端,如何测试有效性?

[英]Azure Batch client, how to test for validity?

I'm working on integrating with the Azure Batch API and construct a client object based on credentials I pass through. 我正在与Azure Batch API集成,并根据我通过的凭据构造一个客户端对象。 What I want to know is how can I test to see whether the connection is valid and the credentials are correct? 我想知道的是如何测试连接是否有效以及凭据是否正确? I can't see anything on the API to do this. 我在API上看不到任何东西可以做到这一点。 You can just create the BatchClient object and then call operations on it to list jobs, pools etc, all of which fail with a complex error if your initial credentials were wrong. 您可以只创建BatchClient对象,然后在其上调用操作以列出作业,池等,如果您的初始凭据错误,所有这些都将失败并显示一个复杂错误。 I want to be able to test for incorrect credentials before I attempt any other operations. 我希望能够在尝试任何其他操作之前测试不正确的凭据。 Does anyone know how to do this? 有谁知道如何做到这一点?

var client = BatchClient.Open(new BatchSharedKeyCredentials(
                                string.Format("https://{0}.{1}.batch.azure.com",
                                        _primaryBatchAccountName,
                                        _primaryRegion),
                                _primaryBatchAccountName,
                                _primaryBatchAccountKey));

This is the code to create the client object. 这是创建客户端对象的代码。 But it doesn't throw any error even if you pass it completely wrong values. 但是,即使您传递了完全错误的值,它也不会引发任何错误。 You only get the error when you try and do anything with it. 尝试执行任何操作时,只会得到该错误。

The BatchClient doesn't keep a persistent connection "open." BatchClient不会保持持久连接“打开”。 It just issues REST requests to the target endpoint whenever required (ie when you use a method). 它仅在需要时(即,使用方法时)向目标端点发出REST请求。

To the best of my knowledge, there is no way to determine if you have the "right" credentials values or endpoint data until you try to use the BatchClient to actually communicate with the server. 据我所知,在尝试使用BatchClient与服务器实际通信之前,无法确定您是否具有“正确的”凭据值或终结点数据。 This is because it's not really possible for the client to know what endpoints are valid, nor is it possible for it to know what a "valid" credential looks like, or if the credential you specified is correct (the server must verify that). 这是因为客户端实际上不可能知道哪些端点有效,也不可能知道“有效”证书的外观,或者您指定的证书是否正确(服务器必须验证)。

The best recommendation I can come up with is to just try to issue a simple API call (like a ListJobs or something) and ensure that it completes successfully. 我能提出的最佳建议是尝试发出一个简单的API调用(例如ListJobs之类)并确保它成功完成。 That should validate that your BatchClient is working. 那应该验证您的BatchClient是否正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM