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

Accessing Government Cloud (High) #115

Closed
Bakan0 opened this issue Mar 8, 2024 · 15 comments
Closed

Accessing Government Cloud (High) #115

Bakan0 opened this issue Mar 8, 2024 · 15 comments

Comments

@Bakan0
Copy link

Bakan0 commented Mar 8, 2024

Awesome tool! I'm hoping that it can connect to the government cloud. Is there a command or switch/option that exists to set that?
After loggin in, I receive the following error message:
Error: Response status code does not indicate success: 404 (Not Found).

Copy link

welcome bot commented Mar 8, 2024

Thanks for opening your first issue! Reports like these help improve the project!

@mivano
Copy link
Owner

mivano commented Mar 12, 2024

Unfortunately, it can not. It connects to the public cloud version only. I do not have a Government Cloud account, so I m unsure if the same calls can be made. If so, it might be an option to change the base url to try out?

@Bakan0
Copy link
Author

Bakan0 commented Mar 12, 2024 via email

@mivano
Copy link
Owner

mivano commented Mar 12, 2024

At the moment, there is no CLI switch for it. So if you can run the source, you can change the url here: https://github.com/mivano/azure-cost-cli/blob/main/src/Program.cs#L24
If that works, I can introduce an override.

@Bakan0
Copy link
Author

Bakan0 commented Mar 12, 2024

That's exciting! According to their documentation here: Compare Azure Government and global Azure
, updating that to management.usgovcloudapi.net should work. I'm going to try it out today and report back. Thank you!

@mivano
Copy link
Owner

mivano commented Mar 12, 2024

I m assuming it is similar for the other clouds (like German), but I m unable to verify, so do let me know and I will see how we can add an override in.

@Bakan0
Copy link
Author

Bakan0 commented Mar 12, 2024

So I forked it and made the change, but as I am not a developer, I cannot seem to figure out how to compile it into a binary :/

I am running ubuntu 22.04.4 LTS and have dotnet and cmake installed, but I'm not sure how to create a usable executable from the code/Program.cs file. I'm doing my best to check around the internet, but if you could provide me with some guidance, that would surely be much appreciated.

Thanks in advance :)

@mivano
Copy link
Owner

mivano commented Mar 13, 2024

From the src folder, you should be able to execute dotnet run, optionally passing in --framework net6.0. This will build and run the application. The binary can be found in the bin/debug/netx folder (azure-cost).

@Bakan0
Copy link
Author

Bakan0 commented Mar 13, 2024

Is this meaningful output? I did run az login --scope management.usgovcloudapi.net/.default with a successful login once also updating the url here: https://github.com/mivano/azure-cost-cli/blob/main/src/CostApi/AzureCostApiRetriever.cs#L60

user@jammy-gcch:~/git/src$ dotnet run --framework net6.0
/home/user/.nuget/packages/microsoft.build.tasks.git/8.0.0/build/Microsoft.Build.Tasks.Git.targets(25,5): warning : Repository '/home/user/git' has no remote. [/home/user/git/src/azure-cost-cli.csproj::TargetFramework=net6.0]
/home/user/.nuget/packages/microsoft.sourcelink.common/8.0.0/build/Microsoft.SourceLink.Common.targets(53,5): warning : Source control information is not available - the generated source link is empty. [/home/user/git/src/azure-cost-cli.csproj::TargetFramework=net6.0]
Unhandled exception. System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at AzureCostCli.CostApi.AzureCostApiRetriever.ExecuteCallToCostApi(Boolean includeDebugOutput, Object payload, Uri uri) in /home/user/git/src/CostApi/AzureCostApiRetriever.cs:line 150
   at AzureCostCli.CostApi.AzureCostApiRetriever.RetrieveCosts(Boolean includeDebugOutput, Scope scope, String[] filter, MetricType metric, TimeframeType timeFrame, DateOnly from, DateOnly to) in /home/user/git/src/CostApi/AzureCostApiRetriever.cs:line 200
   at AzureCostCli.Commands.AccumulatedCost.AccumulatedCostCommand.<>c__DisplayClass4_0.<<ExecuteAsync>b__0>d.MoveNext() in /home/user/git/src/Commands/AccumulatedCost/AccumulatedCostCommand.cs:line 107
