| 144 | Option<Error> validateEnvironment(const Environment& environment) |
| 145 | { |
| 146 | foreach (const Environment::Variable& variable, environment.variables()) { |
| 147 | switch (variable.type()) { |
| 148 | case Environment::Variable::SECRET: { |
| 149 | if (!variable.has_secret()) { |
| 150 | return Error( |
| 151 | "Environment variable '" + variable.name() + |
| 152 | "' of type 'SECRET' must have a secret set"); |
| 153 | } |
| 154 | |
| 155 | if (variable.has_value()) { |
| 156 | return Error( |
| 157 | "Environment variable '" + variable.name() + |
| 158 | "' of type 'SECRET' must not have a value set"); |
| 159 | } |
| 160 | |
| 161 | Option<Error> error = validateSecret(variable.secret()); |
| 162 | if (error.isSome()) { |
| 163 | return Error( |
| 164 | "Environment variable '" + variable.name() + "' specifies an " |
| 165 | "invalid secret: " + error->message); |
| 166 | } |
| 167 | |
| 168 | if (variable.secret().value().data().find('\0') != string::npos) { |
| 169 | return Error( |
| 170 | "Environment variable '" + variable.name() + "' specifies a " |
| 171 | "secret containing null bytes, which is not allowed in the " |
| 172 | "environment"); |
| 173 | } |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | // NOTE: If new variable types are added in the future and an upgraded |
| 178 | // client/master sends a new type to an older master/agent, the older |
| 179 | // master/agent will see VALUE instead of the new type, since VALUE is set |
| 180 | // as the default type in the protobuf definition. |
| 181 | case Environment::Variable::VALUE: |
| 182 | if (!variable.has_value()) { |
| 183 | return Error( |
| 184 | "Environment variable '" + variable.name() + |
| 185 | "' of type 'VALUE' must have a value set"); |
| 186 | } |
| 187 | |
| 188 | if (variable.has_secret()) { |
| 189 | return Error( |
| 190 | "Environment variable '" + variable.name() + |
| 191 | "' of type 'VALUE' must not have a secret set"); |
| 192 | } |
| 193 | break; |
| 194 | |
| 195 | case Environment::Variable::UNKNOWN: |
| 196 | return Error("Environment variable of type 'UNKNOWN' is not allowed"); |
| 197 | |
| 198 | UNREACHABLE(); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | return None(); |
| 203 | } |
nothing calls this directly
no test coverage detected