{"id":13452375,"url":"https://github.com/inspec/train","last_synced_at":"2025-03-23T19:34:10.957Z","repository":{"id":37430993,"uuid":"44141707","full_name":"inspec/train","owner":"inspec","description":"Transport Interface to unify communication over SSH, WinRM, and friends.","archived":false,"fork":false,"pushed_at":"2024-04-10T11:37:34.000Z","size":2183,"stargazers_count":120,"open_issues_count":65,"forks_count":88,"subscribers_count":72,"default_branch":"main","last_synced_at":"2024-04-12T09:18:19.599Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inspec.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-10-13T00:26:45.000Z","updated_at":"2024-04-15T09:04:18.297Z","dependencies_parsed_at":"2023-10-20T20:23:44.606Z","dependency_job_id":"e8636f0e-697c-4317-85e8-7c44f648d3a8","html_url":"https://github.com/inspec/train","commit_stats":{"total_commits":1295,"total_committers":119,"mean_commits":"10.882352941176471","dds":0.8277992277992278,"last_synced_commit":"13a73252bc87eb89ce4417862f9003ff8d4e6263"},"previous_names":["chef/train"],"tags_count":338,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inspec%2Ftrain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inspec%2Ftrain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inspec%2Ftrain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inspec%2Ftrain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inspec","download_url":"https://codeload.github.com/inspec/train/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245159335,"owners_count":20570363,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:01:22.310Z","updated_at":"2025-03-23T19:34:10.417Z","avatar_url":"https://github.com/inspec.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Train - Transport Interface\n\n* **Project State: Active**\n* **Issues Response SLA: 3 business days**\n* **Pull Request Response SLA: 3 business days**\n\nFor more information on project states and SLAs, see [this documentation](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md).\n\n[![Build status](https://badge.buildkite.com/ee9d6f49d995b23e943955b12d5aaadf4314d12b7cc99b03be.svg?branch=master)](https://buildkite.com/chef-oss/inspec-train-master-verify)\n[![Gem Version](https://badge.fury.io/rb/train.svg)](https://badge.fury.io/rb/train)\n\n**Umbrella Project**: [Chef Foundation](https://github.com/chef/chef-oss-practices/blob/master/projects/chef-foundation.md)\n\n**Project State**: [Active](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md#active)\n\n**Issues [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md)**: 14 days\n\n**Pull Request [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md)**: 14 days\n\nTrain lets you talk to your local or remote operating systems and APIs with a unified interface.\n\nIt allows you to:\n\n* execute commands via `run_command`\n* interact with files via `file`\n* identify the target operating system via `os`\n* authenticate to API-based services and treat them like a platform\n\nTrain supports:\n\n* Local execution\n* SSH\n* WinRM\n* Docker and Podman\n* Mock (for testing and debugging)\n* AWS as an API\n* Azure as an API\n* VMware via PowerCLI\n* Habitat\n\n# Examples\n\n## Setup\n\n**Local**\n\n```ruby\nrequire 'train'\ntrain = Train.create('local')\n```\n\n**SSH**\n\n```ruby\nrequire 'train'\ntrain = Train.create('ssh',\n  host: '1.2.3.4', port: 22, user: 'root', key_files: '/vagrant')\n```\n\nIf you don't specify the `key_files` and `password` options, SSH agent authentication will be attempted. For example:\n\n```ruby\nrequire 'train'\ntrain = Train.create('ssh', host: '1.2.3.4', port: 22, user: 'root')\n```\n\nSSH transport has an `ssh_config_file` option to set the SSH config file path. This is set by default to `true` to read the values from the default SSH config file path. For example, `~/.ssh/config`, `/etc/ssh_config`, `/etc/ssh/ssh_config`. Precedence is given to the options set through the arguments.\n\n**WinRM**\n\n```ruby\nrequire 'train'\ntrain = Train.create('winrm',\n  host: '1.2.3.4', user: 'Administrator', password: '...', ssl: true, self_signed: true)\n```\n\n**Docker**\n\n```ruby\nrequire 'train'\ntrain = Train.create('docker', host: 'container_id...')\n```\nYou can use `user` option to connect with privileged user on non root user images.\n\n```ruby\nrequire 'train'\ntrain = Train.create('docker', host: 'container_id...', user: 'root')\n```\n\nFor Docker Desktop for Windows, you must enable the \"Expose daemon on tcp://localhost:2375 without TLS\" setting. To change the URL that train uses to connect to Docker, use the `docker_url` option:\n\n```ruby\nrequire 'train'\ntrain = Train.create('docker', host: 'container_id...', docker_url: 'tcp://localhost:1234')\n```\n\nWindows Docker containers require PowerShell, which is assumed to be installed as `powershell.exe`. If it is installed as `pwsh`, use the `--shell-command` option to specify `pwsh` as the shell.\n\n**Podman**\n\n```ruby\nrequire 'train'\ntrain = Train.create('podman', host: 'container_id...')\n```\n\n```ruby\nrequire 'train'\ntrain = Train.create('podman', host: 'container_id...', podman_url: 'tcp://localhost:1234')\n```\n\nTo connect to a Podman container, the Podman API endpoint URL needs to set. It can be set through the `podman_url` option or else Train will check for the CONTAINER_HOST environment variable. If neither is defined then Train will try to connect to the default URL, that is `unix:///run/user/UID/podman/podman.sock` for non-root users and `unix:///run/podman/podman.sock` for the root user. Precedence is given to options set through the arguments.\n\n**AWS**\n\nTo use AWS API authentication, setup an AWS client profile to store the Access Key ID and Secret Access Key.\n\n```ruby\nrequire 'train'\ntrain = Train.create('aws', region: 'us-east-2', profile: 'my-profile')\n```\n\nYou may also use the standard AWS CLI environment variables, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_REGION`.\n\n```ruby\nrequire 'train'\ntrain = Train.create('aws')\n```\n\n**VMware**\n\n```ruby\nrequire 'train'\nTrain.create('vmware', viserver: '10.0.0.10', user: 'demouser', password: 'securepassword')\n```\n\nYou may also use environment variables by setting `VISERVER`, `VISERVER__USERNAME`, and `VISERVER_PASSWORD`\n\n```ruby\nrequire 'train'\nTrain.create('vmware')\n```\n\n## Configuration\n\nTo get a list of available options for a plugin:\n\n```ruby\nputs Train.options('ssh')\n```\nThis will provide all configuration options:\n\n```ruby\n{\n  :host     =\u003e { :required =\u003e true},\n  :port     =\u003e { :default  =\u003e 22, :required =\u003e true},\n  :user     =\u003e { :default  =\u003e \"root\", :required =\u003e true},\n  :keys     =\u003e { :default  =\u003e nil},\n  :password =\u003e { :default  =\u003e nil},\n  ...\n```\n\n## Usage\n\n```ruby\n# start or reuse a connection\nconn = train.connection\n\n# run a command on Linux/Unix/Mac\nputs conn.run_command('whoami').stdout\n\n# get OS info\nputs conn.os[:family]\nputs conn.os[:release]\n\n# access files\nputs conn.file('/proc/version').content\n\n# access specific API client functionality\nec2_client = train.connection.aws_client(Aws::EC2::Client)\nputs ec2_client.describe_instances\n\n# close the connection\nconn.close\n```\n\n# Testing\n\nWe perform `unit`, `integration` and `windows` tests.\n\n* `unit` tests ensure the intended behaviour of the implementation\n* `integration` tests run against VMs and docker containers\n* `windows` tests that run on appveyor for windows integration tests\n\n## Mac/Linux\n\n```\nbundle exec ruby -W -Ilib:test/unit test/unit/extras/stat_test.rb\n```\n\n## Windows\n\n```\n# run windows tests\nbundle exec rake test:windows\n\n# run single tests\nbundle exec ruby -I .\\test\\windows\\ .\\test\\windows\\local_test.rb\n```\n\n\n# Kudos and Contributors\n\nTrain is heavily based on the work of:\n\n* [test-kitchen](https://github.com/test-kitchen/test-kitchen)\n\n    by [Fletcher Nichol](mailto:fnichol@nichol.ca)\n    and [a great community of contributors](https://github.com/test-kitchen/test-kitchen/graphs/contributors)\n\n* [ohai](https://github.com/chef/ohai)\n\n    by Adam Jacob, Chef Software Inc.\n    and [a great community of contributors](https://github.com/chef/ohai/graphs/contributors)\n\n\nWe also want to thank [halo](https://github.com/halo) who did a great contribution by handing over the `train` gem name.\n\n## Contributing\n\n1. Fork it\n1. Create your feature branch (git checkout -b my-new-feature)\n1. Commit your changes (git commit -am 'Add some feature')\n1. Push to the branch (git push origin my-new-feature)\n1. Create new Pull Request\n\n## License\n\n| **Author:**          | Dominik Richter (\u003cdrichter@chef.io\u003e)\n\n| **Author:**          | Christoph Hartmann (\u003cchartmann@chef.io\u003e)\n\n| **Copyright:**       | Copyright (c) 2015-2019 Chef Software Inc.\n\n| **Copyright:**       | Copyright (c) 2015 Vulcano Security GmbH.\n\n| **License:**         | Apache License, Version 2.0\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finspec%2Ftrain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finspec%2Ftrain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finspec%2Ftrain/lists"}