vagrant-windows-domain 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbdaa30870420b7e0fc8c44c2716a0bf97f5067114f276f391a6147ef6d29c7a
4
- data.tar.gz: 52db0ec2e6a68ef743f10720d0c03add6844c59e31f6a6e974db046d10c187cf
3
+ metadata.gz: b03f283e47170d9b9a2db97da8a456a11ba260a851fc2f54f8a84d5513e258bd
4
+ data.tar.gz: 05f3530dd6fa06382d09515160c8a06f4c538d45f66ee15f80840e6d1276b059
5
5
  SHA512:
6
- metadata.gz: 6915697baa4d5922ad0c33b17466e0d01f5dc92ab26fbe295aa6009bd50c4d3b3d79234460d3b3368f90a02b93db51c9b33c176967311e3a7087ec3b984f4a3c
7
- data.tar.gz: b1dc722b9620aeeb3a03870c063351d79161af9931f603cfcf389c06e23685a5716ae71c3921f852debb772ad8006d4b72447b2d5b90f4ae6565c9ff7cbcdeb8
6
+ metadata.gz: 75ed7c28a93fe9a00a5cc7d30ed30f4631e1e4773f196fe5dcfb667265f30bcf514afcc74a4af08230dacbd39364eef6c5850494f0c29824bbe21a0f22f9ee15
7
+ data.tar.gz: 247b3cb63c12c8597a1fcceeca3799f4f30cd529fcd197e3d0d7eb198febeb11d977bc1eab66d989ba0efb2d56b8cca05d3e705a994b705ff409844d65835097
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
2
  before_install:
3
+ - gem update --system
3
4
  - gem install bundler
4
5
  rvm:
6
+ - ruby-head
5
7
  - 2.5.1
6
8
  - 2.4.4
7
- - ruby-head
8
9
  matrix:
9
10
  allow_failures:
10
11
  - rvm: ruby-head
@@ -12,6 +13,4 @@ matrix:
12
13
  env:
13
14
  matrix:
14
15
  - VAGRANT_VERSION=v2.1.5
15
- global:
16
- secure: bs4ezY+1Wksy8hH3nymPJ3AL99mpXULVc/AIh16JetEYw1850QkX7r4gQukMlcyByKUhxucjDLid0Y+KDH5kGMM16QjrVQGhAnUQzMoLD2qPbAaxDCUqpCJtFEEQKYxJvFvEK8a5SQzAsTVG4sgABQ/MllsIIH0FjkWgFtH6050=
17
16
  script: bundle exec rake test:unit
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
7
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", :tag => "v2.1.5"
8
8
  end
9
9
 
@@ -75,7 +75,7 @@ module VagrantPlugins
75
75
 
76
76
  # Final step of the Configuration lifecyle prior to
77
77
  # validation.
78
- #
78
+ #
79
79
  # Ensures all attributes are set to defaults if not provided.
80
80
  def finalize!
81
81
  super
@@ -87,10 +87,10 @@ module VagrantPlugins
87
87
  @password = nil if @password == UNSET_VALUE || @password == ""
88
88
  @join_options = [] if @join_options == UNSET_VALUE
89
89
  @ou_path = nil if @ou_path == UNSET_VALUE
90
- @primary_dns = nil if @primary_dns == UNSET_VALUE
91
- @secondary_dns = nil if @secondary_dns == UNSET_VALUE
90
+ @primary_dns = nil if @primary_dns == UNSET_VALUE || @primary_dns == ""
91
+ @secondary_dns = nil if @secondary_dns == UNSET_VALUE || @secondary_dns == ""
92
92
  @unsecure = false if @unsecure == UNSET_VALUE
93
- @rename = true if @rename == UNSET_VALUE
93
+ @rename = false if @rename == UNSET_VALUE
94
94
  end
95
95
 
96
96
  # Validate configuration and return a hash of errors.
@@ -103,9 +103,13 @@ module VagrantPlugins
103
103
  errors = _detected_errors
104
104
 
105
105
  # Need to supply one of them!
106
- if ( (@username != nil && @password != nil) && @unsecure == true)
106
+ if (@username != nil && @password != nil) && @unsecure == true
107
107
  errors << I18n.t("vagrant_windows_domain.errors.both_credentials_provided")
108
108
  end
109
+
110
+ if @secondary_dns != nil && @primary_dns == nil
111
+ errors << I18n.t("vagrant_windows_domain.errors.invalid_dns_config")
112
+ end
109
113
 
