Skip to content

Commit

Permalink
Merge pull request #28 from jen20/private-error-messages
Browse files Browse the repository at this point in the history
Make azure.ParamNotSpecifiedError unexported
  • Loading branch information
ruslangabitov committed Feb 3, 2015
2 parents c1f7c85 + f833f04 commit 9abf8bf
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 71 deletions.
11 changes: 6 additions & 5 deletions clients/hostedServiceClient/hostedServiceClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ const (
azureDeploymentURL = "services/hostedservices/%s/deployments/%s"
deleteAzureDeploymentURL = "services/hostedservices/%s/deployments/%s?comp=media"

invalidDnsLengthError = "The DNS name must be between 3 and 25 characters."
invalidDnsLengthError = "The DNS name must be between 3 and 25 characters."
paramNotSpecifiedError = "Parameter %s is not specified."
)

func CreateHostedService(dnsName, location string, reverseDnsFqdn string) (string, error) {
if len(dnsName) == 0 {
return "", fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName")
return "", fmt.Errorf(paramNotSpecifiedError, "dnsName")
}
if len(location) == 0 {
return "", fmt.Errorf(azure.ParamNotSpecifiedError, "location")
return "", fmt.Errorf(paramNotSpecifiedError, "location")
}

err := verifyDNSName(dnsName)
Expand Down Expand Up @@ -64,7 +65,7 @@ func CreateHostedService(dnsName, location string, reverseDnsFqdn string) (strin

func CheckHostedServiceNameAvailability(dnsName string) (bool, string, error) {
if len(dnsName) == 0 {
return false, "", fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName")
return false, "", fmt.Errorf(paramNotSpecifiedError, "dnsName")
}

err := verifyDNSName(dnsName)
Expand All @@ -89,7 +90,7 @@ func CheckHostedServiceNameAvailability(dnsName string) (bool, string, error) {

func DeleteHostedService(dnsName string) error {
if len(dnsName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName")
return fmt.Errorf(paramNotSpecifiedError, "dnsName")
}

err := verifyDNSName(dnsName)
Expand Down
9 changes: 5 additions & 4 deletions clients/imageClient/imageClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
)

const (
azureImageListURL = "services/images"
invalidImageError = "Can not find image %s in specified subscription, please specify another image name."
azureImageListURL = "services/images"
invalidImageError = "Can not find image %s in specified subscription, please specify another image name."
paramNotSpecifiedError = "Parameter %s is not specified."
)

func GetImageList() (ImageList, error) {
Expand All @@ -24,13 +25,13 @@ func GetImageList() (ImageList, error) {
if err != nil {
return imageList, err
}

return imageList, err
}

func ResolveImageName(imageName string) error {
if len(imageName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "imageName")
return fmt.Errorf(paramNotSpecifiedError, "imageName")
}

imageList, err := GetImageList()
Expand Down
9 changes: 5 additions & 4 deletions clients/locationClient/locationClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
)

const (
azureLocationListURL = "locations"
invalidLocationError = "Invalid location: %s. Available locations: %s"
azureLocationListURL = "locations"
invalidLocationError = "Invalid location: %s. Available locations: %s"
paramNotSpecifiedError = "Parameter %s is not specified."
)

func ResolveLocation(location string) error {
if len(location) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "location")
return fmt.Errorf(paramNotSpecifiedError, "location")
}

locations, err := GetLocationList()
Expand Down Expand Up @@ -51,7 +52,7 @@ func GetLocationList() (LocationList, error) {

func GetLocation(location string) (*Location, error) {
if len(location) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "location")
return nil, fmt.Errorf(paramNotSpecifiedError, "location")
}

locations, err := GetLocationList()
Expand Down
9 changes: 5 additions & 4 deletions clients/storageServiceClient/storageServiceClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
azureStorageServiceURL = "services/storageservices/%s"

blobEndpointNotFoundError = "Blob endpoint was not found in storage serice %s"
paramNotSpecifiedError = "Parameter %s is not specified."
)

func GetStorageServiceList() (*StorageServiceList, error) {
Expand All @@ -35,7 +36,7 @@ func GetStorageServiceList() (*StorageServiceList, error) {

func GetStorageServiceByName(serviceName string) (*StorageService, error) {
if len(serviceName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "serviceName")
return nil, fmt.Errorf(paramNotSpecifiedError, "serviceName")
}

storageService := new(StorageService)
Expand All @@ -55,7 +56,7 @@ func GetStorageServiceByName(serviceName string) (*StorageService, error) {

func GetStorageServiceByLocation(location string) (*StorageService, error) {
if len(location) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "location")
return nil, fmt.Errorf(paramNotSpecifiedError, "location")
}

storageService := new(StorageService)
Expand All @@ -77,10 +78,10 @@ func GetStorageServiceByLocation(location string) (*StorageService, error) {

func CreateStorageService(name, location string) (*StorageService, error) {
if len(name) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "name")
return nil, fmt.Errorf(paramNotSpecifiedError, "name")
}
if len(location) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "location")
return nil, fmt.Errorf(paramNotSpecifiedError, "location")
}

storageDeploymentConfig := createStorageServiceDeploymentConf(name, location)
Expand Down
73 changes: 37 additions & 36 deletions clients/vmClient/vmClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ const (
invalidPasswordError = "Password must have at least one upper case, lower case and numeric character."
invalidRoleSizeError = "Invalid role size: %s. Available role sizes: %s"
invalidRoleSizeInLocationError = "Role size: %s not available in location: %s."
paramNotSpecifiedError = "Parameter %s is not specified."
)

//Region public methods starts

func CreateAzureVM(azureVMConfiguration *Role, dnsName, location string) error {
if azureVMConfiguration == nil {
return fmt.Errorf(azure.ParamNotSpecifiedError, "azureVMConfiguration")
return fmt.Errorf(paramNotSpecifiedError, "azureVMConfiguration")
}
if len(dnsName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName")
return fmt.Errorf(paramNotSpecifiedError, "dnsName")
}
if len(location) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "location")
return fmt.Errorf(paramNotSpecifiedError, "location")
}

err := verifyDNSname(dnsName)
Expand Down Expand Up @@ -99,16 +100,16 @@ func CreateAzureVM(azureVMConfiguration *Role, dnsName, location string) error {

func CreateAzureVMConfiguration(dnsName, instanceSize, imageName, location string) (*Role, error) {
if len(dnsName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName")
return nil, fmt.Errorf(paramNotSpecifiedError, "dnsName")
}
if len(instanceSize) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "instanceSize")
return nil, fmt.Errorf(paramNotSpecifiedError, "instanceSize")
}
if len(imageName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "imageName")
return nil, fmt.Errorf(paramNotSpecifiedError, "imageName")
}
if len(location) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "location")
return nil, fmt.Errorf(paramNotSpecifiedError, "location")
}

