Class: VagrantPlugins::OrbStack::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-orbstack/config.rb

Overview

Configuration class for OrbStack provider.

This class defines configuration options available in Vagrantfiles for customizing OrbStack machine creation and behavior.

Examples:

Basic configuration

Vagrant.configure("2") do |config|
  config.vm.provider :orbstack do |os|
    os.distro = "ubuntu"
    os.version = "22.04"
    os.machine_name = "my-dev-env"
  end
end

Constant Summary collapse

DISTRO_EMPTY_ERROR =

Error message constants for validation

'distro cannot be empty'
MACHINE_NAME_FORMAT_ERROR =
'machine_name must contain only alphanumeric characters and hyphens'
SSH_USERNAME_EMPTY_ERROR =
'ssh_username cannot be empty'
FORWARD_AGENT_BOOLEAN_ERROR =
'forward_agent must be a boolean (true or false)'
MACHINE_NAME_PATTERN =

Regular expression pattern for valid machine_name format.

Valid machine names must:

  • Start with an alphanumeric character (a-z, A-Z, 0-9)
  • End with an alphanumeric character
  • May contain hyphens between alphanumeric segments
  • No consecutive hyphens allowed
/^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Initialize configuration with unset values.



68
69
70
71
72
73
74
75
76
# File 'lib/vagrant-orbstack/config.rb', line 68

def initialize
  super
  @distro = VagrantPlugins::OrbStack::UNSET_VALUE
  @version = VagrantPlugins::OrbStack::UNSET_VALUE
  @machine_name = VagrantPlugins::OrbStack::UNSET_VALUE
  @ssh_username = VagrantPlugins::OrbStack::UNSET_VALUE
  @forward_agent = VagrantPlugins::OrbStack::UNSET_VALUE
  @logger = Log4r::Logger.new('vagrant_orbstack::config')
end

Instance Attribute Details

#distroString?

Linux distribution to use for the machine

Returns:

  • (String, nil)

    Distribution name (e.g., "ubuntu", "debian")



47
48
49
# File 'lib/vagrant-orbstack/config.rb', line 47

def distro
  @distro
end

#forward_agentBoolean?

Enable SSH agent forwarding

Returns:

  • (Boolean, nil)

    Whether to forward SSH agent (defaults to false)



47
# File 'lib/vagrant-orbstack/config.rb', line 47

attr_accessor :distro

#machine_nameString?

Custom name for the OrbStack machine

Returns:

  • (String, nil)

    Machine name



47
# File 'lib/vagrant-orbstack/config.rb', line 47

attr_accessor :distro

#ssh_usernameString?

Custom SSH username for connecting to the machine

Returns:

  • (String, nil)

    SSH username (defaults to OrbStack's default if nil)



47
# File 'lib/vagrant-orbstack/config.rb', line 47

attr_accessor :distro

#versionString?

Distribution version to use

Returns:

  • (String, nil)

    Version string (e.g., "22.04")



47
# File 'lib/vagrant-orbstack/config.rb', line 47

attr_accessor :distro

Instance Method Details

#finalize!Object

Finalize configuration by setting defaults.

Called by Vagrant after Vagrantfile is loaded to set default values for any unset configuration options.



84
85
86
87
88
89
90
# File 'lib/vagrant-orbstack/config.rb', line 84

def finalize!
  @distro = 'ubuntu' if @distro == VagrantPlugins::OrbStack::UNSET_VALUE
  @version = nil if @version == VagrantPlugins::OrbStack::UNSET_VALUE
  @machine_name = nil if @machine_name == VagrantPlugins::OrbStack::UNSET_VALUE
  @ssh_username = nil if @ssh_username == VagrantPlugins::OrbStack::UNSET_VALUE
  @forward_agent = false if @forward_agent == VagrantPlugins::OrbStack::UNSET_VALUE
end

#validate(_machine) ⇒ Hash<String, Array<String>>

Validate configuration values.

Parameters:

  • _machine (Vagrant::Machine)

    The machine to validate for

Returns:

  • (Hash<String, Array<String>>)

    Validation errors by namespace



97
98
99
100
101
102
103
104
# File 'lib/vagrant-orbstack/config.rb', line 97

def validate(_machine)
  errors = _detected_errors
  validate_distro(errors)
  validate_machine_name(errors)
  validate_ssh_username(errors)
  validate_forward_agent(errors)
  { 'OrbStack Provider' => errors }
end