diff --git a/clients/imageClient/entities.go b/clients/imageClient/entities.go index 8bd8ba92e7c6..6af657522d5b 100644 --- a/clients/imageClient/entities.go +++ b/clients/imageClient/entities.go @@ -5,18 +5,18 @@ import ( ) type ImageList struct { - XMLName xml.Name `xml:"Images"` - Xmlns string `xml:"xmlns,attr"` - OSImages []OSImage `xml:"OSImage"` + XMLName xml.Name `xml:"Images"` + Xmlns string `xml:"xmlns,attr"` + OSImages []OSImage `xml:"OSImage"` } type OSImage struct { - Category string - Label string - LogicalSizeInGB string - Name string - OS string - Eula string - Description string - Location string + Category string + Label string + LogicalSizeInGB string + Name string + OS string + Eula string + Description string + Location string } diff --git a/clients/imageClient/imageClient.go b/clients/imageClient/imageClient.go index 3d9245f65043..036831e5d3ef 100644 --- a/clients/imageClient/imageClient.go +++ b/clients/imageClient/imageClient.go @@ -1,18 +1,18 @@ package imageClient import ( - "fmt" "encoding/xml" "errors" + "fmt" azure "github.com/MSOpenTech/azure-sdk-for-go" ) const ( - azureImageListURL = "services/images" + azureImageListURL = "services/images" invalidLocationError = "Error: Can not find image %s in specified subscription, please specify another image name \n" ) -func GetImageList() (ImageList, error){ +func GetImageList() (ImageList, error) { imageList := ImageList{} response, err := azure.SendAzureGetRequest(azureImageListURL) @@ -24,11 +24,11 @@ func GetImageList() (ImageList, error){ return imageList, err } -func ResolveImageName(imageName string) (error) { +func ResolveImageName(imageName string) error { if len(imageName) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "imageName") } - + imageList, err := GetImageList() if err != nil { return err diff --git a/clients/locationClient/entities.go b/clients/locationClient/entities.go index 9c42928f089e..7571726f6630 100644 --- a/clients/locationClient/entities.go +++ b/clients/locationClient/entities.go @@ -5,13 +5,13 @@ import ( ) type LocationList struct { - XMLName xml.Name `xml:"Locations"` - Xmlns string `xml:"xmlns,attr"` - Locations []Location `xml:"Location"` + XMLName xml.Name `xml:"Locations"` + Xmlns string `xml:"xmlns,attr"` + Locations []Location `xml:"Location"` } type Location struct { - Name string - DisplayName string - AvailableServices []string `xml:"AvailableServices>AvailableService"` + Name string + DisplayName string + AvailableServices []string `xml:"AvailableServices>AvailableService"` } diff --git a/clients/locationClient/locationClient.go b/clients/locationClient/locationClient.go index 194e604bae34..f123c2e5da3b 100644 --- a/clients/locationClient/locationClient.go +++ b/clients/locationClient/locationClient.go @@ -1,12 +1,12 @@ package locationClient import ( - "fmt" - "strings" + "bytes" "encoding/xml" "errors" - "bytes" + "fmt" azure "github.com/MSOpenTech/azure-sdk-for-go" + "strings" ) const ( @@ -14,11 +14,11 @@ const ( invalidLocationError = "Invalid location. Available locations: %s" ) -func ResolveLocation(location string) (error) { +func ResolveLocation(location string) error { if len(location) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "location") } - + locations, err := GetLocationList() if err != nil { return err diff --git a/clients/storageServiceClient/entities.go b/clients/storageServiceClient/entities.go index 290760820aa4..4b703e3a0671 100644 --- a/clients/storageServiceClient/entities.go +++ b/clients/storageServiceClient/entities.go @@ -5,45 +5,45 @@ import ( ) type StorageServiceList struct { - XMLName xml.Name `xml:"StorageServices"` - Xmlns string `xml:"xmlns,attr"` + XMLName xml.Name `xml:"StorageServices"` + Xmlns string `xml:"xmlns,attr"` StorageServices []StorageService `xml:"StorageService"` } type StorageService struct { - Url string - ServiceName string - StorageServiceProperties StorageServiceProperties + Url string + ServiceName string + StorageServiceProperties StorageServiceProperties } type StorageServiceProperties struct { - Description string - Location string - Label string - Status string - Endpoints []string `xml:"Endpoints>Endpoint"` - GeoReplicationEnabled string - GeoPrimaryRegion string + Description string + Location string + Label string + Status string + Endpoints []string `xml:"Endpoints>Endpoint"` + GeoReplicationEnabled string + GeoPrimaryRegion string } type StorageServiceDeployment struct { - XMLName xml.Name `xml:"CreateStorageServiceInput"` - Xmlns string `xml:"xmlns,attr"` - ServiceName string - Description string - Label string - AffinityGroup string `xml:",omitempty"` - Location string `xml:",omitempty"` - GeoReplicationEnabled bool - ExtendedProperties ExtendedPropertyList - SecondaryReadEnabled bool + XMLName xml.Name `xml:"CreateStorageServiceInput"` + Xmlns string `xml:"xmlns,attr"` + ServiceName string + Description string + Label string + AffinityGroup string `xml:",omitempty"` + Location string `xml:",omitempty"` + GeoReplicationEnabled bool + ExtendedProperties ExtendedPropertyList + SecondaryReadEnabled bool } type ExtendedPropertyList struct { - ExtendedProperty []ExtendedProperty + ExtendedProperty []ExtendedProperty } type ExtendedProperty struct { - Name string - Value string + Name string + Value string } diff --git a/clients/storageServiceClient/storageServiceClient.go b/clients/storageServiceClient/storageServiceClient.go index a5428b4b3a5d..29b4123978ff 100644 --- a/clients/storageServiceClient/storageServiceClient.go +++ b/clients/storageServiceClient/storageServiceClient.go @@ -1,23 +1,23 @@ package storageServiceClient import ( - "fmt" - "strings" - "errors" - "encoding/xml" "encoding/base64" + "encoding/xml" + "errors" + "fmt" azure "github.com/MSOpenTech/azure-sdk-for-go" + "strings" ) const ( - azureXmlns = "http://schemas.microsoft.com/windowsazure" + azureXmlns = "http://schemas.microsoft.com/windowsazure" azureStorageServiceListURL = "services/storageservices" - azureStorageServiceURL = "services/storageservices/%s" + azureStorageServiceURL = "services/storageservices/%s" blobEndpointNotFoundError = "Blob endpoint was not found in storage serice %s" ) -func GetStorageServiceList() (*StorageServiceList, error){ +func GetStorageServiceList() (*StorageServiceList, error) { storageServiceList := new(StorageServiceList) response, err := azure.SendAzureGetRequest(azureStorageServiceListURL) @@ -33,11 +33,11 @@ func GetStorageServiceList() (*StorageServiceList, error){ return storageServiceList, nil } -func GetStorageServiceByName(serviceName string) (*StorageService, error){ +func GetStorageServiceByName(serviceName string) (*StorageService, error) { if len(serviceName) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "serviceName") } - + storageService := new(StorageService) requestURL := fmt.Sprintf(azureStorageServiceURL, serviceName) response, err := azure.SendAzureGetRequest(requestURL) @@ -57,7 +57,7 @@ func GetStorageServiceByLocation(location string) (*StorageService, error) { if len(location) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "location") } - + storageService := new(StorageService) storageServiceList, err := GetStorageServiceList() if err != nil { @@ -75,14 +75,14 @@ func GetStorageServiceByLocation(location string) (*StorageService, error) { return nil, nil } -func CreateStorageService(name, location string) (*StorageService, error){ +func CreateStorageService(name, location string) (*StorageService, error) { if len(name) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "name") } if len(location) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "location") } - + storageDeploymentConfig := createStorageServiceDeploymentConf(name, location) deploymentBytes, err := xml.Marshal(storageDeploymentConfig) if err != nil { @@ -115,7 +115,7 @@ func GetBlobEndpoint(storageService *StorageService) (string, error) { return "", errors.New(fmt.Sprintf(blobEndpointNotFoundError, storageService.ServiceName)) } -func createStorageServiceDeploymentConf(name, location string) (StorageServiceDeployment){ +func createStorageServiceDeploymentConf(name, location string) StorageServiceDeployment { storageServiceDeployment := StorageServiceDeployment{} storageServiceDeployment.ServiceName = name diff --git a/clients/vmClient/entities.go b/clients/vmClient/entities.go index 432f83c10310..a0f01ea85122 100644 --- a/clients/vmClient/entities.go +++ b/clients/vmClient/entities.go @@ -5,52 +5,52 @@ import ( ) type VMDeployment struct { - XMLName xml.Name `xml:"Deployment"` - Xmlns string `xml:"xmlns,attr"` - Name string - DeploymentSlot string - Status string `xml:",omitempty"` - Label string - Url string `xml:",omitempty"` - RoleList RoleList - RoleInstanceList RoleInstanceList `xml:",omitempty"` + XMLName xml.Name `xml:"Deployment"` + Xmlns string `xml:"xmlns,attr"` + Name string + DeploymentSlot string + Status string `xml:",omitempty"` + Label string + Url string `xml:",omitempty"` + RoleList RoleList + RoleInstanceList RoleInstanceList `xml:",omitempty"` } type HostedServiceDeployment struct { - XMLName xml.Name `xml:"CreateHostedService"` - Xmlns string `xml:"xmlns,attr"` - ServiceName string - Label string - Description string - Location string + XMLName xml.Name `xml:"CreateHostedService"` + Xmlns string `xml:"xmlns,attr"` + ServiceName string + Label string + Description string + Location string } type RoleList struct { - Role []*Role + Role []*Role } type RoleInstanceList struct { - RoleInstance []*RoleInstance + RoleInstance []*RoleInstance } type RoleInstance struct { - RoleName string - InstanceName string - InstanceStatus string - InstanceSize string - PowerState string + RoleName string + InstanceName string + InstanceStatus string + InstanceSize string + PowerState string } type Role struct { - RoleName string - RoleType string - ConfigurationSets ConfigurationSets + RoleName string + RoleType string + ConfigurationSets ConfigurationSets ResourceExtensionReferences ResourceExtensionReferences `xml:",omitempty"` - OSVirtualHardDisk OSVirtualHardDisk - RoleSize string - ProvisionGuestAgent bool - UseCertAuth bool `xml:"-"` - CertPath string `xml:"-"` + OSVirtualHardDisk OSVirtualHardDisk + RoleSize string + ProvisionGuestAgent bool + UseCertAuth bool `xml:"-"` + CertPath string `xml:"-"` } type ConfigurationSets struct { @@ -58,7 +58,7 @@ type ConfigurationSets struct { } type ResourceExtensionReferences struct { - ResourceExtensionReference []ResourceExtensionReference + ResourceExtensionReference []ResourceExtensionReference } type InputEndpoints struct { @@ -70,41 +70,41 @@ type SubnetNames struct { } type ResourceExtensionReference struct { - ReferenceName string - Publisher string - Name string - Version string - ResourceExtensionParameterValues ResourceExtensionParameterValues `xml:",omitempty"` - State string + ReferenceName string + Publisher string + Name string + Version string + ResourceExtensionParameterValues ResourceExtensionParameterValues `xml:",omitempty"` + State string } type ResourceExtensionParameterValues struct { - ResourceExtensionParameterValue []ResourceExtensionParameter + ResourceExtensionParameterValue []ResourceExtensionParameter } type ResourceExtensionParameter struct { - Key string - Value string - Type string + Key string + Value string + Type string } type OSVirtualHardDisk struct { - MediaLink string - SourceImageName string - HostCaching string `xml:",omitempty"` - DiskName string `xml:",omitempty"` - OS string `xml:",omitempty"` + MediaLink string + SourceImageName string + HostCaching string `xml:",omitempty"` + DiskName string `xml:",omitempty"` + OS string `xml:",omitempty"` } type ConfigurationSet struct { - ConfigurationSetType string - HostName string `xml:",omitempty"` - UserName string `xml:",omitempty"` - UserPassword string `xml:",omitempty"` - DisableSshPasswordAuthentication bool - InputEndpoints InputEndpoints `xml:",omitempty"` - SubnetNames SubnetNames `xml:",omitempty"` - SSH SSH `xml:",omitempty"` + ConfigurationSetType string + HostName string `xml:",omitempty"` + UserName string `xml:",omitempty"` + UserPassword string `xml:",omitempty"` + DisableSshPasswordAuthentication bool + InputEndpoints InputEndpoints `xml:",omitempty"` + SubnetNames SubnetNames `xml:",omitempty"` + SSH SSH `xml:",omitempty"` } type SSH struct { @@ -116,16 +116,16 @@ type PublicKeyList struct { } type PublicKey struct { - Fingerprint string - Path string + Fingerprint string + Path string } type InputEndpoint struct { - LocalPort int - Name string - Port int - Protocol string - Vip string + LocalPort int + Name string + Port int + Protocol string + Vip string } //!TODO @@ -133,30 +133,30 @@ type SubnetName struct { } type ServiceCertificate struct { - XMLName xml.Name `xml:"CertificateFile"` - Xmlns string `xml:"xmlns,attr"` - Data string - CertificateFormat string - Password string `xml:",omitempty"` + XMLName xml.Name `xml:"CertificateFile"` + Xmlns string `xml:"xmlns,attr"` + Data string + CertificateFormat string + Password string `xml:",omitempty"` } type StartRoleOperation struct { - Xmlns string `xml:"xmlns,attr"` - OperationType string + Xmlns string `xml:"xmlns,attr"` + OperationType string } type ShutdownRoleOperation struct { - Xmlns string `xml:"xmlns,attr"` - OperationType string + Xmlns string `xml:"xmlns,attr"` + OperationType string } type RestartRoleOperation struct { - Xmlns string `xml:"xmlns,attr"` - OperationType string + Xmlns string `xml:"xmlns,attr"` + OperationType string } type AvailabilityResponse struct { - Xmlns string `xml:"xmlns,attr"` - Result bool - Reason string + Xmlns string `xml:"xmlns,attr"` + Result bool + Reason string } diff --git a/clients/vmClient/vmClient.go b/clients/vmClient/vmClient.go index 3e1366d67d73..c52c87012e7e 100644 --- a/clients/vmClient/vmClient.go +++ b/clients/vmClient/vmClient.go @@ -1,49 +1,49 @@ package vmClient import ( - "fmt" - "time" - "encoding/xml" - "encoding/base64" - "encoding/pem" - "os" - "io/ioutil" "crypto/rand" "crypto/sha1" - "io" + "encoding/base64" + "encoding/pem" + "encoding/xml" "errors" - "strings" - "os/user" - "path" - "github.com/MSOpenTech/azure-sdk-for-go/clients/locationClient" + "fmt" + azure "github.com/MSOpenTech/azure-sdk-for-go" "github.com/MSOpenTech/azure-sdk-for-go/clients/imageClient" + "github.com/MSOpenTech/azure-sdk-for-go/clients/locationClient" "github.com/MSOpenTech/azure-sdk-for-go/clients/storageServiceClient" "github.com/MSOpenTech/azure-sdk-for-go/clients/vmDiskClient" - azure "github.com/MSOpenTech/azure-sdk-for-go" + "io" + "io/ioutil" + "os" + "os/user" + "path" + "strings" + "time" ) const ( - azureXmlns = "http://schemas.microsoft.com/windowsazure" - azureDeploymentListURL = "services/hostedservices/%s/deployments" - azureHostedServiceListURL = "services/hostedservices" - azureHostedServiceURL = "services/hostedservices/%s" + azureXmlns = "http://schemas.microsoft.com/windowsazure" + azureDeploymentListURL = "services/hostedservices/%s/deployments" + azureHostedServiceListURL = "services/hostedservices" + azureHostedServiceURL = "services/hostedservices/%s" azureHostedServiceAvailabilityURL = "services/hostedservices/operations/isavailable/%s" - azureDeploymentURL = "services/hostedservices/%s/deployments/%s" - azureRoleURL = "services/hostedservices/%s/deployments/%s/roles/%s" - azureOperationsURL = "services/hostedservices/%s/deployments/%s/roleinstances/%s/Operations" - azureCertificatListURL = "services/hostedservices/%s/certificates" + azureDeploymentURL = "services/hostedservices/%s/deployments/%s" + azureRoleURL = "services/hostedservices/%s/deployments/%s/roles/%s" + azureOperationsURL = "services/hostedservices/%s/deployments/%s/roleinstances/%s/Operations" + azureCertificatListURL = "services/hostedservices/%s/certificates" - osLinux = "Linux" + osLinux = "Linux" osWindows = "Windows" - dockerPublicConfig = "{ \"dockerport\": \"%v\" }" - dockerPrivateConfig = "{ \"ca\": \"%s\", \"server-cert\": \"%s\", \"server-key\": \"%s\" }" + dockerPublicConfig = "{ \"dockerport\": \"%v\" }" + dockerPrivateConfig = "{ \"ca\": \"%s\", \"server-cert\": \"%s\", \"server-key\": \"%s\" }" dockerDirExistsMessage = "Docker directory exists" - missingDockerCertsError = "Can not find docker certificates folder %s. You should generate docker certificates first. Info can be found here: https://docs.docker.com/articles/https/" + missingDockerCertsError = "Can not find docker certificates folder %s. You should generate docker certificates first. Info can be found here: https://docs.docker.com/articles/https/" provisioningConfDoesNotExistsError = "You should set azure VM provisioning config first" - invalidCertExtensionError = "Certificate %s is invalid. Please specify %s certificate." - invalidOSError = "You must specify correct OS param. Valid values are 'Linux' and 'Windows'" + invalidCertExtensionError = "Certificate %s is invalid. Please specify %s certificate." + invalidOSError = "You must specify correct OS param. Valid values are 'Linux' and 'Windows'" ) //Region public methods starts @@ -55,7 +55,7 @@ func CreateAzureVM(role *Role, dnsName, location string) error { if len(location) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "location") } - + fmt.Println("Creating hosted service... ") requestId, err := CreateHostedService(dnsName, location) if err != nil { @@ -81,7 +81,7 @@ func CreateAzureVM(role *Role, dnsName, location string) error { return err } - requestURL := fmt.Sprintf(azureDeploymentListURL, role.RoleName) + requestURL := fmt.Sprintf(azureDeploymentListURL, role.RoleName) requestId, err = azure.SendAzurePostRequest(requestURL, vMDeploymentBytes) if err != nil { return err @@ -99,7 +99,7 @@ func CreateHostedService(dnsName, location string) (string, error) { if len(location) == 0 { return "", fmt.Errorf(azure.ParamNotSpecifiedError, "location") } - + result, reason, err := CheckHostedServiceNameAvailability(dnsName) if err != nil { return "", err @@ -107,7 +107,7 @@ func CreateHostedService(dnsName, location string) (string, error) { if !result { return "", fmt.Errorf("%s Hosted service name: %s", reason, dnsName) } - + err = locationClient.ResolveLocation(location) if err != nil { return "", err @@ -132,19 +132,19 @@ func CheckHostedServiceNameAvailability(dnsName string) (bool, string, error) { if len(dnsName) == 0 { return false, "", fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName") } - + requestURL := fmt.Sprintf(azureHostedServiceAvailabilityURL, dnsName) response, err := azure.SendAzureGetRequest(requestURL) if err != nil { return false, "", err } - + availabilityResponse := new(AvailabilityResponse) err = xml.Unmarshal(response, availabilityResponse) if err != nil { return false, "", err } - + return availabilityResponse.Result, availabilityResponse.Reason, nil } @@ -152,7 +152,7 @@ func DeleteHostedService(dnsName string) error { if len(dnsName) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName") } - + requestURL := fmt.Sprintf(azureHostedServiceURL, dnsName) requestId, err := azure.SendAzureDeleteRequest(requestURL) if err != nil { @@ -176,7 +176,7 @@ func CreateAzureVMConfiguration(name, instanceSize, imageName, location string) if len(location) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "location") } - + fmt.Println("Creating azure VM configuration... ") err := locationClient.ResolveLocation(location) @@ -199,7 +199,7 @@ func AddAzureLinuxProvisioningConfig(azureVMConfig *Role, userName, password, ce if len(password) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "password") } - + fmt.Println("Adding azure provisioning configuration... ") configurationSets := ConfigurationSets{} @@ -241,7 +241,7 @@ func SetAzureVMExtension(azureVMConfiguration *Role, name string, publisher stri if len(referenceName) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "referenceName") } - + fmt.Printf("Setting azure VM extension: %s... \n", name) extension := ResourceExtensionReference{} @@ -278,7 +278,7 @@ func SetAzureDockerVMExtension(azureVMConfiguration *Role, dockerCertDir string, if len(dockerCertDir) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "dockerCertDir") } - + if len(version) == 0 { version = "0.3" } @@ -305,7 +305,7 @@ func GetVMDeployment(cloudserviceName, deploymentName string) (*VMDeployment, er if len(deploymentName) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName") } - + deployment := new(VMDeployment) requestURL := fmt.Sprintf(azureDeploymentURL, cloudserviceName, deploymentName) @@ -329,26 +329,26 @@ func DeleteVMDeployment(cloudserviceName, deploymentName string) error { if len(deploymentName) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName") } - + vmDeployment, err := GetVMDeployment(cloudserviceName, deploymentName) if err != nil { return err } vmDiskName := vmDeployment.RoleList.Role[0].OSVirtualHardDisk.DiskName - - requestURL := fmt.Sprintf(azureDeploymentURL, cloudserviceName, deploymentName) + + requestURL := fmt.Sprintf(azureDeploymentURL, cloudserviceName, deploymentName) requestId, err := azure.SendAzureDeleteRequest(requestURL) if err != nil { return err } azure.WaitAsyncOperation(requestId) - + err = vmDiskClient.DeleteDisk(vmDiskName) if err != nil { return err } - + return nil } @@ -362,10 +362,10 @@ func GetRole(cloudserviceName, deploymentName, roleName string) (*Role, error) { if len(roleName) == 0 { return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "roleName") } - + role := new(Role) - requestURL := fmt.Sprintf(azureRoleURL, cloudserviceName, deploymentName, roleName) + requestURL := fmt.Sprintf(azureRoleURL, cloudserviceName, deploymentName, roleName) response, azureErr := azure.SendAzureGetRequest(requestURL) if azureErr != nil { return nil, azureErr @@ -389,7 +389,7 @@ func StartRole(cloudserviceName, deploymentName, roleName string) error { if len(roleName) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName") } - + startRoleOperation := createStartRoleOperation() startRoleOperationBytes, err := xml.Marshal(startRoleOperation) @@ -417,7 +417,7 @@ func ShutdownRole(cloudserviceName, deploymentName, roleName string) error { if len(roleName) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName") } - + shutdownRoleOperation := createShutdowRoleOperation() shutdownRoleOperationBytes, err := xml.Marshal(shutdownRoleOperation) @@ -445,7 +445,7 @@ func RestartRole(cloudserviceName, deploymentName, roleName string) error { if len(roleName) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName") } - + restartRoleOperation := createRestartRoleOperation() restartRoleOperationBytes, err := xml.Marshal(restartRoleOperation) @@ -453,7 +453,7 @@ func RestartRole(cloudserviceName, deploymentName, roleName string) error { return err } - requestURL := fmt.Sprintf(azureOperationsURL, cloudserviceName, deploymentName, roleName) + requestURL := fmt.Sprintf(azureOperationsURL, cloudserviceName, deploymentName, roleName) requestId, azureErr := azure.SendAzurePostRequest(requestURL, restartRoleOperationBytes) if azureErr != nil { return azureErr @@ -473,8 +473,8 @@ func DeleteRole(cloudserviceName, deploymentName, roleName string) error { if len(roleName) == 0 { return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName") } - - requestURL := fmt.Sprintf(azureRoleURL, cloudserviceName, deploymentName, roleName) + + requestURL := fmt.Sprintf(azureRoleURL, cloudserviceName, deploymentName, roleName) requestId, azureErr := azure.SendAzureDeleteRequest(requestURL) if azureErr != nil { return azureErr @@ -486,7 +486,6 @@ func DeleteRole(cloudserviceName, deploymentName, roleName string) error { //Region public methods ends - //Region private methods starts func createStartRoleOperation() StartRoleOperation { @@ -513,7 +512,7 @@ func createRestartRoleOperation() RestartRoleOperation { return startRoleOperation } -func createDockerPublicConfig(dockerPort int) string{ +func createDockerPublicConfig(dockerPort int) string { config := fmt.Sprintf(dockerPublicConfig, dockerPort) return config } @@ -562,7 +561,7 @@ func parseFileToBase64String(path string) (string, error) { return base64Content, nil } -func addDockerPort(configurationSets []ConfigurationSet, dockerPort int) error { +func addDockerPort(configurationSets []ConfigurationSet, dockerPort int) error { if len(configurationSets) == 0 { return errors.New(provisioningConfDoesNotExistsError) } @@ -579,7 +578,7 @@ func addDockerPort(configurationSets []ConfigurationSet, dockerPort int) error return nil } -func createHostedServiceDeploymentConfig(dnsName, location string) (HostedServiceDeployment) { +func createHostedServiceDeploymentConfig(dnsName, location string) HostedServiceDeployment { deployment := HostedServiceDeployment{} deployment.ServiceName = dnsName label := base64.StdEncoding.EncodeToString([]byte(dnsName)) @@ -590,7 +589,7 @@ func createHostedServiceDeploymentConfig(dnsName, location string) (HostedServic return deployment } -func createVMDeploymentConfig(role *Role) (VMDeployment) { +func createVMDeploymentConfig(role *Role) VMDeployment { deployment := VMDeployment{} deployment.Name = role.RoleName deployment.Xmlns = azureXmlns @@ -601,7 +600,7 @@ func createVMDeploymentConfig(role *Role) (VMDeployment) { return deployment } -func createAzureVMRole(name, instanceSize, imageName, location string) (*Role, error){ +func createAzureVMRole(name, instanceSize, imageName, location string) (*Role, error) { config := new(Role) config.RoleName = name config.RoleSize = instanceSize @@ -616,7 +615,7 @@ func createAzureVMRole(name, instanceSize, imageName, location string) (*Role, e return config, nil } -func createOSVirtualHardDisk(dnsName, imageName, location string) (OSVirtualHardDisk, error){ +func createOSVirtualHardDisk(dnsName, imageName, location string) (OSVirtualHardDisk, error) { oSVirtualHardDisk := OSVirtualHardDisk{} err := imageClient.ResolveImageName(imageName) @@ -633,7 +632,7 @@ func createOSVirtualHardDisk(dnsName, imageName, location string) (OSVirtualHard return oSVirtualHardDisk, nil } -func getVHDMediaLink(dnsName, location string) (string, error){ +func getVHDMediaLink(dnsName, location string) (string, error) { storageService, err := storageServiceClient.GetStorageServiceByLocation(location) if err != nil { @@ -706,7 +705,7 @@ func createLinuxProvisioningConfig(dnsName, userName, userPassword, certPath str return provisioningConfig, nil } -func uploadServiceCert(dnsName, certPath string) (error) { +func uploadServiceCert(dnsName, certPath string) error { certificateConfig, err := createServiceCertDeploymentConf(certPath) if err != nil { return err @@ -717,7 +716,7 @@ func uploadServiceCert(dnsName, certPath string) (error) { return err } - requestURL := fmt.Sprintf(azureCertificatListURL, dnsName) + requestURL := fmt.Sprintf(azureCertificatListURL, dnsName) requestId, azureErr := azure.SendAzurePostRequest(requestURL, certificateConfigBytes) if azureErr != nil { return azureErr @@ -730,7 +729,7 @@ func uploadServiceCert(dnsName, certPath string) (error) { func createServiceCertDeploymentConf(certPath string) (ServiceCertificate, error) { certConfig := ServiceCertificate{} certConfig.Xmlns = azureXmlns - data , err := ioutil.ReadFile(certPath) + data, err := ioutil.ReadFile(certPath) if err != nil { return certConfig, err } @@ -768,7 +767,7 @@ func getServiceCertFingerprint(certPath string) (string, error) { if readErr != nil { return "", readErr } - + block, rest := pem.Decode(certData) if block == nil { return "", errors.New(string(rest)) @@ -779,9 +778,9 @@ func getServiceCertFingerprint(certPath string) (string, error) { return fingerprint, nil } -func checkServiceCertExtension(certPath string) (error) { +func checkServiceCertExtension(certPath string) error { certParts := strings.Split(certPath, ".") - certExt := certParts[len(certParts) - 1] + certExt := certParts[len(certParts)-1] acceptedExtension := "pem" if certExt != acceptedExtension { @@ -809,7 +808,7 @@ func createNetworkConfig(os string) (ConfigurationSet, error) { return networkConfig, nil } -func createEndpoint(name string, protocol string, extertalPort int, internalPort int) (InputEndpoint) { +func createEndpoint(name string, protocol string, extertalPort int, internalPort int) InputEndpoint { endpoint := InputEndpoint{} endpoint.Name = name endpoint.Protocol = protocol diff --git a/clients/vmDiskClient/vmDiskClient.go b/clients/vmDiskClient/vmDiskClient.go index 477d8a1327da..d8ebcbf34295 100644 --- a/clients/vmDiskClient/vmDiskClient.go +++ b/clients/vmDiskClient/vmDiskClient.go @@ -26,4 +26,4 @@ func DeleteDisk(diskName string) error { return nil } -//Region public methods ends \ No newline at end of file +//Region public methods ends diff --git a/common.go b/common.go index da148fc041cc..c467e44295c3 100644 --- a/common.go +++ b/common.go @@ -1,32 +1,32 @@ package azureSdkForGo import ( - "fmt" - "io" "bytes" - "time" - "strings" - "errors" - "os/exec" "encoding/xml" - "github.com/MSOpenTech/azure-sdk-for-go/core/tls" + "errors" + "fmt" "github.com/MSOpenTech/azure-sdk-for-go/core/http" + "github.com/MSOpenTech/azure-sdk-for-go/core/tls" + "io" + "os/exec" + "strings" + "time" ) const ( ParamNotSpecifiedError = "Parameter %s is not specified." azureManagementDnsName = "https://management.core.windows.net" - msVersionHeader = "x-ms-version" - msVersionHeaderValue = "2014-05-01" - contentHeader = "Content-Type" - contentHeaderValue = "application/xml" - requestIdHeader = "X-Ms-Request-Id" + msVersionHeader = "x-ms-version" + msVersionHeaderValue = "2014-05-01" + contentHeader = "Content-Type" + contentHeaderValue = "application/xml" + requestIdHeader = "X-Ms-Request-Id" ) //Region public methods starts -func SendAzureGetRequest(url string) ([]byte, error){ +func SendAzureGetRequest(url string) ([]byte, error) { if len(url) == 0 { return nil, fmt.Errorf(ParamNotSpecifiedError, "url") } @@ -40,11 +40,11 @@ func SendAzureGetRequest(url string) ([]byte, error){ return responseContent, nil } -func SendAzurePostRequest(url string, data []byte) (string, error){ +func SendAzurePostRequest(url string, data []byte) (string, error) { if len(url) == 0 { return "", fmt.Errorf(ParamNotSpecifiedError, "url") } - + response, err := SendAzureRequest(url, "POST", data) if err != nil { return "", err @@ -54,11 +54,11 @@ func SendAzurePostRequest(url string, data []byte) (string, error){ return requestId[0], nil } -func SendAzureDeleteRequest(url string) (string, error){ +func SendAzureDeleteRequest(url string) (string, error) { if len(url) == 0 { return "", fmt.Errorf(ParamNotSpecifiedError, "url") } - + response, err := SendAzureRequest(url, "DELETE", nil) if err != nil { return "", err @@ -68,14 +68,14 @@ func SendAzureDeleteRequest(url string) (string, error){ return requestId[0], nil } -func SendAzureRequest(url string, requestType string, data []byte) (*http.Response, error){ +func SendAzureRequest(url string, requestType string, data []byte) (*http.Response, error) { if len(url) == 0 { return nil, fmt.Errorf(ParamNotSpecifiedError, "url") } if len(requestType) == 0 { return nil, fmt.Errorf(ParamNotSpecifiedError, "requestType") } - + client := createHttpClient() response, err := sendRequest(client, url, requestType, data, 5) @@ -90,7 +90,7 @@ func ExecuteCommand(command string) ([]byte, error) { if len(command) == 0 { return nil, fmt.Errorf(ParamNotSpecifiedError, "command") } - + parts := strings.Fields(command) head := parts[0] parts = parts[1:len(parts)] @@ -106,11 +106,11 @@ func ExecuteCommand(command string) ([]byte, error) { return out, nil } -func GetOperationStatus(operationId string) (*Operation, error){ +func GetOperationStatus(operationId string) (*Operation, error) { if len(operationId) == 0 { return nil, fmt.Errorf(ParamNotSpecifiedError, "operationId") } - + operation := new(Operation) url := "operations/" + operationId response, azureErr := SendAzureGetRequest(url) @@ -126,11 +126,11 @@ func GetOperationStatus(operationId string) (*Operation, error){ return operation, nil } -func WaitAsyncOperation(operationId string) (error) { +func WaitAsyncOperation(operationId string) error { if len(operationId) == 0 { return fmt.Errorf(ParamNotSpecifiedError, "operationId") } - + status := "InProgress" operation := new(Operation) err := errors.New("") @@ -151,7 +151,7 @@ func WaitAsyncOperation(operationId string) (error) { return nil } -func CheckStringParams(url string) ([]byte, error){ +func CheckStringParams(url string) ([]byte, error) { if len(url) == 0 { return nil, fmt.Errorf(ParamNotSpecifiedError, "url") } @@ -169,7 +169,7 @@ func CheckStringParams(url string) ([]byte, error){ //Region private methods starts -func sendRequest(client *http.Client, url string, requestType string, data []byte, numberOfRetries int) (*http.Response, error){ +func sendRequest(client *http.Client, url string, requestType string, data []byte, numberOfRetries int) (*http.Response, error) { request, reqErr := createAzureRequest(url, requestType, data) if reqErr != nil { return nil, reqErr @@ -199,7 +199,7 @@ func sendRequest(client *http.Client, url string, requestType string, data []byt return response, nil } -func getAzureError(responseBody []byte) (error){ +func getAzureError(responseBody []byte) error { error := new(AzureError) err := xml.Unmarshal(responseBody, error) if err != nil { @@ -209,7 +209,7 @@ func getAzureError(responseBody []byte) (error){ return error } -func createAzureRequest(url string, requestType string, data []byte) (*http.Request, error){ +func createAzureRequest(url string, requestType string, data []byte) (*http.Request, error) { var request *http.Request var err error @@ -231,7 +231,7 @@ func createAzureRequest(url string, requestType string, data []byte) (*http.Req return request, nil } -func createHttpClient() (*http.Client){ +func createHttpClient() *http.Client { cert, _ := tls.X509KeyPair(GetPublishSettings().SubscriptionCert, GetPublishSettings().SubscriptionKey) ssl := &tls.Config{} @@ -246,7 +246,7 @@ func createHttpClient() (*http.Client){ return client } -func getResponseBody(response *http.Response) ([]byte){ +func getResponseBody(response *http.Response) []byte { responseBody := make([]byte, response.ContentLength) io.ReadFull(response.Body, responseBody) @@ -256,9 +256,9 @@ func getResponseBody(response *http.Response) ([]byte){ //Region private methods ends type AzureError struct { - XMLName xml.Name `xml:"Error"` - Code string - Message string + XMLName xml.Name `xml:"Error"` + Code string + Message string } func (e *AzureError) Error() string { @@ -266,9 +266,9 @@ func (e *AzureError) Error() string { } type Operation struct { - XMLName xml.Name `xml:"Operation"` - ID string - Status string - HttpStatusCode string - Error AzureError + XMLName xml.Name `xml:"Operation"` + ID string + Status string + HttpStatusCode string + Error AzureError } diff --git a/core/http/response.go b/core/http/response.go index a0c6762dce0a..a8c64ba6332e 100644 --- a/core/http/response.go +++ b/core/http/response.go @@ -9,8 +9,8 @@ package http import ( "bufio" "bytes" - "github.com/MSOpenTech/azure-sdk-for-go/core/tls" "errors" + "github.com/MSOpenTech/azure-sdk-for-go/core/tls" "io" "net/textproto" "net/url" diff --git a/core/http/transport.go b/core/http/transport.go index e805a44dc8fe..144b01e33bd9 100644 --- a/core/http/transport.go +++ b/core/http/transport.go @@ -12,9 +12,9 @@ package http import ( "bufio" "compress/gzip" - "github.com/MSOpenTech/azure-sdk-for-go/core/tls" "errors" "fmt" + "github.com/MSOpenTech/azure-sdk-for-go/core/tls" "io" "log" "net" diff --git a/core/tls/conn.go b/core/tls/conn.go index aba810a95014..db036f967778 100644 --- a/core/tls/conn.go +++ b/core/tls/conn.go @@ -900,7 +900,6 @@ func (c *Conn) handleRenegotiation() error { return c.Handshake() } - // Read can be made to time out and return a net.Error with Timeout() == true // after a fixed time limit; see SetDeadline and SetReadDeadline. func (c *Conn) Read(b []byte) (n int, err error) { diff --git a/publishSettings.go b/publishSettings.go index e1b56c5a2466..ae7c9e9672e0 100644 --- a/publishSettings.go +++ b/publishSettings.go @@ -1,20 +1,20 @@ package azureSdkForGo import ( - "fmt" + "encoding/base64" + "encoding/xml" "errors" + "fmt" "io/ioutil" - "encoding/xml" "os" "os/user" "path" - "encoding/base64" ) var settings publishSettings = publishSettings{} func GetPublishSettings() publishSettings { - return settings; + return settings } func setPublishSettings(id string, cert []byte, key []byte) { @@ -30,7 +30,7 @@ func ImportPublishSettings(id string, certPath string) error { if len(certPath) == 0 { return fmt.Errorf(ParamNotSpecifiedError, "certPath") } - + cert, err := ioutil.ReadFile(certPath) if err != nil { return err @@ -93,7 +93,7 @@ func getSubscriptionCert(subscription subscription) ([]byte, error) { return pemCert, nil } -func createPfxCert(managementCert string, pfxCertPath string) (error) { +func createPfxCert(managementCert string, pfxCertPath string) error { pfxCert, err := base64.StdEncoding.DecodeString(managementCert) if err != nil { @@ -158,30 +158,30 @@ func getAzureDir() (string, error) { } type publishSettings struct { - XMLName xml.Name `xml:"PublishSettings"` - SubscriptionID string - SubscriptionCert []byte - SubscriptionKey []byte + XMLName xml.Name `xml:"PublishSettings"` + SubscriptionID string + SubscriptionCert []byte + SubscriptionKey []byte } type publishData struct { - XMLName xml.Name `xml:"PublishData"` + XMLName xml.Name `xml:"PublishData"` PublishProfiles []publishProfile `xml:"PublishProfile"` } type publishProfile struct { - XMLName xml.Name `xml:"PublishProfile"` - SchemaVersion string `xml:",attr"` - PublishMethod string `xml:",attr"` - Url string `xml:",attr"` - ManagementCertificate string `xml:",attr"` - Subscriptions []subscription `xml:"Subscription"` + XMLName xml.Name `xml:"PublishProfile"` + SchemaVersion string `xml:",attr"` + PublishMethod string `xml:",attr"` + Url string `xml:",attr"` + ManagementCertificate string `xml:",attr"` + Subscriptions []subscription `xml:"Subscription"` } type subscription struct { - XMLName xml.Name `xml:"Subscription"` - ServiceManagementUrl string `xml:",attr"` - Id string `xml:",attr"` - Name string `xml:",attr"` - ManagementCertificate string `xml:",attr"` + XMLName xml.Name `xml:"Subscription"` + ServiceManagementUrl string `xml:",attr"` + Id string `xml:",attr"` + Name string `xml:",attr"` + ManagementCertificate string `xml:",attr"` }