Exports added by :with are ineffective when :user is specified
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 48/100
Línea de trabajo
Comienza localizando los métodos builder with y user mostrados en el issue e inspecciona cómo componen el comando de shell generado cuando se usan ambas opciones. El cambio estará terminado cuando el builder with no añada un subshell de export para un comando de usuario, mientras que el builder user siga proporcionando las variables de entorno.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
When a command is mapped, (:should_map?), both :with and :user are invoked.
In both builder methods, the environment variables specified are intended to be inherited by the subshell.
Say that we have the env var MYVAR=myvar, and the command mycommand, which needs to be run as the user myuser. The relevant builder methods are:
def with(&_block)
env_string = environment_string
return yield if env_string.empty?
"( export #{env_string} ; #{yield} )"
end
def user(&_block)
return yield unless options[:user]
env_string = environment_string
"sudo -u #{options[:user].to_s.shellescape} #{env_string + " " unless env_string.empty?}-- sh -c #{yield.shellescape}"
end
this will generate something like:
( export MYVAR=myvar ; sudo -u myuser MYVAR=myvar -- sh -c command )
The problem is that the export is ineffective, because exports are not inherited by the sudo subshell.
While this is harmless, it clutters the generated commands, and it's also semantically incorrect (because it's ineffective) and confusing.
This could be avoided by just yielding the the builder block if options[:user] is set:
def with(&_block)
> # Exports are ineffective on non-login (sudo) shells; in this case, the :user builder takes
> # care of setting them.
> return yield if options[:user]
env_string = environment_string
return yield if env_string.empty?
"( export #{env_string} ; #{yield} )"
end
This makes the (internal) commands output more readable (and understandable). While this has no effect on the end users, it helps understanding those who approach Capistrano/Sshkit development (at least, it did it for me 😬).
If this is approved (either in this form or another), I can easily open a PR.
- Lenguaje dominante
- Ruby
- Estrellas
- 1.2k
- Forks
- 257
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de capistrano/sshkit
-
should have an openssh backend Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
capistrano/sshkit#563 · 6 reacciones ·
-
No redaction for with values Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
capistrano/sshkit#562 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 48/100
capistrano/sshkit#554 · 3 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
capistrano/sshkit#543 · 2 comentarios ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
capistrano/sshkit#518 · 1 comentario ·
Todos los issues de capistrano/sshkit
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
simp/pupmod-simp-simp#395 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
simp/pupmod-simp-rsyslog#219 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
simp/pupmod-simp-pupmod#256 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
simp/pupmod-simp-sudo#150 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100