110
114
  { "windows domain provisioner" => errors }
111
115
  end
@@ -14,4 +14,6 @@ en:
14
14
  binary_not_detected: |-
15
15
  "The command '%{binary} required to join/remove the guest machine from the domain '%{domain}' was not found on the guest machine"
16
16
  absolute_module_path: |-
17
- "Absolute 'module_path' not allowed. Please provide a path relative to your Vagrantfile."
17
+ "Absolute 'module_path' not allowed. Please provide a path relative to your Vagrantfile."
18
+ invalid_dns_config: |-
19
+ "Primary dns must be set before configuring Secondary DNS."
@@ -24,10 +24,10 @@ module VagrantPlugins
24
24
  Provisioner
25
25
  end
26
26
 
27
- action_hook(:windows_domain, :machine_action_destroy) do |hook|
28
- require_relative 'action/leave_domain'
29
- hook.prepend(VagrantPlugins::WindowsDomain::LeaveDomain)
30
- end
27
+ # action_hook(:windows_domain, :machine_action_destroy) do |hook|
28
+ # require_relative 'action/leave_domain'
29
+ # hook.prepend(VagrantPlugins::WindowsDomain::LeaveDomain)
30
+ # end
31
31
  end
32
32
  end
33
33
  end
@@ -150,7 +150,7 @@ module VagrantPlugins
150
150
  # This is the method called when destroying a machine that allows
151
151
  # for any state related to the machine created by the provisioner
152
152
  # to be cleaned up.
153
- def destroy
153
+ def cleanup
154
154
  if @config && @config.domain != nil
155
155
  if is_joined_to_domain()
156
156
  set_credentials
@@ -312,7 +312,7 @@ module VagrantPlugins
312
312
  last_type = nil
313
313
  new_line = ""
314
314
  error = false
315
- machine.communicate.sudo("powershell -ExecutionPolicy Bypass -OutputFormat Text -file #{script_path}", opts) do |type, data|
315
+ exit_status = @machine.communicate.sudo("powershell -ExecutionPolicy Bypass -OutputFormat Text -file #{script_path}", opts) do |type, data|
316
316
  if !data.chomp.empty?
317
317
  error = true if type == :stderr
318
318
  if [:stderr, :stdout].include?(type)
@@ -190,6 +190,14 @@ function Remove-ADSIComputer
190
190
  }
191
191
  }
192
192
  }
193
+ try
194
+ {
195
+ Get-NetConnectionProfile -ErrorAction Stop | Set-NetConnectionProfile -NetworkCategory private -ErrorAction Stop
196
+ }
197
+ catch
198
+ {
199
+ Write-host "Network adapters already set to private network type"
200
+ }
193
201
  <% if options[:computer_name] != nil %>
194
202
  $computerName='<%= options[:computer_name] %>'
195
203
  <% else %>
