Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Exports added by :with are ineffective when :user is specified

未关闭
#490 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
ruby
领域
devops

调研方向

首先定位 issue 中所示的 with 和 user builder 方法,并检查在同时使用这两个选项时,它们如何组合生成的 shell 命令。当 with builder 不再为用户命令添加 export 子 shell,而 user builder 仍然提供环境变量时,此更改即完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Ruby
星标
1.2k
派生
257
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

capistrano/sshkit 的其他 Issue

查看 capistrano/sshkit 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。