gpt4 book ai didi

github - 我想在我的 GIT 存储库上使用 HTTPS 连接,并且凭据在数据包中

转载 作者:行者123 更新时间:2023-12-04 14:15:07 26 4
gpt4 key购买 nike

我正在尝试创建一个配方,该配方将使用我的用户名和密码下载我的 git 存储库,这些用户名和密码位于数据包中。这是我的代码,下面是一个错误,表明它无法在我的 git 块中获取我的凭据。有任何想法吗?

accounts = data_bag_item('databag_name', 'databag_item')

git "my_repo" do
user accounts
puts user.inspect
repository "https://github.com/my_repo/myrepo.git"
reference "branch"
destination "/var/www/myrepo"
action :sync
end

我的错误是:
Expected process to exit with [0], but received '1'
---- Begin output of git ls-remote https://github.com/my_repo/myrepo.git branch ----
STDOUT: 
STDERR: /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:172:in `getpwnam': can't find user for accounts (ArgumentError)
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:172:in `uid'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:92:in `set_user'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:226:in `block in fork_subprocess'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:222:in `fork'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:222:in `fork_subprocess'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:35:in `run_command'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:222:in `run_command'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/shell_out.rb:30:in `shell_out'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/shell_out.rb:35:in `shell_out!'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:222:in `remote_resolve_reference'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:212:in `target_revision'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:68:in `block (2 levels) in define_resource_requirements'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:232:in `call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:232:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:322:in `block in run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:321:in `each'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:321:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider.rb:128:in `process_resource_requirements'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider.rb:105:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource.rb:597:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:49:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `block (2 levels) in converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `each'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `block in converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection.rb:94:in `block in execute_each_resource'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection.rb:92:in `execute_each_resource'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:80:in `converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:378:in `converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:420:in `do_run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:176:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application.rb:140:in `run_chef_client'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:274:in `block in run_application'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:267:in `loop'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:267:in `run_application'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application.rb:72:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/bin/chef-client:26:in `<top (required)>'
from /usr/bin/chef-client:23:in `load'
from /usr/bin/chef-client:23:in `<main>'
---- End output of git ls-remote https://github.com/my_repo/myrepo.git branch ----
Ran git ls-remote https://github.com/my_repo/myrepo.git branch returned 1

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/themes/recipes/default.rb

 34: git "my_repo" do
 35:   user "accounts"
 36:   puts user.inspect
 37:   repository "https://github.com/my_repo/myrepo.git"
 38:   reference "branch"
 39:   destination "/var/www/my_repo"
 41:   action :sync
 42: end
 43: 

Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/themes/recipes/default.rb:34:in `from_file'

git("my_repo") do
  provider Chef::Provider::Git
  action [:sync]
  retries 0
  retry_delay 2
  destination "/var/www/my_repo"
  revision "branch"
  remote "origin"
  cookbook_name "themes"
  recipe_name "default"
  user "accounts"
  repository "https://github.com/my_repo/myrepo.git"
end

[2013-01-31T10:12:21+00:00] ERROR: Running exception handlers
[2013-01-31T10:12:21+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-01-31T10:12:21+00:00] ERROR: Exception handlers complete
[2013-01-31T10:12:21+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-01-31T10:12:21+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: git[my_repo] (themes::default line 34) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of git ls-remote https://github.com/my_repo/myrepo.git branch ----
STDOUT: 
STDERR: /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:172:in `getpwnam': can't find user for accounts (ArgumentError)
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:172:in `uid'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:92:in `set_user'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:226:in `block in fork_subprocess'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:222:in `fork'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:222:in `fork_subprocess'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:35:in `run_command'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:222:in `run_command'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/shell_out.rb:30:in `shell_out'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/shell_out.rb:35:in `shell_out!'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:222:in `remote_resolve_reference'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:212:in `target_revision'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:68:in `block (2 levels) in define_resource_requirements'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:232:in `call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:232:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:322:in `block in run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:321:in `each'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:321:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider.rb:128:in `process_resource_requirements'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider.rb:105:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource.rb:597:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:49:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `block (2 levels) in converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `each'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `block in converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection.rb:94:in `block in execute_each_resource'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection.rb:92:in `execute_each_resource'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:80:in `converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:378:in `converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:420:in `do_run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:176:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application.rb:140:in `run_chef_client'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:274:in `block in run_application'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:267:in `loop'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:267:in `run_application'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application.rb:72:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/bin/chef-client:26:in `<top (required)>'
from /usr/bin/chef-client:23:in `load'
from /usr/bin/chef-client:23:in `<main>'
---- End output of git ls-remote https://github.com/my_repo/myrepo.git branch ----
Ran git ls-remote https://github.com/my_repo/myrepo.git branch returned 1

---

是否有示例代码显示如何通过数据包通过身份验证从 github 下载我的代码。

最佳答案

user 中的属性git resource 不是 GitHub 上的用户名,而是系统用户,它将成为您克隆存储库的目录的所有者。显然您没有创建系统用户帐户,所以这就是您收到错误的原因。

您的 git 资源应如下所示:

git "/var/www/myrepo" do
repository "git@github.com:username/myrepo.git" #or "https://github.com/my_repo/myrepo.git"
revision "HEAD"
action :sync
end

但是您需要某种机制来在 GitHub 上进行身份验证。我建议使用 ssh key ,因为我不知道有什么方法可以永久存储您的密码以进行身份​​验证 - 只有一些 caching少量时间可用。可以根据 this guide on GitHub生成 key 对.然后,您可以将您的私钥保存在 中。加密数据包 .
{
"id": "mykeys",
"private": "[The private key with newlines replaced with \n]",
"public": "[The public key with newlines replaced with \n]"
}

然后你可以使用你在recipe中的数据包在~/.ssh/id_rsa中重新创建一个私钥文件
keys = Chef::EncryptedDataBagItem.load('databag_name', 'mykeys')

directory ::File.join( ENV['HOME'], '.ssh' ) do
mode 0755
end

file ::File.join( ENV['HOME'], '.ssh', 'id_rsa' ) do
content keys['private']
mode 0600
end

要跳过检查主机“github.com”的真实性,请在您的说明书 files/default/config 中创建一个包含以下内容的文件。
Host github.com
StrictHostKeyChecking no
UserKnownHostsFile /dev/null

并将以下内容添加到配方中:
cookbook_file ::File.join( ENV['HOME'], '.ssh', 'config' ) do
mode 0644
end

如果您不想以 root 身份,而是以其他用户身份克隆存储库,那么您必须在该用户的主目录中创建所有 .ssh 配置文件。

关于github - 我想在我的 GIT 存储库上使用 HTTPS 连接,并且凭据在数据包中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14624560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com