@@ -207,38 +215,34 @@ $credentials = New-Object System.Management.Automation.PSCredential ($username,
207
215
  if (Test-PartOfDomain -computerName $computerName -domain $domain){
208
216
  throw "$computerName already part of domain $domain"
209
217
  } else {
210
- #If a value is provided for the Primary_DNS variable in the vagrantfile, powershell will attempt to determine if the string is a valid IP and will statically set the primary dns server of the vm's nic if it is.
218
+ #If a value is provided for the Primary_DNS and Secondary_DNS variable in the vagrantfile, powershell will determine if the string is a valid IP and will statically set the primary and secondary dns servers of the vm's nic if it is. If only Primary_DNS variable is provided, powershell will statically set the primary dns server of the vm's nic while leaving the secondary unset.
211
219
  <% if options[:primary_dns] != nil %>
220
+ $wmi = Get-WmiObject -ComputerName $env:COMPUTERNAME -Namespace "root\CIMV2" -Class "Win32_NetworkAdapterconfiguration" -Filter 'IPENABLED=TRUE AND Index=2' -Impersonation Impersonate -ErrorAction Stop | Where-Object { $_.DefaultIPGateway }
221
+ # $currdns = $wmi.DNSServerSearchOrder
212
222
  $prim = '<%= options[:primary_dns] %>'
213
- If ($prim -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
214
- {
215
- $wmi = Get-WmiObject -ComputerName $env:COMPUTERNAME -Namespace "root\CIMV2" -Class "Win32_NetworkAdapterconfiguration" -Filter 'IPENABLED=TRUE' -Impersonation Impersonate -ErrorAction Stop | Where-Object { $_.DefaultIPGateway }
216
- $currdns = $wmi.DNSServerSearchOrder
217
- $wmi.SetDNSServerSearchOrder(@($prim, $currdns[1]))
218
- }
219
- else
220
- {
221
- throw "Invalid IP address provided"
222
- }
223
- <% end %>
224
-
225
- #If a value is provided for the Secondary_DNS variable in the vagrantfile, powershell will attempt to determine if the string is a valid IP and will statically set the secondary dns server of the vm's nic if it is.
226
- <% if options[:secondary_dns] != nil %>
227
- $sec = '<%= options[:secondary_dns] %>'
228
- If ($sec -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
229
- {
230
- $wmi = Get-WmiObject -ComputerName $env:COMPUTERNAME -Namespace "root\CIMV2" -Class "Win32_NetworkAdapterconfiguration" -Filter 'IPENABLED=TRUE' -Impersonation Impersonate -ErrorAction Stop | Where-Object { $_.DefaultIPGateway }
231
- $currdns = $wmi.DNSServerSearchOrder
232
- $wmi.SetDNSServerSearchOrder(@($currdns[0], $sec))
233
- }
234
- else
235
- {
236
- throw "Invalid IP address provided"
237
- }
223
+ # Modified the configuration so that the secondary dns can only be set if the primary dns server has also been set
224
+ <% if options[:secondary_dns] != nil %>
225
+ $sec = '<%= options[:secondary_dns] %>'
226
+ If (($prim -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") -and ($sec -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"))
227
+ {
228
+ $wmi.SetDNSServerSearchOrder(@("$prim", "$sec"))
229
+ }
230
+ else
231
+ {
232
+ throw "Invalid value provided for dns server ip"
233
+ }
234
+ <% else %>
235
+ If ($prim -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
236
+ {
237
+ $wmi.SetDNSServerSearchOrder("$prim")
238
+ }
239
+ else
240
+ {
241
+ throw "Invalid IP address provided"
242
+ }
243
+ <% end %>
238
244
  <% end %>
239
- Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory private
240
- Add-Computer <%= options[:parameters] %> -Verbose -Force -PassThru
241
-
245
+ Add-Computer <%= options[:parameters] %> -Verbose -Force
242
246
  # Rename computer separately: Fixes GH issue #11
243
247
  <% if options[:computer_name] != nil %>
244
248
  $completed = $false
@@ -258,17 +262,26 @@ if (Test-PartOfDomain -computerName $computerName -domain $domain){
258
262
  }
259
263
  }
260
264
  <% end %>
261
-
262
265
  Repair-OpenSSHPasswd
263
266
  }
264
267
  <% else %>
265
- if (!(Test-JoinedToADomain)) {
266
- Throw "$computerName not part of any domain"
268
+ $compobj = Get-ADSIComputer -Identity $computerName -Credential $credentials -DomainName $domain
269
+ if (!(Test-JoinedToADomain) -or !($compobj)) {
270
+ # Throw "$computerName not part of any domain"
271
+ return
267
272
  } else {
268
273
  #When destroying the vagrant machine, the goal is not as much to have the virtual machine disjoin from the domain, but to remove the computer object associated with the
269
274
  #machine so that future runs of vagrant up will succeed (especially when the vagrantfile explicitly defines a computer name. That being the case, the remove-computer
270
275
  #command has been replaced with a custom function which is able to remove the computer object associated with the vagrant machine in active directory.
271
- Remove-ADSIComputer -Identity $env:COMPUTERNAME -DomainName $domain -Credential $credentials -Verbose
276
+ try
277
+ {
278
+ Remove-ADSIComputer -Identity $env:COMPUTERNAME -DomainName $domain -Credential $credentials -Verbose -ErrorAction Stop
272
279
  Repair-OpenSSHPasswd
280
+ }
281
+ catch
282
+ {
283
+ Repair-OpenSSHPasswd
284
+ }
285
+
273
286
  }
274
287
  <% end %>
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module WindowsDomain
3
- VERSION = "1.3.4"
3
+ VERSION = "1.3.5"
4
4
  end
5
5
  end
@@ -195,7 +195,7 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
195
195
  expect(ui).to receive(:info).with("\"Running Windows Domain Provisioner\"")
196
196
  expect(ui).to receive(:info).with("deleted", {:color=>:green, :new_line=>false, :prefix=>false})
197
197
 
198
- subject.destroy
198
+ subject.cleanup
199
199
  end
200
200
 
201
201
  it "should not leave domain plugin not associated with current Vagrantfile" do
@@ -204,7 +204,7 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
204
204
  subject = described_class.new machine, double("env", :domain => nil)
205
205
 
206
206
  expect(ui).to_not receive(:ask)
207
- expect(subject.destroy).to eq(nil)
207
+ expect(subject.cleanup).to eq(nil)
208
208
  end
209
209
 
210
210
  it "should ask for credentials when leaving domain when no credentials were provided" do
@@ -219,7 +219,7 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
219
219
  expect(ui).to receive(:info).with(any_args).twice
220
220
  expect(ui).to receive(:ask).with("Please enter your domain password (output will be hidden): ", {:echo=>false}).and_return("myusername")
221
221
  expect(ui).to receive(:ask).with("Please enter your domain username: ")
222
- subject.destroy
222
+ subject.cleanup
223
223
  end
224
224
 
225
225
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["matt.fellows@onegeek.com.au"]
11
11
  spec.summary = "Windows Domain Provisioner for Vagrant"
12
12
  spec.description = "Adds and Removes Windows Guests from a Windows Domain, as part of the standard machine lifecycle."
13
- spec.homepage = "https://github.com/SEEK-Jobs/vagrant-windows-domain"
13
+ spec.homepage = "https://github.com/mefellows/vagrant-windows-domain"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-windows-domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Fellows
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-17 00:00:00.000000000 Z
11
+ date: 2021-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -133,11 +133,10 @@ files:
133
133
  - lib/vagrant-windows-domain/version.rb
134
134
  - spec/base.rb
135
135
  - spec/provisioner/config_spec.rb
136
- - spec/provisioner/leave_domain_spec.rb
137
136
  - spec/provisioner/provisioner_spec.rb
138
137
  - spec/spec_helper.rb
139
138
  - vagrant-windows-domain.gemspec
140
- homepage: https://github.com/SEEK-Jobs/vagrant-windows-domain
139
+ homepage: https://github.com/mefellows/vagrant-windows-domain
141
140
  licenses:
142
141
  - MIT
143
142
  metadata: {}
@@ -156,14 +155,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
155
  - !ruby/object:Gem::Version
157
156
  version: '0'
158
157
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 2.7.7
158
+ rubygems_version: 3.0.3
161
159
  signing_key:
162
160
  specification_version: 4
163
161
  summary: Windows Domain Provisioner for Vagrant
164
162
  test_files:
165
163
  - spec/base.rb
166
164
  - spec/provisioner/config_spec.rb
167
- - spec/provisioner/leave_domain_spec.rb
168
165
  - spec/provisioner/provisioner_spec.rb
169
166
  - spec/spec_helper.rb
@@ -1,131 +0,0 @@
1
- require 'spec_helper'
2
- require 'vagrant-windows-domain/provisioner'
3
- require 'vagrant-windows-domain/action/leave_domain'
4
- require 'vagrant-windows-domain/config'
5
- require 'base'
6
-
7
- describe VagrantPlugins::WindowsDomain::LeaveDomain do
8
-
9
- include_context "unit"
10
- let(:instance) { described_class.new }
11
-
12
- let(:root_path) { (Pathname.new(Dir.mktmpdir)).to_s }
13
- let(:domain) { "foo.com" }
14
- let(:ui) { double("ui") }
15
- let(:app) { double("app") }
16
- let(:communicator) { double ("communicator") }
17
- let(:shell) { double ("shell") }
18
- let(:powershell) { double ("powershell") }
19
- let(:guest) { double ("guest") }
20
- let(:configuration_file) { "manifests/MyWebsite.ps1" }
21
- let(:module_path) { ["foo/modules", "foo/modules2"] }
22
- let(:config) { VagrantPlugins::WindowsDomain::Config.new }
23
- let(:vm) { double("vm", provisioners: [double("prov", config: config)]) }
24
- let(:root_config) { double("root_config", vm: vm) }
25
- let(:env) { {:ui => ui, :machine => machine} }
26
- let(:machine) { double("machine", ui: ui, id: "1234", config: root_config) }
27
- let(:provisioner) { double("provisioner") }
28
- subject { described_class.new app, env }
29
-
30
- describe "call" do
31
-
32
- before do
33
- allow(machine).to receive(:communicate).and_return(communicator)
34
- allow(env).to receive(:machine).and_return(machine)
35
- allow(communicator).to receive(:shell).and_return(shell)
36
- allow(shell).to receive(:powershell).and_yield(:stdout, "myoldcomputername")
37
- config.domain = domain
38
- allow(env).to receive(:machine).and_return(machine)
39
- allow(machine).to receive(:env).and_return(env)
40
- allow(env).to receive(:ui).and_return(ui)
41
- subject.provisioner = provisioner
42
- end
43
-
44
- context "when no configuration exists for the machine" do
45
- it "should pass control to the next middleware Action" do
46
- config.domain = nil
47
- expect(app).to receive(:call).with(env)
48
- subject.call(env)
49
- end
50
- end
51
-
52
- context "when machine is running" do
53
- it "should prompt the user if they would like to destroy & d/c the machine" do
54
- state = double("state", id: :running)
55
- expect(provisioner).to receive(:destroy)
56
-
57
- expect(app).to receive(:call).with(env)
58
- expect(ui).to receive(:ask).with("Are you sure you want to destroy this machine and disconnect from #{domain}? (y/n)").and_return("y")
59
- expect(machine).to receive(:state).and_return(state).twice
60
- subject.call(env)
61
-
62
- end
63
-
64
- it "should not continue if the user declines to destroy the machine" do
65
- state = double("state", id: :running)
66
- expect(provisioner).to_not receive(:destroy)
67
-
68
- expect(ui).to receive(:ask).with("Are you sure you want to destroy this machine and disconnect from #{domain}? (y/n)").and_return("n")
69
- expect(machine).to receive(:state).and_return(state).twice
70
- expect(app).to_not receive(:call).with(env)
71
- subject.call(env)
72
- end
73
- end
74
-
75
- context "when machine is :paused, :saved or :poweroff" do
76
- it "should prompt the user if they would like to force destroy the machine" do
77
- state = double("state", id: :poweroff)
78
- provisioner = double("provisioner")
79
- subject.provisioner = provisioner
80
-
81
- expect(ui).to receive(:say).with(:warn, "Machine is currently not running. To properly leave the #{domain} network the machine needs to be running and connected to the network in which it was provisioned. Please run `vagrant up` and then `vagrant destroy`.\n")
82
- expect(ui).to receive(:ask).with("Would you like to continue destroying this machine, leaving this machine orphaned in the '#{domain}' network? If so, type 'destroy'").and_return("destroy")
83
- expect(ui).to receive(:say).with(:warn, "Force destroying this machine and not leaving the domain foo.com. May FSM have mercy on your soul.")
84
- expect(machine).to receive(:state).and_return(state).twice
85
- expect(app).to receive(:call).with(env)
86
- # Can't call destroy on a non-running machine
87
- expect(provisioner).to_not receive(:destroy)
88
-
89
- subject.call(env)
90
-
91
- expect(env[:force_confirm_destroy]).to be(true)
92
- end
93
-
94
- it "should not pass on to middleware if user declines force destroy" do
95
- state = double("state", id: :poweroff)
96
- provisioner = double("provisioner")
97
- subject.provisioner = provisioner
98
-
99
- expect(ui).to receive(:say).with(:warn, "Machine is currently not running. To properly leave the #{domain} network the machine needs to be running and connected to the network in which it was provisioned. Please run `vagrant up` and then `vagrant destroy`.\n")
100
- expect(ui).to receive(:ask).with("Would you like to continue destroying this machine, leaving this machine orphaned in the '#{domain}' network? If so, type 'destroy'").and_return("n")
101
- expect(machine).to receive(:state).and_return(state).twice
102
- expect(app).to_not receive(:call).with(env)
103
- expect(provisioner).to_not receive(:destroy)
104
- expect(env[:force_confirm_destroy]).to be(nil)
105
-
106
- subject.call(env)
107
- end
108
- end
109
-
110
- context "when machine is :not_created" do
111
- it "should pass control to the next middleware action" do
112
- state = double("state", id: :not_created)
113
- expect(machine).to receive(:state).and_return(state)
114
-
115
- expect(app).to receive(:call).with(env)
116
- subject.call(env)
117
- end
118
- end
119
- end
120
-
121
-
122
- describe "initialize" do
123
-
124
- its("env") { should eq(env) }
125
- its("app") { should eq(app) }
126
- its("config") { should eq(config) }
127
- its("machine") { should eq(machine) }
128
-
129
- end
130
-
131
- end