Commit Graph

9 Commits

Author SHA1 Message Date
Anton Kolesnyk
2aae6be7a3
Encapsulate getenv(), and make it work on UWP (#3275)
It all started with UWP. The [docs](https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps?view=msvc-170) say: "`Environment variables are not available to UWP apps.`". And it truly won't work, I tried: linker error, the function is simply not present.

So, for a year or so, we were `ifdef`ing everything enivoronment-related: console logger, environment credential, managed identity credential.

And then just recently we wanted to enable our CI for UWP, including tests and samples. And it required to do more ifdefs (in vcpkg, we don't build samples or tests, so that problem did not exist).

It just became more messy. Especially in samples - you can see how we would disable warning with `#pragma warning(disable : 4996)` or defining `_CRT_SECURE_NO_WARNINGS` already, but now came UWP, so we would have to add comment that `getenv()` is not available and make the sample compilation to either fail with clear message, or throw an exception. Plus we would have to detect that we are being compiled on UWP, which also adds visual clutter for reader. You can see how such an irrelevant (for a sample) thing as `getenv` was consuming more and more lines of sample code and reader's attention.

But then! I read docs on more APIs for UWP. And I noticed that on .NET you can read environment variables. So I went and checked Win32 API docs for [GetEnvironmentVariable()](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getenvironmentvariable) - it says: "`Minimum supported client: ... UWP apps`".

**GetEnvironmentVariable() works on UWP!**
And so does `SetEnvironmentVariable()` (our tests use it, which means we can make all of them work and execute for UWP).

That's good news, but now it would probably be more code: it usually takes more lines to invoke WinAPI, it is no more an one-liner to call `getenv()/setenv()`. So, I encapsulated that into `Azure::Core::_internal::Environment::GetVariable()` and `SetVariable()`. You can see how much less ifdefs is in our code now. Not to mention it works on UWP!

Per team request, that API is SDK-internal. Samples use their own mini-helper project, `get-env-helper` that makes is so that `getenv()` works naturally on Linux and macOS, compiles without warnings and works on Win32, and compiles and works on UWP (using `GetEnvironmentStringsA()`)

If it was for me, I would just make `Azure::Core::Environment::GetVariable()` public and simplify even further, I think it would be beneficial for sample readers (you can see that extra `get-env-helper` stuff adds just a little more visual clutter, compared to nothing). But I can see reasons against that, why team did not want to do it.
2022-01-29 08:22:33 +00:00
George Arama
10a46b3132
fixup sample , add to build (#2808) 2021-09-01 18:04:20 -07:00
Wes Haggard
015c34a029
Update links from master to main (#2488)
* Update links from master to main

* Upate other references from master to main
2021-06-24 22:27:14 -07:00
Ahson Khan
479134595b
Consolidate the use of std::size_t and always use size_t instead, since it is a "primitive" type. (#2415)
* Consolidate the use of std::size_t and always use size_t instead, since
it is a type.

* Fix clang formatting.
2021-06-09 11:09:54 -07:00
Anton Kolesnyk
efe4772acb
Update upper/lower/other casing (#2267)
Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
2021-05-14 12:54:16 -07:00
Victor Vazquez
1f5bfb6984
Vcpkg sample (#2161)
* extra test

* sample

* typo

* Adding storage sample
2021-05-07 21:22:42 +00:00
Ahson Khan
8095d85e67
Simplify the public surface design of Response<T> for usability. (#1974)
* Simplify the design of Response<T> for usability.

* Revert changes to operation<T> to keep the changes single purpose.

* Update many of the response<T> call sites based on API changes.

* Update all remaining callsites and fix clang formatting.

* Update Response<T> documentation.

* Fix clang formatting.

* Remove status code from the Response<T> public surface area.

* Update the changelog.

* Fix up CL wording and remove commented-out change to operation<T>.

* Fixed test by actually calling a method.

* Fix up key vault test by not taking ownership of raw response.

* Fix call to get status code in test.

* Add new line at end of keyvualt live test file.

* Make a local copy within keyvault pipeline to avoid compilers re-ordering things.

* Make the fixes to the recent keyvault changes.

* Fix key vault pipeline to address ImportKey test failure
2021-04-01 00:50:04 +00:00
Rick Winter
50efbdb4c0
Add holder for registry handle to ensure cleanup of native resources. (#1711)
Add a holder for the registry key to ensure it is always cleaned up when it goes out of scope.
Exceptions should be caught as const.
2021-02-22 17:48:28 +00:00
Victor Vazquez
1aaf1f22df
Sample for fetchContent (#1392)
* Sample for fetchContent
2021-01-22 16:10:44 -08:00