(ctx context.Context, ch *cmdutil.Helper, projectPath, projectName, environment string, warnForNoVars bool)
| 47 | } |
| 48 | |
| 49 | func PullVars(ctx context.Context, ch *cmdutil.Helper, projectPath, projectName, environment string, warnForNoVars bool) error { |
| 50 | // Parse and verify the project directory |
| 51 | repo, instanceID, err := cmdutil.RepoForProjectPath(projectPath) |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | p, err := parser.Parse(ctx, repo, instanceID, "prod", "duckdb", true) |
| 56 | if err != nil { |
| 57 | return fmt.Errorf("failed to parse project: %w", err) |
| 58 | } |
| 59 | if p.RillYAML == nil { |
| 60 | return fmt.Errorf("not a valid Rill project (missing a rill.yaml file)") |
| 61 | } |
| 62 | |
| 63 | // Find the cloud project name |
| 64 | if projectName == "" { |
| 65 | projectName, err = ch.InferProjectName(ctx, projectPath, "use --project to specify the name") |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | } |
| 70 | client, err := ch.Client() |
| 71 | if err != nil { |
| 72 | return err |
| 73 | } |
| 74 | res, err := client.GetProjectVariables(ctx, &adminv1.GetProjectVariablesRequest{ |
| 75 | Org: ch.Org, |
| 76 | Project: projectName, |
| 77 | Environment: environment, |
| 78 | ForAllEnvironments: environment == "", |
| 79 | }) |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | |
| 84 | // new vars from the cloud |
| 85 | newVars := groupVariablesByEnv(res) |
| 86 | |
| 87 | // existing vars from the .env files in the project |
| 88 | currentVars := p.GetDotEnvPerEnvironment() |
| 89 | |
| 90 | // If variables for every environment are exactly the same as what's in the .env file, skip writing and warn the user |
| 91 | equal := true |
| 92 | for env, resVars := range newVars { |
| 93 | if !maps.Equal(resVars, currentVars[env]) { |
| 94 | equal = false |
| 95 | break |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if equal && warnForNoVars { |
| 100 | if len(res.Variables) == 0 { |
| 101 | ch.Printf("No cloud credentials found for project %q.\n", projectName) |
| 102 | } else { |
| 103 | ch.Printf("Local .env file is already up to date with cloud credentials.\n") |
| 104 | } |
| 105 | return nil |
| 106 | } |
no test coverage detected