Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create connect function #1252

Closed
siadatism opened this issue Oct 11, 2023 · 10 comments
Closed

Create connect function #1252

siadatism opened this issue Oct 11, 2023 · 10 comments
Labels
question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@siadatism
Copy link

I used Autorest to create a Powershell CLI for my Rest API using its swagger. I want to have a connect function to get the server address (host) and save it for later commands like an open session. It's nice to check the server availability in the connect function as well.

Is there anything like this in the generated CLI? If not, how can I add this functionality to it? Thanks.

@dolauli dolauli added the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label Oct 12, 2023
@soroshsabz
Copy link

ITNOA

@dolauli I have the same problem, Did you can provide solution for this?

@soroshsabz
Copy link

I ask this question on SO

https://stackoverflow.com/q/77297750/1539100

@dolauli
Copy link
Contributor

dolauli commented Oct 16, 2023

@siadatism You do not need to do that, since we have created a shared httpclient in a file like https://github.com/Azure/azure-powershell/blob/main/src/Databricks/generated/Module.cs. Besides I do not think you will need to check server availability, since it is rare case and the check will take some additional cost, even if the server/service is not avail and we do not have the check, the request will also fail and an error will be reported to users.

@soroshsabz
Copy link

@dolauli So, how to specify URL when I call cmdlet?

For example I have a CLI for some services that host on appliance, so when I want to call CLI, I want to specify which appliance, must be response to me.

@dolauli
Copy link
Contributor

dolauli commented Oct 20, 2023

You may use https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-parameterized-host in your swagger, by doing that, we could generate host for you to input for each cmdlet.
Or, you may set a placeholder in swagger. And then add a handler in our pipeline through customization to replace the host with the real host (set in env variable or a file). Here is an example how to add a handler.

@dolauli dolauli closed this as completed Oct 20, 2023
@soroshsabz
Copy link

related to BSVN/IpTables.Api#22

@soroshsabz
Copy link

You may use https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-parameterized-host in your swagger, by doing that, we could generate host for you to input for each cmdlet. Or, you may set a placeholder in swagger. And then add a handler in our pipeline through customization to replace the host with the real host (set in env variable or a file). Here is an example how to add a handler.

@dolauli So How Azure implement Connect-AzAccount?

thanks a lot for helping me :)

@soroshsabz
Copy link

@dolauli Did you can get me more advice to implementing clean code Connect-AzAccount like cmdlet?

thanks

@soroshsabz
Copy link

I ask some question about this

Azure/azure-powershell#23233

@soroshsabz
Copy link

We can done it, thanks to @dolauli .

All developers can see our example in: BSVN/IpTables.Api#56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

3 participants