Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks should be able to have access to the config #1207

Open
jcoyne opened this issue Nov 8, 2024 · 4 comments
Open

Hooks should be able to have access to the config #1207

jcoyne opened this issue Nov 8, 2024 · 4 comments

Comments

@jcoyne
Copy link

jcoyne commented Nov 8, 2024

In my case I need the ssh username in the pre-connect hook.

This allows my pre-connect hook to put a temporary key on the remote server. I have to do this because we use GSS-API/Kerberos for auth, but there is no support for that in net-ssh.

I'm basically porting this code for capistrano into a Kamal hook: https://github.com/cbeer/capistrano-one_time_key/blob/master/lib/capistrano/one_time_key.rb

@3v0k4
Copy link

3v0k4 commented Nov 13, 2024

Have you considered something like the following?

#!/usr/bin/env ruby

require 'yaml'

config = File.read(File.join(Dir.pwd, "config", "deploy.yml"))
ssh_user = YAML.load(config).dig("ssh", "user")
puts ssh_user

@jcoyne
Copy link
Author

jcoyne commented Nov 13, 2024

@3v0k4 that would work. It seemed inelegant, but maybe it doesn't matter to have two copies of the config loaded.

@3v0k4
Copy link

3v0k4 commented Nov 13, 2024

The thing is that, with the current architecture, hooks are run in a separate process that runs the script.

An alternative you could consider is:

#!/usr/bin/env ruby

require 'open3'

kamal = Gem.bin_path("kamal", "kamal")
config, _status = Open3.capture2(kamal, "config")
ssh_user = YAML.load(config).dig(:ssh_options, :user)
puts ssh_user

EDIT: use Gem.bin_path

@jcoyne
Copy link
Author

jcoyne commented Nov 13, 2024

Thank you for the suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants