| 111 | } |
| 112 | |
| 113 | foreach (const JSON::Value& item, archMap->values) { |
| 114 | if (!item.is<JSON::Object>()) { |
| 115 | return Error("'archMap' contains a non-object item"); |
| 116 | } |
| 117 | |
| 118 | const auto architecture = |
| 119 | item.as<JSON::Object>().at<JSON::String>("architecture"); |
| 120 | |
| 121 | if (!architecture.isSome()) { |
| 122 | return Error( |
| 123 | "Cannot determine 'architecture' field for 'archMap' item: " + |
| 124 | (architecture.isError() ? architecture.error() : "Not found")); |
| 125 | } |
| 126 | |
| 127 | const auto arch = parseArchitecture(architecture->value); |
| 128 | if (arch.isError()) { |
| 129 | return Error(arch.error()); |
| 130 | } |
| 131 | |
| 132 | Try<bool> nativeArch = SeccompFilter::nativeArch(arch.get()); |
| 133 | if (nativeArch.isError()) { |
| 134 | return Error(nativeArch.error()); |
| 135 | } |
| 136 | |
| 137 | // We ignore architectures that doesn't match the native architecture of |
| 138 | // this host. |
| 139 | if (!nativeArch.get()) { |
| 140 | continue; |
| 141 | } |
| 142 | |
| 143 | // Add this architecture with corresponding subarchitectures to the list of |
| 144 | // architectures of the profile. |
| 145 | const auto subArchitectures = |
| 146 | item.as<JSON::Object>().at<JSON::Array>("subArchitectures"); |
| 147 | |
| 148 | if (!subArchitectures.isSome()) { |
| 149 | return Error( |
| 150 | "Cannot determine 'subArchitectures' field for 'archMap' item: " + |
| 151 | (subArchitectures.isError() ? subArchitectures.error() |
| 152 | : "Not found")); |
| 153 | } |
| 154 | |
| 155 | foreach (const JSON::Value& subItem, subArchitectures->values) { |
| 156 | if (!subItem.is<JSON::String>()) { |
| 157 | return Error("'subArchitectures' contains a non-string item"); |
| 158 | } |
| 159 | |
| 160 | const auto subArch = parseArchitecture(subItem.as<JSON::String>().value); |
| 161 | if (subArch.isError()) { |
| 162 | return Error(subArch.error()); |
| 163 | } |
| 164 | |
| 165 | profile->mutable_architectures()->Add(subArch.get()); |
| 166 | } |
| 167 | |
| 168 | profile->mutable_architectures()->Add(arch.get()); |
| 169 | } |
| 170 |
nothing calls this directly
no test coverage detected