err := verifyDNSname(dnsName)
Expand Down Expand Up @@ -140,10 +141,10 @@ func CreateAzureVMConfiguration(dnsName, instanceSize, imageName, location strin

func AddAzureLinuxProvisioningConfig(azureVMConfiguration *Role, userName, password, certPath string, sshPort int) (*Role, error) {
if azureVMConfiguration == nil {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "azureVMConfiguration")
return nil, fmt.Errorf(paramNotSpecifiedError, "azureVMConfiguration")
}
if len(userName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "userName")
return nil, fmt.Errorf(paramNotSpecifiedError, "userName")
}

configurationSets := ConfigurationSets{}
Expand Down Expand Up @@ -173,19 +174,19 @@ func AddAzureLinuxProvisioningConfig(azureVMConfiguration *Role, userName, passw

func SetAzureVMExtension(azureVMConfiguration *Role, name string, publisher string, version string, referenceName string, state string, publicConfigurationValue string, privateConfigurationValue string) (*Role, error) {
if azureVMConfiguration == nil {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "azureVMConfiguration")
return nil, fmt.Errorf(paramNotSpecifiedError, "azureVMConfiguration")
}
if len(name) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "name")
return nil, fmt.Errorf(paramNotSpecifiedError, "name")
}
if len(publisher) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "publisher")
return nil, fmt.Errorf(paramNotSpecifiedError, "publisher")
}
if len(version) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "version")
return nil, fmt.Errorf(paramNotSpecifiedError, "version")
}
if len(referenceName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "referenceName")
return nil, fmt.Errorf(paramNotSpecifiedError, "referenceName")
}

