| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | PushImageOptions.cpp |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | This file contains the implementation of the WinRT wrapper for the WSLC SDK PushImageOptions class. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #include "precomp.h" |
| 16 | #include "PushImageOptions.h" |
| 17 | #include "Microsoft.WSL.Containers.PushImageOptions.g.cpp" |
| 18 | |
| 19 | namespace winrt::Microsoft::WSL::Containers::implementation { |
| 20 | |
| 21 | PushImageOptions::PushImageOptions(hstring const& image, hstring const& registryAuth) : |
| 22 | m_image(winrt::to_string(image)), m_registryAuth(winrt::to_string(registryAuth)) |
| 23 | { |
| 24 | if (image.empty()) |
| 25 | { |
| 26 | throw hresult_invalid_argument(L"Image cannot be empty"); |
| 27 | } |
| 28 | |
| 29 | if (registryAuth.empty()) |
| 30 | { |
| 31 | throw hresult_invalid_argument(L"Registry auth cannot be empty"); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | hstring PushImageOptions::Image() |
| 36 | { |
| 37 | return winrt::to_hstring(m_image); |
| 38 | } |
| 39 | |
| 40 | void PushImageOptions::Image(hstring const& value) |
| 41 | { |
| 42 | if (m_pushImageOptions) |
| 43 | { |
| 44 | throw hresult_illegal_state_change(L"Cannot change value after options have been applied"); |
| 45 | } |
| 46 | |
| 47 | if (value.empty()) |
| 48 | { |
| 49 | throw hresult_invalid_argument(L"Image cannot be empty"); |
| 50 | } |
| 51 | |
| 52 | m_image = winrt::to_string(value); |
| 53 | } |
| 54 | |
| 55 | hstring PushImageOptions::RegistryAuth() |
| 56 | { |
| 57 | return winrt::to_hstring(m_registryAuth); |
| 58 | } |
| 59 | |
| 60 | void PushImageOptions::RegistryAuth(hstring const& value) |
| 61 | { |
| 62 | if (m_pushImageOptions) |
| 63 | { |
| 64 | throw hresult_illegal_state_change(L"Cannot change value after options have been applied"); |
| 65 | } |
| 66 | |
| 67 | if (value.empty()) |
| 68 | { |
| 69 | throw hresult_invalid_argument(L"Registry auth cannot be empty"); |
| 70 | } |
| 71 | |
| 72 | m_registryAuth = winrt::to_string(value); |
| 73 | } |
| 74 | |
| 75 | WslcPushImageOptions PushImageOptions::ToStruct() |
| 76 | { |
| 77 | if (!m_pushImageOptions) |
| 78 | { |
| 79 | m_pushImageOptions = std::make_unique<WslcPushImageOptions>(); |
| 80 | m_pushImageOptions->image = m_image.c_str(); |
| 81 | m_pushImageOptions->registryAuth = m_registryAuth.c_str(); |
| 82 | m_pushImageOptions->progressCallback = nullptr; |
| 83 | m_pushImageOptions->progressCallbackContext = nullptr; |
| 84 | } |
| 85 | |
| 86 | return *m_pushImageOptions; |
| 87 | } |
| 88 | |
| 89 | } // namespace winrt::Microsoft::WSL::Containers::implementation |