Mattijs De Paepe
11/28/2023, 10:32 PMprefect.yaml
to configure a git_clone
pull step that uses gitlab-credentials to clone a private repo.
It seems that the token which is of type pydantic SecretStr isn’t being resolved before the command of git clone …
is run. Has anyone else encountered this?Nate
11/28/2023, 10:49 PMpull
step?Mattijs De Paepe
11/28/2023, 10:54 PMpull:
- prefect.deployments.steps.git_clone:
repository: <https://git_url/some_group/repo.git>
branch: master
credentials: "{{ prefect.blocks.gitlab-credentials.mattijs-gitlab }}"
The reason I think it’s not being resolved (apart from not being able to see where in the code) is that I tried the following:
import prefect
from prefect.blocks.core import Block
from prefect.runner.storage import GitRepository
async with prefect.get_client() as client:
cred = await Block.load("gitlab-credentials/mattijs-gitlab", client=client)
# This doesn't work
git_repo = GitRepository(
url="<https://git_url/some_group/repo.git>",
credentials=cred,
branch="master",
include_submodules=False,
)
# This does work
git_repo = GitRepository(
url="<https://git_url/some_group/repo.git>",
credentials={"token": MY_TOKEN},
branch="master",
include_submodules=False,
)
async with prefect.get_client() as client:
await git_repo.pull_code()
Nate
11/28/2023, 10:59 PMasync with prefect.get_client() as client:
cred = await Block.load("gitlab-credentials/mattijs-gitlab", client=client)
shouldnt affect anything, just curiousMattijs De Paepe
11/28/2023, 11:06 PMRuntimeError Traceback (most recent call last)
/home/jupyter-mattijs/repos/X/Y.ipynb Cell 24 line 2
1 async with prefect.get_client() as client:
----> 2 await gr.pull_code()
File ~/.conda/envs/paps/lib/python3.10/site-packages/prefect/runner/storage.py:238, in GitRepository.pull_code(self)
235 except subprocess.CalledProcessError as exc:
236 # Hide the command used to avoid leaking the access token
237 exc_chain = None if self._credentials else exc
--> 238 raise RuntimeError(
239 f"Failed to clone repository {self._url!r} with exit code"
240 f" {exc.returncode}."
241 ) from exc_chain
RuntimeError: Failed to clone repository '<https://git_url/some_group/repo.git>' with exit code 128.
When you print the cmd
at this line, it prints with the asterisks (*) for the token i.e. https://********@git_url/some_group/repo.git
. The only thing that remains after from what I can see is the anyio.run_process
function which I don’t think would call .get_secret_value()
Mattijs De Paepe
11/28/2023, 11:09 PMclient = prefect.get_client()
cred = await Block.load("gitlab-credentials/mattijs-gitlab", client=client)
Mattijs De Paepe
11/28/2023, 11:11 PMNate
11/28/2023, 11:12 PMOh just realised, I don’t have to include the client in the load function callyep it should be the same thing, we will grab a client for you here with this `inject_client` decorator so you shouldn't have to pass your own unless you need a specific instance of a client for some reason
Nate
11/28/2023, 11:14 PMtype(MY_TOKEN)
here?
# This does work
git_repo = GitRepository(
url="<https://git_url/some_group/repo.git>",
credentials={"token": MY_TOKEN},
branch="master",
include_submodules=False,
)
Mattijs De Paepe
11/28/2023, 11:14 PMNate
11/28/2023, 11:22 PMgit_repo = GitRepository(
url="<https://git_url/some_group/repo.git>",
credentials={"access_token": Block.load("gitlab-credentials/mattijs-gitlab").dict().get("token")},
branch="master",
include_submodules=False,
)
Mattijs De Paepe
11/28/2023, 11:29 PMgit_repo = GitRepository(
url="<https://git.ridewithvia.dev/data-science/prebooking-algo-params-snowflake.git>",
credentials={"access_token": prefect.blocks.system.Secret(value=block.dict().get("token"))},
branch="master",
include_submodules=False,
)
(Block.load()
straight didn’t work because that returns a coroutine, or am I doing something wrong?)Mattijs De Paepe
11/28/2023, 11:29 PMNate
11/28/2023, 11:30 PM@sync_compatible
decorator, so you'd have to await Block.load
if calling from async contextMattijs De Paepe
11/29/2023, 10:10 AMNate
11/29/2023, 3:33 PM@sync_compatible
based on the type hinting I think we just need to better document this. GitRepository needs a Secret
block or a string
git_repo = GitRepository(
url="<https://git_url/some_group/repo.git>",
credentials={"access_token": await Secret.load("my-gitlab-token")},
branch="master",
include_submodules=False,
)
an enhancement
issue asking for support with GitlabCredentials
here i think would also make senseMattijs De Paepe
11/29/2023, 3:42 PMGitlabCredentials
block in a prefect.yaml
pull step. Nor a GithubCredentials
block I think but can’t test that. I think this is a regression.Mattijs De Paepe
11/29/2023, 3:43 PMNate
11/29/2023, 3:49 PMgit_clone
step under the hood to use GitRepository
, which doesn't correctly template out Gitlab / Github repo blocks. so actually yeah I agree this is a bugNate
11/29/2023, 3:50 PMalex
11/29/2023, 3:52 PMGitLabCredentials
block in this context, so looks like a bug to me also.Mattijs De Paepe
11/29/2023, 3:54 PMif isinstance(credentials.get("token"), SecretStr):
credentials["token"] = credentials["token"].get_secret_value()
alex
11/29/2023, 3:55 PMMattijs De Paepe
11/29/2023, 4:09 PM