extension := ResourceExtensionReference{}
Expand Down Expand Up @@ -220,7 +221,7 @@ func SetAzureVMExtension(azureVMConfiguration *Role, name string, publisher stri

func SetAzureDockerVMExtension(azureVMConfiguration *Role, dockerPort int, version string) (*Role, error) {
if azureVMConfiguration == nil {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "azureVMConfiguration")
return nil, fmt.Errorf(paramNotSpecifiedError, "azureVMConfiguration")
}

if len(version) == 0 {
Expand All @@ -245,10 +246,10 @@ func SetAzureDockerVMExtension(azureVMConfiguration *Role, dockerPort int, versi

func GetVMDeployment(cloudserviceName, deploymentName string) (*VMDeployment, error) {
if len(cloudserviceName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
return nil, fmt.Errorf(paramNotSpecifiedError, "cloudserviceName")
}
if len(deploymentName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
return nil, fmt.Errorf(paramNotSpecifiedError, "deploymentName")
}

deployment := new(VMDeployment)
Expand All @@ -269,10 +270,10 @@ func GetVMDeployment(cloudserviceName, deploymentName string) (*VMDeployment, er

func DeleteVMDeployment(cloudserviceName, deploymentName string) error {
if len(cloudserviceName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
return fmt.Errorf(paramNotSpecifiedError, "cloudserviceName")
}
if len(deploymentName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
return fmt.Errorf(paramNotSpecifiedError, "deploymentName")
}

requestURL := fmt.Sprintf(deleteAzureDeploymentURL, cloudserviceName, deploymentName)
Expand All @@ -288,13 +289,13 @@ func DeleteVMDeployment(cloudserviceName, deploymentName string) error {

func GetRole(cloudserviceName, deploymentName, roleName string) (*Role, error) {
if len(cloudserviceName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
return nil, fmt.Errorf(paramNotSpecifiedError, "cloudserviceName")
}
if len(deploymentName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
return nil, fmt.Errorf(paramNotSpecifiedError, "deploymentName")
}
if len(roleName) == 0 {
return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "roleName")
return nil, fmt.Errorf(paramNotSpecifiedError, "roleName")
}

role := new(Role)
Expand All @@ -315,13 +316,13 @@ func GetRole(cloudserviceName, deploymentName, roleName string) (*Role, error) {

func StartRole(cloudserviceName, deploymentName, roleName string) error {
if len(cloudserviceName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
return fmt.Errorf(paramNotSpecifiedError, "cloudserviceName")
}
if len(deploymentName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
return fmt.Errorf(paramNotSpecifiedError, "deploymentName")
}
if len(roleName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName")
return fmt.Errorf(paramNotSpecifiedError, "roleName")
}

startRoleOperation := createStartRoleOperation()
Expand All @@ -343,13 +344,13 @@ func StartRole(cloudserviceName, deploymentName, roleName string) error {

func ShutdownRole(cloudserviceName, deploymentName, roleName string) error {
if len(cloudserviceName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
return fmt.Errorf(paramNotSpecifiedError, "cloudserviceName")
}
if len(deploymentName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
return fmt.Errorf(paramNotSpecifiedError, "deploymentName")
}
if len(roleName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName")
return fmt.Errorf(paramNotSpecifiedError, "roleName")
}

shutdownRoleOperation := createShutdowRoleOperation()
Expand All @@ -371,13 +372,13 @@ func ShutdownRole(cloudserviceName, deploymentName, roleName string) error {

func RestartRole(cloudserviceName, deploymentName, roleName string) error {
if len(cloudserviceName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
return fmt.Errorf(paramNotSpecifiedError, "cloudserviceName")
}
if len(deploymentName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
return fmt.Errorf(paramNotSpecifiedError, "deploymentName")
}
if len(roleName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName")
return fmt.Errorf(paramNotSpecifiedError, "roleName")
}

restartRoleOperation := createRestartRoleOperation()
Expand All @@ -399,13 +400,13 @@ func RestartRole(cloudserviceName, deploymentName, roleName string) error {

func DeleteRole(cloudserviceName, deploymentName, roleName string) error {
if len(cloudserviceName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
return fmt.Errorf(paramNotSpecifiedError, "cloudserviceName")
}
if len(deploymentName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
return fmt.Errorf(paramNotSpecifiedError, "deploymentName")
}
if len(roleName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName")
return fmt.Errorf(paramNotSpecifiedError, "roleName")
}

requestURL := fmt.Sprintf(azureRoleURL, cloudserviceName, deploymentName, roleName)
Expand Down Expand Up @@ -436,7 +437,7 @@ func GetRoleSizeList() (RoleSizeList, error) {

func ResolveRoleSize(roleSizeName string) error {
if len(roleSizeName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "roleSizeName")
return fmt.Errorf(paramNotSpecifiedError, "roleSizeName")
}

roleSizeList, err := GetRoleSizeList()
Expand Down Expand Up @@ -764,7 +765,7 @@ next:

func isInstanceSizeAvailableInLocation(location *locationClient.Location, instanceSize string) (bool, error) {
if len(instanceSize) == 0 {
return false, fmt.Errorf(azure.ParamNotSpecifiedError, "vmSize")
return false, fmt.Errorf(paramNotSpecifiedError, "vmSize")
}

for _, availableRoleSize := range location.VirtualMachineRoleSizes {
Expand Down
5 changes: 3 additions & 2 deletions clients/vmDiskClient/vmDiskClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
)

const (
azureVMDiskURL = "services/disks/%s"
azureVMDiskURL = "services/disks/%s"
paramNotSpecifiedError = "Parameter %s is not specified."
)

//Region public methods starts

func DeleteDisk(diskName string) error {
if len(diskName) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "diskName")
return fmt.Errorf(paramNotSpecifiedError, "diskName")
}

requestURL := fmt.Sprintf(azureVMDiskURL, diskName)
Expand Down
Loading

0 comments on commit 9abf8bf

Please sign in to comment.