@@ -44,19 +44,35 @@ layout uv
4444# debugging much more challenging. It's easy for obscure error messages to get swallowed up and waste development time
4545# forgetting that this error path exists.
4646op_inject_source () {
47- local tmpfile
48- tmpfile=$( mktemp)
47+ local input_file injected_file op_reference_pattern
48+ op_reference_pattern=' op://[[:alnum:].~_-]+/[[:alnum:].~_-]+/[[:alnum:].~_/-]+'
49+ # simplified matcher for op://vault/item/field references with alnum, dot, underscore, tilde, dash, or slash in the field
50+ # references using other characters or additional path segments will bypass replacement
51+
52+ input_file=$( umask 077; mktemp)
53+ injected_file=$( umask 077; mktemp)
54+
55+ if ! cat > " $input_file " ; then
56+ just _banner_echo " Failed to capture inject input"
57+ rm -f " $input_file " " $injected_file "
58+ return 1
59+ fi
4960
5061 if [ -n " ${OP_INTEGRATION_DISABLED:- } " ]; then
51- cat > " $tmpfile "
52- sed -E ' s@op://[^[:space:]]+@fake-op-value@g' " $tmpfile " > " ${tmpfile} .fake"
53- source " ${tmpfile} .fake"
54- rm -f " $tmpfile " " ${tmpfile} .fake"
62+ if grep -Eq " ${op_reference_pattern} " " $input_file " ; then
63+ # intentionally uses a single placeholder for all secrets while OP integration is disabled
64+ sed -E " s|${op_reference_pattern} |fake-op-value|g" " $input_file " > " $injected_file "
65+ else
66+ just _banner_echo " OP_INTEGRATION_DISABLED set but no op references matched fallback pattern; leaving values unchanged"
67+ cp " $input_file " " $injected_file "
68+ fi
69+ source " $injected_file "
70+ rm -f " $input_file " " $injected_file "
5571 return 0
5672 fi
5773
5874 # `inject` consumes stdin
59- if ! op inject > " $tmpfile " ; then
75+ if ! op inject < " $input_file " > " $injected_file " ; then
6076 just _banner_echo " 1Password injection failed"
6177 cat >&2 << EOF
6278Make sure you're authenticated with 1Password, have access to referenced secrets, and are using valid secret references.
@@ -72,12 +88,12 @@ Some tips on how to resolve this issue:
7288- If you move a 1P entry out of a vault, this will cause a missing entry error.
7389
7490EOF
75- rm -f " $tmpfile "
91+ rm -f " $input_file " " $injected_file "
7692 return 1
7793 fi
7894
79- source " $tmpfile "
80- rm -f " $tmpfile "
95+ source " $injected_file "
96+ rm -f " $input_file " " $injected_file "
8197}
8298
8399# this is hack to allow us to render a specific .env file
0 commit comments