VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/OCIProfile.cpp@ 73739

Last change on this file since 73739 was 73719, checked in by vboxsync, 7 years ago

Main/Cloud: fix copyright header and todo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/* $Id: OCIProfile.cpp 73719 2018-08-16 17:51:19Z vboxsync $ */
2/** @file
3 * ICloudProfile COM class implementation (OCI).
4 */
5
6/*
7 * Copyright (C) 2008-2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "OCIProfile.h"
19#include "OCIProvider.h"
20#include "CloudClientImpl.h"
21#include "AutoCaller.h"
22#define LOG_GROUP_MAIN_OVERRIDE LOG_GROUP_MAIN_CLOUDPROFILE
23#include "Logging.h"
24
25#include <iprt/cpp/utils.h>
26
27
28////////////////////////////////////////////////////////////////////////////////
29//
30// OCIProfile implementation
31//
32////////////////////////////////////////////////////////////////////////////////
33OCIProfile::OCIProfile()
34 : mVirtualBox(NULL), mParent(NULL)
35{
36}
37
38OCIProfile::~OCIProfile()
39{
40 LogRel(("OCIProfile::~OCIProfile()\n"));
41 unconst(mVirtualBox) = NULL;
42 unconst(mParent).setNull();
43}
44
45HRESULT OCIProfile::FinalConstruct()
46{
47 return BaseFinalConstruct();
48}
49
50void OCIProfile::FinalRelease()
51{
52 uninit();
53
54 BaseFinalRelease();
55}
56
57void OCIProfile::uninit()
58{
59 // Enclose the state transition Ready->InUninit->NotReady.
60 AutoUninitSpan autoUninitSpan(this);
61 if (autoUninitSpan.uninitDone())
62 return;
63
64 unconst(mVirtualBox) = NULL;
65 unconst(mParent).setNull();
66}
67
68HRESULT OCIProfile::initFromConfig(VirtualBox *aVirtualBox,
69 OCIProvider *aParent,
70 const com::Utf8Str &aProfileName)
71{
72 // Enclose the state transition NotReady->InInit->Ready.
73 AutoInitSpan autoInitSpan(this);
74 AssertReturn(autoInitSpan.isOk(), E_FAIL);
75#ifndef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
76 AssertReturn(aVirtualBox, E_INVALIDARG);
77#endif
78 AssertReturn(aParent, E_INVALIDARG);
79 AssertReturn(!aProfileName.isEmpty(), E_INVALIDARG);
80
81 unconst(mVirtualBox) = aVirtualBox;
82 unconst(mParent) = aParent;
83 unconst(mName) = aProfileName;
84
85 autoInitSpan.setSucceeded();
86 return S_OK;
87}
88
89HRESULT OCIProfile::initNew(VirtualBox *aVirtualBox,
90 OCIProvider *aParent,
91 const com::Utf8Str &aProfileName,
92 const std::vector<com::Utf8Str> &aNames,
93 const std::vector<com::Utf8Str> &aValues)
94{
95 // Enclose the state transition NotReady->InInit->Ready.
96 AutoInitSpan autoInitSpan(this);
97 AssertReturn(autoInitSpan.isOk(), E_FAIL);
98#ifndef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
99 AssertReturn(aVirtualBox, E_INVALIDARG);
100#endif
101 AssertReturn(aParent, E_INVALIDARG);
102 AssertReturn(!aProfileName.isEmpty(), E_INVALIDARG);
103
104 unconst(mVirtualBox) = aVirtualBox;
105 unconst(mParent) = aParent;
106 unconst(mName) = aProfileName;
107
108 HRESULT hrc = S_OK;
109 if (!aParent->i_existsProfile(aProfileName))
110 hrc = aParent->i_addProfile(aProfileName, aNames, aValues);
111 else
112 hrc = setError(E_FAIL, tr("Profile '%s' already exists"), aProfileName.c_str());
113
114 if (SUCCEEDED(hrc))
115 autoInitSpan.setSucceeded();
116 return hrc;
117}
118
119void OCIProfile::i_getProfile(StringMap &aProfile) const
120{
121 AutoCaller autoCaller(mParent);
122 if (FAILED(autoCaller.rc()))
123 return;
124 AutoReadLock plock(mParent COMMA_LOCKVAL_SRC_POS);
125
126 mParent->i_getProfileMap(mName, aProfile);
127}
128
129
130static struct
131{
132 const char *pszOCIConfigEntry, *pszDesciption;
133} const g_aOCIConfigEntryToDescription[] =
134{
135 { "user", "OCID of the user calling the API." },
136 { "tenancy", "OCID of your tenancy." },
137 { "compartment", "OCID of your compartment." },
138 { "fingerprint", "Fingerprint for the key pair being used." },
139 { "key_file", "Full path and filename of the private key."
140 "If you encrypted the key with a passphrase, you must also include "
141 "the pass_phrase entry in the config file."},
142 { "pass_phrase", "Passphrase used for the key, if it is encrypted." },
143 { "region", "An Oracle Cloud Infrastructure region" },
144};
145
146
147HRESULT OCIProfile::getName(com::Utf8Str &aName)
148{
149 // mName is constant during life time, no need to lock.
150 aName = mName;
151 return S_OK;
152}
153
154HRESULT OCIProfile::getProviderId(com::Guid &aProviderId)
155{
156 // provider id is constant during life time, no need to lock.
157 aProviderId = mParent->i_getId();
158 return S_OK;
159}
160
161HRESULT OCIProfile::getSupportedPropertyNames(std::vector<com::Utf8Str> &aSupportedPropertyNames)
162{
163 // g_aOCIConfigEntryToDescription is constant during life time, no need to lock.
164 for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i)
165 aSupportedPropertyNames.push_back(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry);
166 return S_OK;
167}
168
169HRESULT OCIProfile::getProperty(const com::Utf8Str &aName,
170 Utf8Str &aReturnValue)
171{
172 AutoCaller autoCaller(mParent);
173 if (FAILED(autoCaller.rc()))
174 return autoCaller.rc();
175 AutoReadLock alock(mParent COMMA_LOCKVAL_SRC_POS);
176 mParent->i_getProfileProperty(mName, aName, aReturnValue);
177 return S_OK;
178}
179
180HRESULT OCIProfile::setProperty(const com::Utf8Str &aName,
181 const com::Utf8Str &aValue)
182{
183 AutoCaller autoCaller(mParent);
184 if (FAILED(autoCaller.rc()))
185 return autoCaller.rc();
186 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS);
187 mParent->i_updateProfileProperty(mName, aName, aValue);
188 return S_OK;
189}
190
191HRESULT OCIProfile::getProperties(const com::Utf8Str &aNames,
192 std::vector<com::Utf8Str> &aReturnNames,
193 std::vector<com::Utf8Str> &aReturnValues)
194{
195 AutoCaller autoCaller(mParent);
196 if (FAILED(autoCaller.rc()))
197 return autoCaller.rc();
198 AutoReadLock alock(mParent COMMA_LOCKVAL_SRC_POS);
199 /// @todo implement name filtering (everywhere... lots of similar code in many places handling properties. */
200 RT_NOREF(aNames);
201 mParent->i_getProfile(mName, aReturnNames, aReturnValues);
202 return S_OK;
203}
204
205HRESULT OCIProfile::setProperties(const std::vector<com::Utf8Str> &aNames,
206 const std::vector<com::Utf8Str> &aValues)
207{
208 AutoCaller autoCaller(mParent);
209 if (FAILED(autoCaller.rc()))
210 return autoCaller.rc();
211 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS);
212 return mParent->i_updateProfile(mName, aNames, aValues);
213}
214
215HRESULT OCIProfile::getPropertyDescription(const com::Utf8Str &aName, com::Utf8Str &aDescription)
216{
217 // g_aOCIConfigEntryToDescription is constant during life time, no need to lock.
218 for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i)
219 if (aName.contains(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry, Utf8Str::CaseInsensitive))
220 {
221 aDescription = g_aOCIConfigEntryToDescription[i].pszDesciption;
222 }
223 return S_OK;
224}
225
226
227HRESULT OCIProfile::createCloudClient(ComPtr<ICloudClient> &aCloudClient)
228{
229 ComObjPtr<CloudClientOCI> pCloudClientOCI;
230 HRESULT hrc = pCloudClientOCI.createObject();
231 if (FAILED(hrc))
232 return hrc;
233 hrc = pCloudClientOCI->initCloudClient(mVirtualBox, this);
234 if (SUCCEEDED(hrc))
235 hrc = pCloudClientOCI.queryInterfaceTo(aCloudClient.asOutParam());
236
237 return hrc;
238}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette