3
3
4
4
import click
5
5
import yaml
6
+ from dagster_shared .plus .config import DagsterPlusCliConfig
6
7
from dagster_shared .yaml_utils import parse_yaml_with_source_positions
7
8
from rich .console import Console
8
9
from rich .table import Table
12
13
from dagster_dg .component import get_specified_env_var_deps , get_used_env_vars
13
14
from dagster_dg .config import normalize_cli_config
14
15
from dagster_dg .context import DgContext
15
- from dagster_dg .env import ProjectEnvVars
16
+ from dagster_dg .env import ProjectEnvVars , get_project_specified_env_vars
16
17
from dagster_dg .utils import DgClickCommand , DgClickGroup
18
+ from dagster_dg .utils .plus import gql
19
+ from dagster_dg .utils .plus .gql_client import DagsterCloudGraphQLClient
17
20
from dagster_dg .utils .telemetry import cli_telemetry_wrapper
18
21
19
22
@@ -35,16 +38,61 @@ def list_env_command(**global_options: object) -> None:
35
38
cli_config = normalize_cli_config (global_options , click .get_current_context ())
36
39
dg_context = DgContext .for_project_environment (Path .cwd (), cli_config )
37
40
41
+ env_vars = get_project_specified_env_vars (dg_context )
42
+
38
43
env = ProjectEnvVars .from_ctx (dg_context )
39
- if not env .values :
40
- click .echo ("No environment variables are defined for this project." )
41
- return
42
44
43
45
table = Table (border_style = "dim" )
44
46
table .add_column ("Env Var" )
45
- table .add_column ("Value" )
46
- for key , value in env .values .items ():
47
- table .add_row (key , value )
47
+ table .add_column ("Local Value" )
48
+ table .add_column ("Components" )
49
+ env_var_keys = set (env .values .keys ()) | set (env_vars .keys ())
50
+
51
+ if DagsterPlusCliConfig .exists ():
52
+ table .add_column ("Dev" )
53
+ table .add_column ("Branch" )
54
+ table .add_column ("Full" )
55
+ scopes_for_key = {}
56
+ config = DagsterPlusCliConfig .get ()
57
+ gql_client = DagsterCloudGraphQLClient .from_config (config )
58
+ for key in env_var_keys :
59
+ secrets_by_location = gql_client .execute (
60
+ gql .GET_SECRETS_FOR_SCOPES_QUERY ,
61
+ {
62
+ "locationName" : dg_context .project_name ,
63
+ "scopes" : {
64
+ "fullDeploymentScope" : True ,
65
+ "allBranchDeploymentsScope" : True ,
66
+ "localDeploymentScope" : True ,
67
+ },
68
+ "secretName" : key ,
69
+ },
70
+ )["secretsForScopes" ]["secrets" ]
71
+ scopes_for_key [key ] = {
72
+ "full" : any (secret ["fullDeploymentScope" ] for secret in secrets_by_location ),
73
+ "branch" : any (
74
+ secret ["allBranchDeploymentsScope" ] for secret in secrets_by_location
75
+ ),
76
+ "local" : any (secret ["localDeploymentScope" ] for secret in secrets_by_location ),
77
+ }
78
+
79
+ if not env_var_keys :
80
+ click .echo ("No environment variables are defined for this project." )
81
+ return
82
+
83
+ for key in env_var_keys :
84
+ value = env .values .get (key )
85
+ components = env_vars .get (key , [])
86
+ table .add_row (
87
+ key ,
88
+ value ,
89
+ ", " .join (str (path ) for path in components ),
90
+ * (
91
+ ["X" if scopes_for_key [key ][scope ] else "" for scope in ["local" , "branch" , "full" ]]
92
+ if DagsterPlusCliConfig .exists ()
93
+ else []
94
+ ),
95
+ )
48
96
console = Console ()
49
97
console .print (table )
50
98
0 commit comments