--- End of stack trace from previous location ---
   at AzureCostCli.OutputFormatters.SpectreConsole.StatusExt.<>c__DisplayClass16_0.<<StartAsync>b__0>d.MoveNext() in /home/user/git/src/OutputFormatters/SpectreConsole/StatusExt.cs:line 99
--- End of stack trace from previous location ---
   at AzureCostCli.OutputFormatters.SpectreConsole.StatusExt.<>c__DisplayClass17_0`1.<<StartAsync>b__0>d.MoveNext() in /home/user/git/src/OutputFormatters/SpectreConsole/StatusExt.cs:line 141
--- End of stack trace from previous location ---
   at Spectre.Console.Progress.<>c__DisplayClass32_0`1.<<StartAsync>b__0>d.MoveNext() in /_/src/Spectre.Console/Live/Progress/Progress.cs:line 138
--- End of stack trace from previous location ---
   at Spectre.Console.Internal.DefaultExclusivityMode.RunAsync[T](Func`1 func) in /_/src/Spectre.Console/Internal/DefaultExclusivityMode.cs:line 40
   at Spectre.Console.Progress.StartAsync[T](Func`2 action) in /_/src/Spectre.Console/Live/Progress/Progress.cs:line 121
   at AzureCostCli.OutputFormatters.SpectreConsole.StatusExt.StartAsync[T](String status, Func`2 func) in /home/user/git/src/OutputFormatters/SpectreConsole/StatusExt.cs:line 138
   at AzureCostCli.OutputFormatters.SpectreConsole.StatusExt.StartAsync(String status, Func`2 action) in /home/user/git/src/OutputFormatters/SpectreConsole/StatusExt.cs:line 97
   at AzureCostCli.Commands.AccumulatedCost.AccumulatedCostCommand.ExecuteAsync(CommandContext context, AccumulatedCostSettings settings) in /home/user/git/src/Commands/AccumulatedCost/AccumulatedCostCommand.cs:line 88
   at Spectre.Console.Cli.CommandExecutor.Execute(IConfiguration configuration, IEnumerable`1 args) in /_/src/Spectre.Console.Cli/Internal/CommandExecutor.cs:line 83
   at Spectre.Console.Cli.CommandApp.RunAsync(IEnumerable`1 args) in /_/src/Spectre.Console.Cli/CommandApp.cs:line 84
   at Program.<Main>$(String[] args) in /home/user/git/src/Program.cs:line 115

Is there something else you wold like me to try?

@mivano
Copy link
Owner

mivano commented Mar 14, 2024

What did you change the url to? So the one that is used by the RetrieveCosts call? A 404 indicates that it cannot find it.

@Bakan0
Copy link
Author

Bakan0 commented Mar 14, 2024

management.usgovcloudapi.net

I suppose we are at a dead end then. Thank you for the assistance ☺️

@mivano
Copy link
Owner

mivano commented Mar 14, 2024

According to this page (https://learn.microsoft.com/en-gb/azure/azure-government/compare-azure-government-global-azure#guidance-for-developers) it should be that URL.

What you can do: when in the Azure portal (the government one), go the the Cost management page and inspect the network traffic and see where the calls to the Query endpoint go to.

image

@Bakan0
Copy link
Author

Bakan0 commented Mar 15, 2024

Hello again! Good news I believe! I had to supply the subscription id, since ours differs from our tenant id, but by running this command:
dotnet run --framework net6.0 costByTag --tag CostCenter --tag costcenter-tag-for-IT -s our-subscription-id

2024-03-14-234900

I think I just need to figure out the querying, and I may be actually able to pull some useful data!! Thank you for your assistance! I'm not sure if I should close this issue or not. I'm also not very sure how to share the changes made with you, but you can see them over at my fork, since that's what I'm using: https://github.com/Bakan0/azure-cost-cli/tree/main

@mivano
Copy link
Owner

mivano commented Mar 15, 2024

Ah that is good to hear. I see in the diff what you changed, so I have to see how I can make this configurable. Give me some time please as I m traveling at the moment.

@mivano
Copy link
Owner

mivano commented Mar 16, 2024

Version 0.38.0 should contain the ability to change the base urls via the config param. See the readme for the options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants