| 1 |
// Package experiments contains functionalities to retrieve synced experiments |
| 2 |
package experiments |
| 3 |
|
| 4 |
import ( |
| 5 |
"encoding/json" |
| 6 |
"fmt" |
| 7 |
"os" |
| 8 |
) |
| 9 |
|
| 10 |
// Experiments contains the experiments flags this version of the launcher expects to receive. |
| 11 |
// Failure to unmarshal the experiment JSON data will result in an empty object being returned |
| 12 |
// to treat experiment flags as their default value. The error should still be checked. |
| 13 |
type Experiments struct { |
| 14 |
EnableTestFeatureForImage bool |
| 15 |
EnableHealthMonitoring bool |
| 16 |
EnableItaVerifier bool |
| 17 |
EnableVerifyCS bool |
| 18 |
EnableAttestationEvidence bool |
| 19 |
EnableB200DriverInstallation bool |
| 20 |
EnableH100DriverInstallation bool |
| 21 |
EnableKeyManager bool |
| 22 |
} |
| 23 |
|
| 24 |
// New takes a filepath, opens the file, and calls ReadJsonInput with the contents |
| 25 |
// of the file. |
| 26 |
// If the file cannot be opened, the experiments map is set to an empty map. |
| 27 |
func New(fpath string) (Experiments, error) { |
| 28 |
f, err := os.ReadFile(fpath) |
| 29 |
if err != nil { |
| 30 |
// Return default values on failure. |
| 31 |
return Experiments{}, err |
| 32 |
} |
| 33 |
|
| 34 |
r, err := readJSONInput(f) |
| 35 |
|
| 36 |
return r, err |
| 37 |
} |
| 38 |
|
| 39 |
// ReadJSONInput takes a reader and unmarshals the contents into the experiments map. |
| 40 |
// If the unmarsahlling fails, the experiments map is set to an empty map. |
| 41 |
func readJSONInput(b []byte) (Experiments, error) { |
| 42 |
var experiments Experiments |
| 43 |
if err := json.Unmarshal(b, &experiments); err != nil { |
| 44 |
// Return default values on failure. |
| 45 |
return Experiments{}, fmt.Errorf("failed to unmarshal json: %w", err) |
| 46 |
} |
| 47 |
return experiments, nil |
| 48 |
} |