MCPcopy Create free account
hub / github.com/Icinga/icinga2 / CreateObjectConfig

Method CreateObjectConfig

lib/remote/configobjectutility.cpp:134–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134String ConfigObjectUtility::CreateObjectConfig(const Type::Ptr& type, const String& fullName,
135 bool ignoreOnError, const Array::Ptr& templates, const Dictionary::Ptr& attrs)
136{
137 auto *nc = dynamic_cast<NameComposer *>(type.get());
138 Dictionary::Ptr nameParts;
139 String name;
140
141 if (nc) {
142 nameParts = nc->ParseName(fullName);
143 name = nameParts->Get("name");
144 } else
145 name = fullName;
146
147 Dictionary::Ptr allAttrs = new Dictionary();
148
149 if (attrs) {
150 attrs->CopyTo(allAttrs);
151
152 ObjectLock olock(attrs);
153 for (const Dictionary::Pair& kv : attrs) {
154 int fid = type->GetFieldId(kv.first.SubStr(0, kv.first.FindFirstOf(".")));
155
156 if (fid < 0)
157 BOOST_THROW_EXCEPTION(ScriptError("Invalid attribute specified: " + kv.first));
158
159 Field field = type->GetFieldInfo(fid);
160
161 if (!(field.Attributes & FAConfig) || kv.first == "name")
162 BOOST_THROW_EXCEPTION(ScriptError("Attribute is marked for internal use only and may not be set: " + kv.first));
163 }
164 }
165
166 if (nameParts)
167 nameParts->CopyTo(allAttrs);
168
169 allAttrs->Remove("name");
170
171 /* update the version for config sync */
172 allAttrs->Set("version", Utility::GetTime());
173
174 std::ostringstream config;
175 ConfigWriter::EmitConfigItem(config, type->GetName(), name, false, ignoreOnError, templates, allAttrs);
176 ConfigWriter::EmitRaw(config, "\n");
177
178 return config.str();
179}
180
181bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& fullName,
182 const String& config, const Array::Ptr& errors, const Array::Ptr& diagnosticInformation, const Value& cookie)

Callers

nothing calls this directly

Calls 12

ScriptErrorClass · 0.85
SubStrMethod · 0.80
FindFirstOfMethod · 0.80
getMethod · 0.45
ParseNameMethod · 0.45
GetMethod · 0.45
CopyToMethod · 0.45
GetFieldIdMethod · 0.45
GetFieldInfoMethod · 0.45
RemoveMethod · 0.45
SetMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected