mirror of https://github.com/docker/docs.git
FIX #2232 Check that the user is an Administrator
Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
parent
d5e11fb961
commit
6a5cc751bb
|
|
@ -124,15 +124,24 @@ func (d *Driver) GetState() (state.State, error) {
|
||||||
|
|
||||||
// PreCreateCheck checks that the machine creation process can be started safely.
|
// PreCreateCheck checks that the machine creation process can be started safely.
|
||||||
func (d *Driver) PreCreateCheck() error {
|
func (d *Driver) PreCreateCheck() error {
|
||||||
|
// Check that hyperv is installed
|
||||||
if err := hypervAvailable(); err != nil {
|
if err := hypervAvailable(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that there is a virtual switch already configured
|
// Check that the user is an Administrator
|
||||||
_, err := d.chooseVirtualSwitch()
|
isAdmin, err := isAdministrator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if !isAdmin {
|
||||||
|
return ErrNotAdministrator
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that there is a virtual switch already configured
|
||||||
|
if _, err := d.chooseVirtualSwitch(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Downloading boot2docker to cache should be done here to make sure
|
// Downloading boot2docker to cache should be done here to make sure
|
||||||
// that a download failure will not leave a machine half created.
|
// that a download failure will not leave a machine half created.
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package hyperv
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -14,6 +14,11 @@ import (
|
||||||
|
|
||||||
var powershell string
|
var powershell string
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNotAdministrator = errors.New("Hyper-v commands have to be run as an Administrator")
|
||||||
|
ErrNotInstalled = errors.New("Hyper-V PowerShell Module is not available")
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
systemPath := strings.Split(os.Getenv("PATH"), ";")
|
systemPath := strings.Split(os.Getenv("PATH"), ";")
|
||||||
for _, path := range systemPath {
|
for _, path := range systemPath {
|
||||||
|
|
@ -61,8 +66,18 @@ func hypervAvailable() error {
|
||||||
|
|
||||||
resp := parseLines(stdout)
|
resp := parseLines(stdout)
|
||||||
if resp[0] != "Hyper-V" {
|
if resp[0] != "Hyper-V" {
|
||||||
return fmt.Errorf("Hyper-V PowerShell Module is not available")
|
return ErrNotInstalled
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isAdministrator() (bool, error) {
|
||||||
|
stdout, err := cmdOut(`@([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")`)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := parseLines(stdout)
|
||||||
|
return resp[0] == "True", nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue