11import base64
22import itertools
33import os
4+ import random
5+ import string
46from io import StringIO
57from pathlib import Path
68from typing import Any , Dict , List , Mapping , Optional , Tuple
79
810import ruamel .yaml
9- from pydantic import BaseModel
11+ from pydantic import BaseModel , Field
1012from ruamel .yaml import CommentedMap as CM
1113from ruamel .yaml import CommentedSeq as CS
1214
@@ -143,12 +145,20 @@ def stub_plugin(plugin: Plugin, namespace: str, repository: str, is_live: bool =
143145 return ruamel_dict
144146
145147
148+ def _get_seed_uid () -> str :
149+ return "" .join (
150+ random .choice (string .ascii_lowercase + string .ascii_uppercase + string .digits )
151+ for _ in range (10 )
152+ )
153+
154+
146155class ProjectSeed (BaseModel ):
147156 """
148157 Contains all information required to generate a Splitgraph project + optionally
149158 a dbt model for GitHub Actions
150159 """
151160
161+ seed_uid : str = Field (default_factory = _get_seed_uid )
152162 namespace : str
153163 plugins : List [str ]
154164 include_dbt : bool = False
@@ -162,11 +172,12 @@ def decode(cls, encoded: str) -> "ProjectSeed":
162172
163173
164174def generate_project (
165- api_client : GQLAPIClient , seed : ProjectSeed , basedir : Path , github_repo : Optional [str ] = None
175+ api_client : GQLAPIClient , seed : str , basedir : Path , github_repo : Optional [str ] = None
166176) -> None :
167- all_plugins = {p .plugin_name : p for p in api_client .get_all_plugins ()}
177+ all_plugins = {p .plugin_name : p for p in api_client .get_all_plugins (seed )}
168178
169- credentials , repositories , repository_info = generate_splitgraph_yml (all_plugins , seed )
179+ decoded_seed = ProjectSeed .decode (seed )
180+ credentials , repositories , repository_info = generate_splitgraph_yml (all_plugins , decoded_seed )
170181
171182 yml = ruamel .yaml .YAML ()
172183 with open (os .path .join (basedir , "splitgraph.credentials.yml" ), "w" ) as f :
@@ -176,7 +187,7 @@ def generate_project(
176187 yml .dump (repositories , f )
177188
178189 # Generate the dbt project
179- if seed .include_dbt :
190+ if decoded_seed .include_dbt :
180191 dbt_repo , _ , is_dbt = repository_info [- 1 ]
181192 assert is_dbt
182193 dbt_sources = [r for r , _ , is_dbt in repository_info if not is_dbt ]
0 commit comments