parent
7b301d7411
commit
9fb9b67381
|
@ -2,9 +2,9 @@ package azurerm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,9 +2,9 @@ package azurerm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
|
@ -2,10 +2,10 @@ package azurerm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
|
@ -3,9 +3,9 @@ package azurerm
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
|
@ -2,9 +2,9 @@ package azurerm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
|
@ -2,9 +2,9 @@ package azurerm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
|
@ -21,6 +21,7 @@ package cdn
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,6 +56,13 @@ func NewCustomDomainsClientWithBaseURI(baseURI string, subscriptionID string) Cu
|
||||||
// is name of the CDN profile within the resource group. resourceGroupName is
|
// is name of the CDN profile within the resource group. resourceGroupName is
|
||||||
// name of the resource group within the Azure subscription.
|
// name of the resource group within the Azure subscription.
|
||||||
func (client CustomDomainsClient) Create(customDomainName string, customDomainProperties CustomDomainParameters, endpointName string, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client CustomDomainsClient) Create(customDomainName string, customDomainProperties CustomDomainParameters, endpointName string, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{customDomainProperties,
|
||||||
|
[]validation.Constraint{{"customDomainProperties.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"customDomainProperties.Properties.HostName", validation.Null, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "cdn.CustomDomainsClient", "Create")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreatePreparer(customDomainName, customDomainProperties, endpointName, profileName, resourceGroupName, cancel)
|
req, err := client.CreatePreparer(customDomainName, customDomainProperties, endpointName, profileName, resourceGroupName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "cdn.CustomDomainsClient", "Create", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "cdn.CustomDomainsClient", "Create", nil, "Failure preparing request")
|
||||||
|
|
|
@ -21,6 +21,7 @@ package cdn
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +54,14 @@ func NewEndpointsClientWithBaseURI(baseURI string, subscriptionID string) Endpoi
|
||||||
// profile within the resource group. resourceGroupName is name of the
|
// profile within the resource group. resourceGroupName is name of the
|
||||||
// resource group within the Azure subscription.
|
// resource group within the Azure subscription.
|
||||||
func (client EndpointsClient) Create(endpointName string, endpointProperties EndpointCreateParameters, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client EndpointsClient) Create(endpointName string, endpointProperties EndpointCreateParameters, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{endpointProperties,
|
||||||
|
[]validation.Constraint{{"endpointProperties.Location", validation.Null, true, nil},
|
||||||
|
{"endpointProperties.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"endpointProperties.Properties.Origins", validation.Null, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "cdn.EndpointsClient", "Create")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreatePreparer(endpointName, endpointProperties, profileName, resourceGroupName, cancel)
|
req, err := client.CreatePreparer(endpointName, endpointProperties, profileName, resourceGroupName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Create", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Create", nil, "Failure preparing request")
|
||||||
|
@ -324,6 +333,12 @@ func (client EndpointsClient) ListByProfileResponder(resp *http.Response) (resul
|
||||||
// resource group. resourceGroupName is name of the resource group within the
|
// resource group. resourceGroupName is name of the resource group within the
|
||||||
// Azure subscription.
|
// Azure subscription.
|
||||||
func (client EndpointsClient) LoadContent(endpointName string, contentFilePaths LoadParameters, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client EndpointsClient) LoadContent(endpointName string, contentFilePaths LoadParameters, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{contentFilePaths,
|
||||||
|
[]validation.Constraint{{"contentFilePaths.ContentPaths", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "cdn.EndpointsClient", "LoadContent")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.LoadContentPreparer(endpointName, contentFilePaths, profileName, resourceGroupName, cancel)
|
req, err := client.LoadContentPreparer(endpointName, contentFilePaths, profileName, resourceGroupName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "LoadContent", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "LoadContent", nil, "Failure preparing request")
|
||||||
|
@ -397,6 +412,12 @@ func (client EndpointsClient) LoadContentResponder(resp *http.Response) (result
|
||||||
// within the resource group. resourceGroupName is name of the resource group
|
// within the resource group. resourceGroupName is name of the resource group
|
||||||
// within the Azure subscription.
|
// within the Azure subscription.
|
||||||
func (client EndpointsClient) PurgeContent(endpointName string, contentFilePaths PurgeParameters, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client EndpointsClient) PurgeContent(endpointName string, contentFilePaths PurgeParameters, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{contentFilePaths,
|
||||||
|
[]validation.Constraint{{"contentFilePaths.ContentPaths", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "cdn.EndpointsClient", "PurgeContent")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.PurgeContentPreparer(endpointName, contentFilePaths, profileName, resourceGroupName, cancel)
|
req, err := client.PurgeContentPreparer(endpointName, contentFilePaths, profileName, resourceGroupName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "PurgeContent", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "PurgeContent", nil, "Failure preparing request")
|
||||||
|
@ -673,6 +694,12 @@ func (client EndpointsClient) UpdateResponder(resp *http.Response) (result autor
|
||||||
// of the CDN profile within the resource group. resourceGroupName is name of
|
// of the CDN profile within the resource group. resourceGroupName is name of
|
||||||
// the resource group within the Azure subscription.
|
// the resource group within the Azure subscription.
|
||||||
func (client EndpointsClient) ValidateCustomDomain(endpointName string, customDomainProperties ValidateCustomDomainInput, profileName string, resourceGroupName string) (result ValidateCustomDomainOutput, err error) {
|
func (client EndpointsClient) ValidateCustomDomain(endpointName string, customDomainProperties ValidateCustomDomainInput, profileName string, resourceGroupName string) (result ValidateCustomDomainOutput, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{customDomainProperties,
|
||||||
|
[]validation.Constraint{{"customDomainProperties.HostName", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "cdn.EndpointsClient", "ValidateCustomDomain")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ValidateCustomDomainPreparer(endpointName, customDomainProperties, profileName, resourceGroupName)
|
req, err := client.ValidateCustomDomainPreparer(endpointName, customDomainProperties, profileName, resourceGroupName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ValidateCustomDomain", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ValidateCustomDomain", nil, "Failure preparing request")
|
||||||
|
|
|
@ -150,8 +150,8 @@ const (
|
||||||
|
|
||||||
// CheckNameAvailabilityInput is input of CheckNameAvailability API.
|
// CheckNameAvailabilityInput is input of CheckNameAvailability API.
|
||||||
type CheckNameAvailabilityInput struct {
|
type CheckNameAvailabilityInput struct {
|
||||||
Name *string `json:"name,omitempty"`
|
Name *string `json:"name,omitempty"`
|
||||||
Type ResourceType `json:"type,omitempty"`
|
Type *string `json:"type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckNameAvailabilityOutput is output of check name availability API.
|
// CheckNameAvailabilityOutput is output of check name availability API.
|
||||||
|
|
|
@ -21,6 +21,7 @@ package cdn
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,6 +50,13 @@ func NewNameAvailabilityClientWithBaseURI(baseURI string, subscriptionID string)
|
||||||
//
|
//
|
||||||
// checkNameAvailabilityInput is input to check.
|
// checkNameAvailabilityInput is input to check.
|
||||||
func (client NameAvailabilityClient) CheckNameAvailability(checkNameAvailabilityInput CheckNameAvailabilityInput) (result CheckNameAvailabilityOutput, err error) {
|
func (client NameAvailabilityClient) CheckNameAvailability(checkNameAvailabilityInput CheckNameAvailabilityInput) (result CheckNameAvailabilityOutput, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{checkNameAvailabilityInput,
|
||||||
|
[]validation.Constraint{{"checkNameAvailabilityInput.Name", validation.Null, true, nil},
|
||||||
|
{"checkNameAvailabilityInput.Type", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "cdn.NameAvailabilityClient", "CheckNameAvailability")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CheckNameAvailabilityPreparer(checkNameAvailabilityInput)
|
req, err := client.CheckNameAvailabilityPreparer(checkNameAvailabilityInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "cdn.NameAvailabilityClient", "CheckNameAvailability", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "cdn.NameAvailabilityClient", "CheckNameAvailability", nil, "Failure preparing request")
|
||||||
|
|
|
@ -21,6 +21,7 @@ package cdn
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +54,13 @@ func NewOriginsClientWithBaseURI(baseURI string, subscriptionID string) OriginsC
|
||||||
// CDN profile within the resource group. resourceGroupName is name of the
|
// CDN profile within the resource group. resourceGroupName is name of the
|
||||||
// resource group within the Azure subscription.
|
// resource group within the Azure subscription.
|
||||||
func (client OriginsClient) Create(originName string, originProperties OriginParameters, endpointName string, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client OriginsClient) Create(originName string, originProperties OriginParameters, endpointName string, profileName string, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{originProperties,
|
||||||
|
[]validation.Constraint{{"originProperties.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"originProperties.Properties.HostName", validation.Null, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "cdn.OriginsClient", "Create")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreatePreparer(originName, originProperties, endpointName, profileName, resourceGroupName, cancel)
|
req, err := client.CreatePreparer(originName, originProperties, endpointName, profileName, resourceGroupName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "cdn.OriginsClient", "Create", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "cdn.OriginsClient", "Create", nil, "Failure preparing request")
|
||||||
|
|
|
@ -21,6 +21,7 @@ package cdn
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +54,13 @@ func NewProfilesClientWithBaseURI(baseURI string, subscriptionID string) Profile
|
||||||
// resourceGroupName is name of the resource group within the Azure
|
// resourceGroupName is name of the resource group within the Azure
|
||||||
// subscription.
|
// subscription.
|
||||||
func (client ProfilesClient) Create(profileName string, profileProperties ProfileCreateParameters, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client ProfilesClient) Create(profileName string, profileProperties ProfileCreateParameters, resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{profileProperties,
|
||||||
|
[]validation.Constraint{{"profileProperties.Location", validation.Null, true, nil},
|
||||||
|
{"profileProperties.Sku", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "cdn.ProfilesClient", "Create")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreatePreparer(profileName, profileProperties, resourceGroupName, cancel)
|
req, err := client.CreatePreparer(profileName, profileProperties, resourceGroupName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Create", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Create", nil, "Failure preparing request")
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
major = "3"
|
major = "4"
|
||||||
minor = "2"
|
minor = "0"
|
||||||
patch = "0"
|
patch = "0"
|
||||||
// Always begin a "tag" with a dash (as per http://semver.org)
|
// Always begin a "tag" with a dash (as per http://semver.org)
|
||||||
tag = "-beta"
|
tag = "-beta"
|
||||||
|
|
|
@ -21,6 +21,7 @@ package compute
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,6 +46,12 @@ func NewUsageOperationsClientWithBaseURI(baseURI string, subscriptionID string)
|
||||||
//
|
//
|
||||||
// location is the location upon which resource usage is queried.
|
// location is the location upon which resource usage is queried.
|
||||||
func (client UsageOperationsClient) List(location string) (result ListUsagesResult, err error) {
|
func (client UsageOperationsClient) List(location string) (result ListUsagesResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{location,
|
||||||
|
[]validation.Constraint{{"location", validation.Pattern, `^[-\w\._]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "compute.UsageOperationsClient", "List")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListPreparer(location)
|
req, err := client.ListPreparer(location)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.UsageOperationsClient", "List", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "compute.UsageOperationsClient", "List", nil, "Failure preparing request")
|
||||||
|
@ -106,7 +113,7 @@ func (client UsageOperationsClient) ListResponder(resp *http.Response) (result L
|
||||||
func (client UsageOperationsClient) ListNextResults(lastResults ListUsagesResult) (result ListUsagesResult, err error) {
|
func (client UsageOperationsClient) ListNextResults(lastResults ListUsagesResult) (result ListUsagesResult, err error) {
|
||||||
req, err := lastResults.ListUsagesResultPreparer()
|
req, err := lastResults.ListUsagesResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.UsageOperationsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.UsageOperationsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -115,12 +122,12 @@ func (client UsageOperationsClient) ListNextResults(lastResults ListUsagesResult
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "compute.UsageOperationsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.UsageOperationsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "compute.UsageOperationsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "compute.UsageOperationsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
major = "3"
|
major = "4"
|
||||||
minor = "2"
|
minor = "0"
|
||||||
patch = "0"
|
patch = "0"
|
||||||
// Always begin a "tag" with a dash (as per http://semver.org)
|
// Always begin a "tag" with a dash (as per http://semver.org)
|
||||||
tag = "-beta"
|
tag = "-beta"
|
||||||
|
|
8
vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensions.go
generated
vendored
8
vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensions.go
generated
vendored
|
@ -21,6 +21,7 @@ package compute
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,6 +53,13 @@ func NewVirtualMachineExtensionsClientWithBaseURI(baseURI string, subscriptionID
|
||||||
// extensionParameters is parameters supplied to the Create Virtual Machine
|
// extensionParameters is parameters supplied to the Create Virtual Machine
|
||||||
// Extension operation.
|
// Extension operation.
|
||||||
func (client VirtualMachineExtensionsClient) CreateOrUpdate(resourceGroupName string, vmName string, vmExtensionName string, extensionParameters VirtualMachineExtension, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client VirtualMachineExtensionsClient) CreateOrUpdate(resourceGroupName string, vmName string, vmExtensionName string, extensionParameters VirtualMachineExtension, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{extensionParameters,
|
||||||
|
[]validation.Constraint{{"extensionParameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"ProvisioningState", validation.ReadOnly, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "compute.VirtualMachineExtensionsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, vmName, vmExtensionName, extensionParameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, vmName, vmExtensionName, extensionParameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
|
|
@ -21,6 +21,7 @@ package compute
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,6 +52,14 @@ func NewVirtualMachinesClientWithBaseURI(baseURI string, subscriptionID string)
|
||||||
// the virtual machine. parameters is parameters supplied to the Capture
|
// the virtual machine. parameters is parameters supplied to the Capture
|
||||||
// Virtual Machine operation.
|
// Virtual Machine operation.
|
||||||
func (client VirtualMachinesClient) Capture(resourceGroupName string, vmName string, parameters VirtualMachineCaptureParameters, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client VirtualMachinesClient) Capture(resourceGroupName string, vmName string, parameters VirtualMachineCaptureParameters, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.VhdPrefix", validation.Null, true, nil},
|
||||||
|
{"parameters.DestinationContainerName", validation.Null, true, nil},
|
||||||
|
{"parameters.OverwriteVhds", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "compute.VirtualMachinesClient", "Capture")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CapturePreparer(resourceGroupName, vmName, parameters, cancel)
|
req, err := client.CapturePreparer(resourceGroupName, vmName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Capture", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Capture", nil, "Failure preparing request")
|
||||||
|
@ -121,6 +130,33 @@ func (client VirtualMachinesClient) CaptureResponder(resp *http.Response) (resul
|
||||||
// the virtual machine. parameters is parameters supplied to the Create
|
// the virtual machine. parameters is parameters supplied to the Create
|
||||||
// Virtual Machine operation.
|
// Virtual Machine operation.
|
||||||
func (client VirtualMachinesClient) CreateOrUpdate(resourceGroupName string, vmName string, parameters VirtualMachine, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client VirtualMachinesClient) CreateOrUpdate(resourceGroupName string, vmName string, parameters VirtualMachine, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.StorageProfile", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.StorageProfile.OsDisk", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.StorageProfile.OsDisk.EncryptionSettings", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.StorageProfile.OsDisk.EncryptionSettings.DiskEncryptionKey", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.StorageProfile.OsDisk.EncryptionSettings.DiskEncryptionKey.SecretURL", validation.Null, true, nil},
|
||||||
|
{"parameters.Properties.StorageProfile.OsDisk.EncryptionSettings.DiskEncryptionKey.SourceVault", validation.Null, true, nil},
|
||||||
|
}},
|
||||||
|
{"parameters.Properties.StorageProfile.OsDisk.EncryptionSettings.KeyEncryptionKey", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.StorageProfile.OsDisk.EncryptionSettings.KeyEncryptionKey.KeyURL", validation.Null, true, nil},
|
||||||
|
{"parameters.Properties.StorageProfile.OsDisk.EncryptionSettings.KeyEncryptionKey.SourceVault", validation.Null, true, nil},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
{"parameters.Properties.StorageProfile.OsDisk.Name", validation.Null, true, nil},
|
||||||
|
{"parameters.Properties.StorageProfile.OsDisk.Vhd", validation.Null, true, nil},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
{"ProvisioningState", validation.ReadOnly, true, nil},
|
||||||
|
{"InstanceView", validation.ReadOnly, true, nil},
|
||||||
|
{"VMID", validation.ReadOnly, true, nil},
|
||||||
|
}},
|
||||||
|
{"Resources", validation.ReadOnly, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "compute.VirtualMachinesClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, vmName, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, vmName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -511,7 +547,7 @@ func (client VirtualMachinesClient) ListResponder(resp *http.Response) (result V
|
||||||
func (client VirtualMachinesClient) ListNextResults(lastResults VirtualMachineListResult) (result VirtualMachineListResult, err error) {
|
func (client VirtualMachinesClient) ListNextResults(lastResults VirtualMachineListResult) (result VirtualMachineListResult, err error) {
|
||||||
req, err := lastResults.VirtualMachineListResultPreparer()
|
req, err := lastResults.VirtualMachineListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -520,12 +556,12 @@ func (client VirtualMachinesClient) ListNextResults(lastResults VirtualMachineLi
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -595,7 +631,7 @@ func (client VirtualMachinesClient) ListAllResponder(resp *http.Response) (resul
|
||||||
func (client VirtualMachinesClient) ListAllNextResults(lastResults VirtualMachineListResult) (result VirtualMachineListResult, err error) {
|
func (client VirtualMachinesClient) ListAllNextResults(lastResults VirtualMachineListResult) (result VirtualMachineListResult, err error) {
|
||||||
req, err := lastResults.VirtualMachineListResultPreparer()
|
req, err := lastResults.VirtualMachineListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -604,12 +640,12 @@ func (client VirtualMachinesClient) ListAllNextResults(lastResults VirtualMachin
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
45
vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesets.go
generated
vendored
45
vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesets.go
generated
vendored
|
@ -21,6 +21,7 @@ package compute
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,6 +52,20 @@ func NewVirtualMachineScaleSetsClientWithBaseURI(baseURI string, subscriptionID
|
||||||
// supplied to the Create Virtual Machine Scale Set operation. parameters is
|
// supplied to the Create Virtual Machine Scale Set operation. parameters is
|
||||||
// parameters supplied to the Create Virtual Machine Scale Set operation.
|
// parameters supplied to the Create Virtual Machine Scale Set operation.
|
||||||
func (client VirtualMachineScaleSetsClient) CreateOrUpdate(resourceGroupName string, name string, parameters VirtualMachineScaleSet, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client VirtualMachineScaleSetsClient) CreateOrUpdate(resourceGroupName string, name string, parameters VirtualMachineScaleSet, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.VirtualMachineProfile", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.VirtualMachineProfile.StorageProfile", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.VirtualMachineProfile.StorageProfile.OsDisk", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.VirtualMachineProfile.StorageProfile.OsDisk.Name", validation.Null, true, nil}}},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
{"ProvisioningState", validation.ReadOnly, true, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "compute.VirtualMachineScaleSetsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, name, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, name, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -263,6 +278,12 @@ func (client VirtualMachineScaleSetsClient) DeleteResponder(resp *http.Response)
|
||||||
// name of the virtual machine scale set. vmInstanceIDs is the list of
|
// name of the virtual machine scale set. vmInstanceIDs is the list of
|
||||||
// virtual machine scale set instance IDs.
|
// virtual machine scale set instance IDs.
|
||||||
func (client VirtualMachineScaleSetsClient) DeleteInstances(resourceGroupName string, vmScaleSetName string, vmInstanceIDs VirtualMachineScaleSetVMInstanceRequiredIDs, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client VirtualMachineScaleSetsClient) DeleteInstances(resourceGroupName string, vmScaleSetName string, vmInstanceIDs VirtualMachineScaleSetVMInstanceRequiredIDs, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{vmInstanceIDs,
|
||||||
|
[]validation.Constraint{{"vmInstanceIDs.InstanceIds", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "compute.VirtualMachineScaleSetsClient", "DeleteInstances")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.DeleteInstancesPreparer(resourceGroupName, vmScaleSetName, vmInstanceIDs, cancel)
|
req, err := client.DeleteInstancesPreparer(resourceGroupName, vmScaleSetName, vmInstanceIDs, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "DeleteInstances", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "DeleteInstances", nil, "Failure preparing request")
|
||||||
|
@ -515,7 +536,7 @@ func (client VirtualMachineScaleSetsClient) ListResponder(resp *http.Response) (
|
||||||
func (client VirtualMachineScaleSetsClient) ListNextResults(lastResults VirtualMachineScaleSetListResult) (result VirtualMachineScaleSetListResult, err error) {
|
func (client VirtualMachineScaleSetsClient) ListNextResults(lastResults VirtualMachineScaleSetListResult) (result VirtualMachineScaleSetListResult, err error) {
|
||||||
req, err := lastResults.VirtualMachineScaleSetListResultPreparer()
|
req, err := lastResults.VirtualMachineScaleSetListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -524,12 +545,12 @@ func (client VirtualMachineScaleSetsClient) ListNextResults(lastResults VirtualM
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -600,7 +621,7 @@ func (client VirtualMachineScaleSetsClient) ListAllResponder(resp *http.Response
|
||||||
func (client VirtualMachineScaleSetsClient) ListAllNextResults(lastResults VirtualMachineScaleSetListWithLinkResult) (result VirtualMachineScaleSetListWithLinkResult, err error) {
|
func (client VirtualMachineScaleSetsClient) ListAllNextResults(lastResults VirtualMachineScaleSetListWithLinkResult) (result VirtualMachineScaleSetListWithLinkResult, err error) {
|
||||||
req, err := lastResults.VirtualMachineScaleSetListWithLinkResultPreparer()
|
req, err := lastResults.VirtualMachineScaleSetListWithLinkResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -609,12 +630,12 @@ func (client VirtualMachineScaleSetsClient) ListAllNextResults(lastResults Virtu
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -689,7 +710,7 @@ func (client VirtualMachineScaleSetsClient) ListSkusResponder(resp *http.Respons
|
||||||
func (client VirtualMachineScaleSetsClient) ListSkusNextResults(lastResults VirtualMachineScaleSetListSkusResult) (result VirtualMachineScaleSetListSkusResult, err error) {
|
func (client VirtualMachineScaleSetsClient) ListSkusNextResults(lastResults VirtualMachineScaleSetListSkusResult) (result VirtualMachineScaleSetListSkusResult, err error) {
|
||||||
req, err := lastResults.VirtualMachineScaleSetListSkusResultPreparer()
|
req, err := lastResults.VirtualMachineScaleSetListSkusResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListSkus", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListSkus", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -698,12 +719,12 @@ func (client VirtualMachineScaleSetsClient) ListSkusNextResults(lastResults Virt
|
||||||
resp, err := client.ListSkusSender(req)
|
resp, err := client.ListSkusSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListSkus", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListSkus", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListSkusResponder(resp)
|
result, err = client.ListSkusResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListSkus", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ListSkus", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -1007,6 +1028,12 @@ func (client VirtualMachineScaleSetsClient) StartResponder(resp *http.Response)
|
||||||
// name of the virtual machine scale set. vmInstanceIDs is the list of
|
// name of the virtual machine scale set. vmInstanceIDs is the list of
|
||||||
// virtual machine scale set instance IDs.
|
// virtual machine scale set instance IDs.
|
||||||
func (client VirtualMachineScaleSetsClient) UpdateInstances(resourceGroupName string, vmScaleSetName string, vmInstanceIDs VirtualMachineScaleSetVMInstanceRequiredIDs, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client VirtualMachineScaleSetsClient) UpdateInstances(resourceGroupName string, vmScaleSetName string, vmInstanceIDs VirtualMachineScaleSetVMInstanceRequiredIDs, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{vmInstanceIDs,
|
||||||
|
[]validation.Constraint{{"vmInstanceIDs.InstanceIds", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "compute.VirtualMachineScaleSetsClient", "UpdateInstances")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.UpdateInstancesPreparer(resourceGroupName, vmScaleSetName, vmInstanceIDs, cancel)
|
req, err := client.UpdateInstancesPreparer(resourceGroupName, vmScaleSetName, vmInstanceIDs, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "UpdateInstances", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "UpdateInstances", nil, "Failure preparing request")
|
||||||
|
|
6
vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesetvms.go
generated
vendored
6
vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesetvms.go
generated
vendored
|
@ -391,7 +391,7 @@ func (client VirtualMachineScaleSetVMsClient) ListResponder(resp *http.Response)
|
||||||
func (client VirtualMachineScaleSetVMsClient) ListNextResults(lastResults VirtualMachineScaleSetVMListResult) (result VirtualMachineScaleSetVMListResult, err error) {
|
func (client VirtualMachineScaleSetVMsClient) ListNextResults(lastResults VirtualMachineScaleSetVMListResult) (result VirtualMachineScaleSetVMListResult, err error) {
|
||||||
req, err := lastResults.VirtualMachineScaleSetVMListResultPreparer()
|
req, err := lastResults.VirtualMachineScaleSetVMListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -400,12 +400,12 @@ func (client VirtualMachineScaleSetVMsClient) ListNextResults(lastResults Virtua
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,6 +21,7 @@ package compute
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,6 +47,12 @@ func NewVirtualMachineSizesClientWithBaseURI(baseURI string, subscriptionID stri
|
||||||
//
|
//
|
||||||
// location is the location upon which virtual-machine-sizes is queried.
|
// location is the location upon which virtual-machine-sizes is queried.
|
||||||
func (client VirtualMachineSizesClient) List(location string) (result VirtualMachineSizeListResult, err error) {
|
func (client VirtualMachineSizesClient) List(location string) (result VirtualMachineSizeListResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{location,
|
||||||
|
[]validation.Constraint{{"location", validation.Pattern, `^[-\w\._]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "compute.VirtualMachineSizesClient", "List")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListPreparer(location)
|
req, err := client.ListPreparer(location)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineSizesClient", "List", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "compute.VirtualMachineSizesClient", "List", nil, "Failure preparing request")
|
||||||
|
|
|
@ -21,12 +21,13 @@ package network
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ApplicationGatewaysClient is the the Microsoft Azure Network management API
|
// ApplicationGatewaysClient is the the Microsoft Azure Network management API
|
||||||
// provides a RESTful set of web services that interact with Microsoft Azure
|
// provides a RESTful set of web services that interact with Microsoft Azure
|
||||||
// Networks service to manage your network resrources. The API has entities
|
// Networks service to manage your network resources. The API has entities
|
||||||
// that capture the relationship between an end user and the Microsoft Azure
|
// that capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type ApplicationGatewaysClient struct {
|
type ApplicationGatewaysClient struct {
|
||||||
|
@ -54,6 +55,13 @@ func NewApplicationGatewaysClientWithBaseURI(baseURI string, subscriptionID stri
|
||||||
// is the name of the ApplicationGateway. parameters is parameters supplied
|
// is the name of the ApplicationGateway. parameters is parameters supplied
|
||||||
// to the create/delete ApplicationGateway operation
|
// to the create/delete ApplicationGateway operation
|
||||||
func (client ApplicationGatewaysClient) CreateOrUpdate(resourceGroupName string, applicationGatewayName string, parameters ApplicationGateway, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client ApplicationGatewaysClient) CreateOrUpdate(resourceGroupName string, applicationGatewayName string, parameters ApplicationGateway, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"OperationalState", validation.ReadOnly, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "network.ApplicationGatewaysClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, applicationGatewayName, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, applicationGatewayName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -115,13 +123,13 @@ func (client ApplicationGatewaysClient) CreateOrUpdateResponder(resp *http.Respo
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the delete applicationgateway operation deletes the specified
|
// Delete the delete ApplicationGateway operation deletes the specified
|
||||||
// applicationgateway. This method may poll for completion. Polling can be
|
// application gateway. This method may poll for completion. Polling can be
|
||||||
// canceled by passing the cancel channel argument. The channel will be used
|
// canceled by passing the cancel channel argument. The channel will be used
|
||||||
// to cancel polling and any outstanding HTTP requests.
|
// to cancel polling and any outstanding HTTP requests.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. applicationGatewayName
|
// resourceGroupName is the name of the resource group. applicationGatewayName
|
||||||
// is the name of the applicationgateway.
|
// is the name of the application gateway.
|
||||||
func (client ApplicationGatewaysClient) Delete(resourceGroupName string, applicationGatewayName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client ApplicationGatewaysClient) Delete(resourceGroupName string, applicationGatewayName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
req, err := client.DeletePreparer(resourceGroupName, applicationGatewayName, cancel)
|
req, err := client.DeletePreparer(resourceGroupName, applicationGatewayName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -182,11 +190,11 @@ func (client ApplicationGatewaysClient) DeleteResponder(resp *http.Response) (re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get applicationgateway operation retreives information about the
|
// Get the Get ApplicationGateway operation retrieves information about the
|
||||||
// specified applicationgateway.
|
// specified application gateway.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. applicationGatewayName
|
// resourceGroupName is the name of the resource group. applicationGatewayName
|
||||||
// is the name of the applicationgateway.
|
// is the name of the application gateway.
|
||||||
func (client ApplicationGatewaysClient) Get(resourceGroupName string, applicationGatewayName string) (result ApplicationGateway, err error) {
|
func (client ApplicationGatewaysClient) Get(resourceGroupName string, applicationGatewayName string) (result ApplicationGateway, err error) {
|
||||||
req, err := client.GetPreparer(resourceGroupName, applicationGatewayName)
|
req, err := client.GetPreparer(resourceGroupName, applicationGatewayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -246,8 +254,8 @@ func (client ApplicationGatewaysClient) GetResponder(resp *http.Response) (resul
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// List the List ApplicationGateway operation retrieves all the
|
// List the List ApplicationGateway operation retrieves all the application
|
||||||
// applicationgateways in a resource group.
|
// gateways in a resource group.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group.
|
// resourceGroupName is the name of the resource group.
|
||||||
func (client ApplicationGatewaysClient) List(resourceGroupName string) (result ApplicationGatewayListResult, err error) {
|
func (client ApplicationGatewaysClient) List(resourceGroupName string) (result ApplicationGatewayListResult, err error) {
|
||||||
|
@ -312,7 +320,7 @@ func (client ApplicationGatewaysClient) ListResponder(resp *http.Response) (resu
|
||||||
func (client ApplicationGatewaysClient) ListNextResults(lastResults ApplicationGatewayListResult) (result ApplicationGatewayListResult, err error) {
|
func (client ApplicationGatewaysClient) ListNextResults(lastResults ApplicationGatewayListResult) (result ApplicationGatewayListResult, err error) {
|
||||||
req, err := lastResults.ApplicationGatewayListResultPreparer()
|
req, err := lastResults.ApplicationGatewayListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -321,19 +329,19 @@ func (client ApplicationGatewaysClient) ListNextResults(lastResults ApplicationG
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAll the List applicationgateway operation retrieves all the
|
// ListAll the List ApplicationGateway operation retrieves all the application
|
||||||
// applicationgateways in a subscription.
|
// gateways in a subscription.
|
||||||
func (client ApplicationGatewaysClient) ListAll() (result ApplicationGatewayListResult, err error) {
|
func (client ApplicationGatewaysClient) ListAll() (result ApplicationGatewayListResult, err error) {
|
||||||
req, err := client.ListAllPreparer()
|
req, err := client.ListAllPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -395,7 +403,7 @@ func (client ApplicationGatewaysClient) ListAllResponder(resp *http.Response) (r
|
||||||
func (client ApplicationGatewaysClient) ListAllNextResults(lastResults ApplicationGatewayListResult) (result ApplicationGatewayListResult, err error) {
|
func (client ApplicationGatewaysClient) ListAllNextResults(lastResults ApplicationGatewayListResult) (result ApplicationGatewayListResult, err error) {
|
||||||
req, err := lastResults.ApplicationGatewayListResultPreparer()
|
req, err := lastResults.ApplicationGatewayListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -404,18 +412,18 @@ func (client ApplicationGatewaysClient) ListAllNextResults(lastResults Applicati
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.ApplicationGatewaysClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the Start ApplicationGateway operation starts application gatewayin
|
// Start the Start ApplicationGateway operation starts application gateway in
|
||||||
// the specified resource group through Network resource provider. This
|
// the specified resource group through Network resource provider. This
|
||||||
// method may poll for completion. Polling can be canceled by passing the
|
// method may poll for completion. Polling can be canceled by passing the
|
||||||
// cancel channel argument. The channel will be used to cancel polling and
|
// cancel channel argument. The channel will be used to cancel polling and
|
||||||
|
@ -483,7 +491,7 @@ func (client ApplicationGatewaysClient) StartResponder(resp *http.Response) (res
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the STOP ApplicationGateway operation stops application gatewayin the
|
// Stop the STOP ApplicationGateway operation stops application gateway in the
|
||||||
// specified resource group through Network resource provider. This method
|
// specified resource group through Network resource provider. This method
|
||||||
// may poll for completion. Polling can be canceled by passing the cancel
|
// may poll for completion. Polling can be canceled by passing the cancel
|
||||||
// channel argument. The channel will be used to cancel polling and any
|
// channel argument. The channel will be used to cancel polling and any
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
//
|
//
|
||||||
// The Microsoft Azure Network management API provides a RESTful set of web
|
// The Microsoft Azure Network management API provides a RESTful set of web
|
||||||
// services that interact with Microsoft Azure Networks service to manage
|
// services that interact with Microsoft Azure Networks service to manage
|
||||||
// your network resrources. The API has entities that capture the
|
// your network resources. The API has entities that capture the relationship
|
||||||
// relationship between an end user and the Microsoft Azure Networks service.
|
// between an end user and the Microsoft Azure Networks service.
|
||||||
package network
|
package network
|
||||||
|
|
||||||
// Copyright (c) Microsoft and contributors. All rights reserved.
|
// Copyright (c) Microsoft and contributors. All rights reserved.
|
||||||
|
|
|
@ -26,8 +26,8 @@ import (
|
||||||
|
|
||||||
// ExpressRouteCircuitAuthorizationsClient is the the Microsoft Azure Network
|
// ExpressRouteCircuitAuthorizationsClient is the the Microsoft Azure Network
|
||||||
// management API provides a RESTful set of web services that interact with
|
// management API provides a RESTful set of web services that interact with
|
||||||
// Microsoft Azure Networks service to manage your network resrources. The
|
// Microsoft Azure Networks service to manage your network resources. The API
|
||||||
// API has entities that capture the relationship between an end user and the
|
// has entities that capture the relationship between an end user and the
|
||||||
// Microsoft Azure Networks service.
|
// Microsoft Azure Networks service.
|
||||||
type ExpressRouteCircuitAuthorizationsClient struct {
|
type ExpressRouteCircuitAuthorizationsClient struct {
|
||||||
ManagementClient
|
ManagementClient
|
||||||
|
@ -46,7 +46,7 @@ func NewExpressRouteCircuitAuthorizationsClientWithBaseURI(baseURI string, subsc
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrUpdate the Put Authorization operation creates/updates an
|
// CreateOrUpdate the Put Authorization operation creates/updates an
|
||||||
// authorization in thespecified ExpressRouteCircuits This method may poll
|
// authorization in the specified ExpressRouteCircuits This method may poll
|
||||||
// for completion. Polling can be canceled by passing the cancel channel
|
// for completion. Polling can be canceled by passing the cancel channel
|
||||||
// argument. The channel will be used to cancel polling and any outstanding
|
// argument. The channel will be used to cancel polling and any outstanding
|
||||||
// HTTP requests.
|
// HTTP requests.
|
||||||
|
@ -258,7 +258,7 @@ func (client ExpressRouteCircuitAuthorizationsClient) GetResponder(resp *http.Re
|
||||||
// an ExpressRouteCircuit.
|
// an ExpressRouteCircuit.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. circuitName is the
|
// resourceGroupName is the name of the resource group. circuitName is the
|
||||||
// name of the curcuit.
|
// name of the circuit.
|
||||||
func (client ExpressRouteCircuitAuthorizationsClient) List(resourceGroupName string, circuitName string) (result AuthorizationListResult, err error) {
|
func (client ExpressRouteCircuitAuthorizationsClient) List(resourceGroupName string, circuitName string) (result AuthorizationListResult, err error) {
|
||||||
req, err := client.ListPreparer(resourceGroupName, circuitName)
|
req, err := client.ListPreparer(resourceGroupName, circuitName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -322,7 +322,7 @@ func (client ExpressRouteCircuitAuthorizationsClient) ListResponder(resp *http.R
|
||||||
func (client ExpressRouteCircuitAuthorizationsClient) ListNextResults(lastResults AuthorizationListResult) (result AuthorizationListResult, err error) {
|
func (client ExpressRouteCircuitAuthorizationsClient) ListNextResults(lastResults AuthorizationListResult) (result AuthorizationListResult, err error) {
|
||||||
req, err := lastResults.AuthorizationListResultPreparer()
|
req, err := lastResults.AuthorizationListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -331,12 +331,12 @@ func (client ExpressRouteCircuitAuthorizationsClient) ListNextResults(lastResult
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
14
vendor/github.com/Azure/azure-sdk-for-go/arm/network/expressroutecircuitpeerings.go
generated
vendored
14
vendor/github.com/Azure/azure-sdk-for-go/arm/network/expressroutecircuitpeerings.go
generated
vendored
|
@ -26,8 +26,8 @@ import (
|
||||||
|
|
||||||
// ExpressRouteCircuitPeeringsClient is the the Microsoft Azure Network
|
// ExpressRouteCircuitPeeringsClient is the the Microsoft Azure Network
|
||||||
// management API provides a RESTful set of web services that interact with
|
// management API provides a RESTful set of web services that interact with
|
||||||
// Microsoft Azure Networks service to manage your network resrources. The
|
// Microsoft Azure Networks service to manage your network resources. The API
|
||||||
// API has entities that capture the relationship between an end user and the
|
// has entities that capture the relationship between an end user and the
|
||||||
// Microsoft Azure Networks service.
|
// Microsoft Azure Networks service.
|
||||||
type ExpressRouteCircuitPeeringsClient struct {
|
type ExpressRouteCircuitPeeringsClient struct {
|
||||||
ManagementClient
|
ManagementClient
|
||||||
|
@ -45,7 +45,7 @@ func NewExpressRouteCircuitPeeringsClientWithBaseURI(baseURI string, subscriptio
|
||||||
return ExpressRouteCircuitPeeringsClient{NewWithBaseURI(baseURI, subscriptionID)}
|
return ExpressRouteCircuitPeeringsClient{NewWithBaseURI(baseURI, subscriptionID)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrUpdate the Put Pering operation creates/updates an peering in the
|
// CreateOrUpdate the Put Peering operation creates/updates an peering in the
|
||||||
// specified ExpressRouteCircuits This method may poll for completion.
|
// specified ExpressRouteCircuits This method may poll for completion.
|
||||||
// Polling can be canceled by passing the cancel channel argument. The
|
// Polling can be canceled by passing the cancel channel argument. The
|
||||||
// channel will be used to cancel polling and any outstanding HTTP requests.
|
// channel will be used to cancel polling and any outstanding HTTP requests.
|
||||||
|
@ -254,7 +254,7 @@ func (client ExpressRouteCircuitPeeringsClient) GetResponder(resp *http.Response
|
||||||
// ExpressRouteCircuit.
|
// ExpressRouteCircuit.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. circuitName is the
|
// resourceGroupName is the name of the resource group. circuitName is the
|
||||||
// name of the curcuit.
|
// name of the circuit.
|
||||||
func (client ExpressRouteCircuitPeeringsClient) List(resourceGroupName string, circuitName string) (result ExpressRouteCircuitPeeringListResult, err error) {
|
func (client ExpressRouteCircuitPeeringsClient) List(resourceGroupName string, circuitName string) (result ExpressRouteCircuitPeeringListResult, err error) {
|
||||||
req, err := client.ListPreparer(resourceGroupName, circuitName)
|
req, err := client.ListPreparer(resourceGroupName, circuitName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -318,7 +318,7 @@ func (client ExpressRouteCircuitPeeringsClient) ListResponder(resp *http.Respons
|
||||||
func (client ExpressRouteCircuitPeeringsClient) ListNextResults(lastResults ExpressRouteCircuitPeeringListResult) (result ExpressRouteCircuitPeeringListResult, err error) {
|
func (client ExpressRouteCircuitPeeringsClient) ListNextResults(lastResults ExpressRouteCircuitPeeringListResult) (result ExpressRouteCircuitPeeringListResult, err error) {
|
||||||
req, err := lastResults.ExpressRouteCircuitPeeringListResultPreparer()
|
req, err := lastResults.ExpressRouteCircuitPeeringListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -327,12 +327,12 @@ func (client ExpressRouteCircuitPeeringsClient) ListNextResults(lastResults Expr
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
// ExpressRouteCircuitsClient is the the Microsoft Azure Network management
|
// ExpressRouteCircuitsClient is the the Microsoft Azure Network management
|
||||||
// API provides a RESTful set of web services that interact with Microsoft
|
// API provides a RESTful set of web services that interact with Microsoft
|
||||||
// Azure Networks service to manage your network resrources. The API has
|
// Azure Networks service to manage your network resources. The API has
|
||||||
// entities that capture the relationship between an end user and the
|
// entities that capture the relationship between an end user and the
|
||||||
// Microsoft Azure Networks service.
|
// Microsoft Azure Networks service.
|
||||||
type ExpressRouteCircuitsClient struct {
|
type ExpressRouteCircuitsClient struct {
|
||||||
|
@ -182,7 +182,7 @@ func (client ExpressRouteCircuitsClient) DeleteResponder(resp *http.Response) (r
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get ExpressRouteCircuit operation retreives information about the
|
// Get the Get ExpressRouteCircuit operation retrieves information about the
|
||||||
// specified ExpressRouteCircuit.
|
// specified ExpressRouteCircuit.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. circuitName is the
|
// resourceGroupName is the name of the resource group. circuitName is the
|
||||||
|
@ -246,7 +246,7 @@ func (client ExpressRouteCircuitsClient) GetResponder(resp *http.Response) (resu
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPeeringStats the Liststats ExpressRouteCircuit operation retrieves all
|
// GetPeeringStats the List stats ExpressRouteCircuit operation retrieves all
|
||||||
// the stats from a ExpressRouteCircuits in a resource group.
|
// the stats from a ExpressRouteCircuits in a resource group.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. circuitName is the
|
// resourceGroupName is the name of the resource group. circuitName is the
|
||||||
|
@ -311,7 +311,7 @@ func (client ExpressRouteCircuitsClient) GetPeeringStatsResponder(resp *http.Res
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStats the Liststats ExpressRouteCircuit operation retrieves all the
|
// GetStats the List stats ExpressRouteCircuit operation retrieves all the
|
||||||
// stats from a ExpressRouteCircuits in a resource group.
|
// stats from a ExpressRouteCircuits in a resource group.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. circuitName is the
|
// resourceGroupName is the name of the resource group. circuitName is the
|
||||||
|
@ -441,7 +441,7 @@ func (client ExpressRouteCircuitsClient) ListResponder(resp *http.Response) (res
|
||||||
func (client ExpressRouteCircuitsClient) ListNextResults(lastResults ExpressRouteCircuitListResult) (result ExpressRouteCircuitListResult, err error) {
|
func (client ExpressRouteCircuitsClient) ListNextResults(lastResults ExpressRouteCircuitListResult) (result ExpressRouteCircuitListResult, err error) {
|
||||||
req, err := lastResults.ExpressRouteCircuitListResultPreparer()
|
req, err := lastResults.ExpressRouteCircuitListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -450,12 +450,12 @@ func (client ExpressRouteCircuitsClient) ListNextResults(lastResults ExpressRout
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -524,7 +524,7 @@ func (client ExpressRouteCircuitsClient) ListAllResponder(resp *http.Response) (
|
||||||
func (client ExpressRouteCircuitsClient) ListAllNextResults(lastResults ExpressRouteCircuitListResult) (result ExpressRouteCircuitListResult, err error) {
|
func (client ExpressRouteCircuitsClient) ListAllNextResults(lastResults ExpressRouteCircuitListResult) (result ExpressRouteCircuitListResult, err error) {
|
||||||
req, err := lastResults.ExpressRouteCircuitListResultPreparer()
|
req, err := lastResults.ExpressRouteCircuitListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -533,12 +533,12 @@ func (client ExpressRouteCircuitsClient) ListAllNextResults(lastResults ExpressR
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitsClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
10
vendor/github.com/Azure/azure-sdk-for-go/arm/network/expressrouteserviceproviders.go
generated
vendored
10
vendor/github.com/Azure/azure-sdk-for-go/arm/network/expressrouteserviceproviders.go
generated
vendored
|
@ -26,8 +26,8 @@ import (
|
||||||
|
|
||||||
// ExpressRouteServiceProvidersClient is the the Microsoft Azure Network
|
// ExpressRouteServiceProvidersClient is the the Microsoft Azure Network
|
||||||
// management API provides a RESTful set of web services that interact with
|
// management API provides a RESTful set of web services that interact with
|
||||||
// Microsoft Azure Networks service to manage your network resrources. The
|
// Microsoft Azure Networks service to manage your network resources. The API
|
||||||
// API has entities that capture the relationship between an end user and the
|
// has entities that capture the relationship between an end user and the
|
||||||
// Microsoft Azure Networks service.
|
// Microsoft Azure Networks service.
|
||||||
type ExpressRouteServiceProvidersClient struct {
|
type ExpressRouteServiceProvidersClient struct {
|
||||||
ManagementClient
|
ManagementClient
|
||||||
|
@ -108,7 +108,7 @@ func (client ExpressRouteServiceProvidersClient) ListResponder(resp *http.Respon
|
||||||
func (client ExpressRouteServiceProvidersClient) ListNextResults(lastResults ExpressRouteServiceProviderListResult) (result ExpressRouteServiceProviderListResult, err error) {
|
func (client ExpressRouteServiceProvidersClient) ListNextResults(lastResults ExpressRouteServiceProviderListResult) (result ExpressRouteServiceProviderListResult, err error) {
|
||||||
req, err := lastResults.ExpressRouteServiceProviderListResultPreparer()
|
req, err := lastResults.ExpressRouteServiceProviderListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -117,12 +117,12 @@ func (client ExpressRouteServiceProvidersClient) ListNextResults(lastResults Exp
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,12 +21,13 @@ package network
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InterfacesClient is the the Microsoft Azure Network management API provides
|
// InterfacesClient is the the Microsoft Azure Network management API provides
|
||||||
// a RESTful set of web services that interact with Microsoft Azure Networks
|
// a RESTful set of web services that interact with Microsoft Azure Networks
|
||||||
// service to manage your network resrources. The API has entities that
|
// service to manage your network resources. The API has entities that
|
||||||
// capture the relationship between an end user and the Microsoft Azure
|
// capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type InterfacesClient struct {
|
type InterfacesClient struct {
|
||||||
|
@ -53,6 +54,19 @@ func NewInterfacesClientWithBaseURI(baseURI string, subscriptionID string) Inter
|
||||||
// is the name of the network interface. parameters is parameters supplied to
|
// is the name of the network interface. parameters is parameters supplied to
|
||||||
// the create/update NetworkInterface operation
|
// the create/update NetworkInterface operation
|
||||||
func (client InterfacesClient) CreateOrUpdate(resourceGroupName string, networkInterfaceName string, parameters Interface, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client InterfacesClient) CreateOrUpdate(resourceGroupName string, networkInterfaceName string, parameters Interface, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.NetworkSecurityGroup", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.NetworkSecurityGroup.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"NetworkInterfaces", validation.ReadOnly, true, nil},
|
||||||
|
{"Subnets", validation.ReadOnly, true, nil},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "network.InterfacesClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, networkInterfaceName, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, networkInterfaceName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -181,7 +195,7 @@ func (client InterfacesClient) DeleteResponder(resp *http.Response) (result auto
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get ntework interface operation retreives information about the
|
// Get the Get network interface operation retrieves information about the
|
||||||
// specified network interface.
|
// specified network interface.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. networkInterfaceName
|
// resourceGroupName is the name of the resource group. networkInterfaceName
|
||||||
|
@ -317,8 +331,8 @@ func (client InterfacesClient) GetEffectiveRouteTableResponder(resp *http.Respon
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVirtualMachineScaleSetNetworkInterface the Get ntework interface
|
// GetVirtualMachineScaleSetNetworkInterface the Get network interface
|
||||||
// operation retreives information about the specified network interface in a
|
// operation retrieves information about the specified network interface in a
|
||||||
// virtual machine scale set.
|
// virtual machine scale set.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group.
|
// resourceGroupName is the name of the resource group.
|
||||||
|
@ -455,7 +469,7 @@ func (client InterfacesClient) ListResponder(resp *http.Response) (result Interf
|
||||||
func (client InterfacesClient) ListNextResults(lastResults InterfaceListResult) (result InterfaceListResult, err error) {
|
func (client InterfacesClient) ListNextResults(lastResults InterfaceListResult) (result InterfaceListResult, err error) {
|
||||||
req, err := lastResults.InterfaceListResultPreparer()
|
req, err := lastResults.InterfaceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -464,12 +478,12 @@ func (client InterfacesClient) ListNextResults(lastResults InterfaceListResult)
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.InterfacesClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.InterfacesClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -538,7 +552,7 @@ func (client InterfacesClient) ListAllResponder(resp *http.Response) (result Int
|
||||||
func (client InterfacesClient) ListAllNextResults(lastResults InterfaceListResult) (result InterfaceListResult, err error) {
|
func (client InterfacesClient) ListAllNextResults(lastResults InterfaceListResult) (result InterfaceListResult, err error) {
|
||||||
req, err := lastResults.InterfaceListResultPreparer()
|
req, err := lastResults.InterfaceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -547,12 +561,12 @@ func (client InterfacesClient) ListAllNextResults(lastResults InterfaceListResul
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.InterfacesClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.InterfacesClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -695,7 +709,7 @@ func (client InterfacesClient) ListVirtualMachineScaleSetNetworkInterfacesRespon
|
||||||
func (client InterfacesClient) ListVirtualMachineScaleSetNetworkInterfacesNextResults(lastResults InterfaceListResult) (result InterfaceListResult, err error) {
|
func (client InterfacesClient) ListVirtualMachineScaleSetNetworkInterfacesNextResults(lastResults InterfaceListResult) (result InterfaceListResult, err error) {
|
||||||
req, err := lastResults.InterfaceListResultPreparer()
|
req, err := lastResults.InterfaceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetNetworkInterfaces", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetNetworkInterfaces", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -704,12 +718,12 @@ func (client InterfacesClient) ListVirtualMachineScaleSetNetworkInterfacesNextRe
|
||||||
resp, err := client.ListVirtualMachineScaleSetNetworkInterfacesSender(req)
|
resp, err := client.ListVirtualMachineScaleSetNetworkInterfacesSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetNetworkInterfaces", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetNetworkInterfaces", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListVirtualMachineScaleSetNetworkInterfacesResponder(resp)
|
result, err = client.ListVirtualMachineScaleSetNetworkInterfacesResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetNetworkInterfaces", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetNetworkInterfaces", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -786,7 +800,7 @@ func (client InterfacesClient) ListVirtualMachineScaleSetVMNetworkInterfacesResp
|
||||||
func (client InterfacesClient) ListVirtualMachineScaleSetVMNetworkInterfacesNextResults(lastResults InterfaceListResult) (result InterfaceListResult, err error) {
|
func (client InterfacesClient) ListVirtualMachineScaleSetVMNetworkInterfacesNextResults(lastResults InterfaceListResult) (result InterfaceListResult, err error) {
|
||||||
req, err := lastResults.InterfaceListResultPreparer()
|
req, err := lastResults.InterfaceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetVMNetworkInterfaces", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetVMNetworkInterfaces", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -795,12 +809,12 @@ func (client InterfacesClient) ListVirtualMachineScaleSetVMNetworkInterfacesNext
|
||||||
resp, err := client.ListVirtualMachineScaleSetVMNetworkInterfacesSender(req)
|
resp, err := client.ListVirtualMachineScaleSetVMNetworkInterfacesSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetVMNetworkInterfaces", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetVMNetworkInterfaces", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListVirtualMachineScaleSetVMNetworkInterfacesResponder(resp)
|
result, err = client.ListVirtualMachineScaleSetVMNetworkInterfacesResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetVMNetworkInterfaces", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.InterfacesClient", "ListVirtualMachineScaleSetVMNetworkInterfaces", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
// LoadBalancersClient is the the Microsoft Azure Network management API
|
// LoadBalancersClient is the the Microsoft Azure Network management API
|
||||||
// provides a RESTful set of web services that interact with Microsoft Azure
|
// provides a RESTful set of web services that interact with Microsoft Azure
|
||||||
// Networks service to manage your network resrources. The API has entities
|
// Networks service to manage your network resources. The API has entities
|
||||||
// that capture the relationship between an end user and the Microsoft Azure
|
// that capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type LoadBalancersClient struct {
|
type LoadBalancersClient struct {
|
||||||
|
@ -115,9 +115,9 @@ func (client LoadBalancersClient) CreateOrUpdateResponder(resp *http.Response) (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the delete loadbalancer operation deletes the specified
|
// Delete the delete LoadBalancer operation deletes the specified load
|
||||||
// loadbalancer. This method may poll for completion. Polling can be canceled
|
// balancer. This method may poll for completion. Polling can be canceled by
|
||||||
// by passing the cancel channel argument. The channel will be used to cancel
|
// passing the cancel channel argument. The channel will be used to cancel
|
||||||
// polling and any outstanding HTTP requests.
|
// polling and any outstanding HTTP requests.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. loadBalancerName is
|
// resourceGroupName is the name of the resource group. loadBalancerName is
|
||||||
|
@ -182,8 +182,8 @@ func (client LoadBalancersClient) DeleteResponder(resp *http.Response) (result a
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get ntework interface operation retreives information about the
|
// Get the Get LoadBalancer operation retrieves information about the
|
||||||
// specified network interface.
|
// specified LoadBalancer.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. loadBalancerName is
|
// resourceGroupName is the name of the resource group. loadBalancerName is
|
||||||
// the name of the loadBalancer. expand is expand references resources.
|
// the name of the loadBalancer. expand is expand references resources.
|
||||||
|
@ -249,7 +249,7 @@ func (client LoadBalancersClient) GetResponder(resp *http.Response) (result Load
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// List the List loadBalancer operation retrieves all the loadbalancers in a
|
// List the List loadBalancer operation retrieves all the load balancers in a
|
||||||
// resource group.
|
// resource group.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group.
|
// resourceGroupName is the name of the resource group.
|
||||||
|
@ -315,7 +315,7 @@ func (client LoadBalancersClient) ListResponder(resp *http.Response) (result Loa
|
||||||
func (client LoadBalancersClient) ListNextResults(lastResults LoadBalancerListResult) (result LoadBalancerListResult, err error) {
|
func (client LoadBalancersClient) ListNextResults(lastResults LoadBalancerListResult) (result LoadBalancerListResult, err error) {
|
||||||
req, err := lastResults.LoadBalancerListResultPreparer()
|
req, err := lastResults.LoadBalancerListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -324,18 +324,18 @@ func (client LoadBalancersClient) ListNextResults(lastResults LoadBalancerListRe
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAll the List loadBalancer operation retrieves all the loadbalancers in
|
// ListAll the List loadBalancer operation retrieves all the load balancers in
|
||||||
// a subscription.
|
// a subscription.
|
||||||
func (client LoadBalancersClient) ListAll() (result LoadBalancerListResult, err error) {
|
func (client LoadBalancersClient) ListAll() (result LoadBalancerListResult, err error) {
|
||||||
req, err := client.ListAllPreparer()
|
req, err := client.ListAllPreparer()
|
||||||
|
@ -398,7 +398,7 @@ func (client LoadBalancersClient) ListAllResponder(resp *http.Response) (result
|
||||||
func (client LoadBalancersClient) ListAllNextResults(lastResults LoadBalancerListResult) (result LoadBalancerListResult, err error) {
|
func (client LoadBalancersClient) ListAllNextResults(lastResults LoadBalancerListResult) (result LoadBalancerListResult, err error) {
|
||||||
req, err := lastResults.LoadBalancerListResultPreparer()
|
req, err := lastResults.LoadBalancerListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -407,12 +407,12 @@ func (client LoadBalancersClient) ListAllNextResults(lastResults LoadBalancerLis
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
// LocalNetworkGatewaysClient is the the Microsoft Azure Network management
|
// LocalNetworkGatewaysClient is the the Microsoft Azure Network management
|
||||||
// API provides a RESTful set of web services that interact with Microsoft
|
// API provides a RESTful set of web services that interact with Microsoft
|
||||||
// Azure Networks service to manage your network resrources. The API has
|
// Azure Networks service to manage your network resources. The API has
|
||||||
// entities that capture the relationship between an end user and the
|
// entities that capture the relationship between an end user and the
|
||||||
// Microsoft Azure Networks service.
|
// Microsoft Azure Networks service.
|
||||||
type LocalNetworkGatewaysClient struct {
|
type LocalNetworkGatewaysClient struct {
|
||||||
|
@ -117,7 +117,7 @@ func (client LocalNetworkGatewaysClient) CreateOrUpdateResponder(resp *http.Resp
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the Delete LocalNetworkGateway operation deletes the specifed local
|
// Delete the Delete LocalNetworkGateway operation deletes the specified local
|
||||||
// network Gateway through Network resource provider. This method may poll
|
// network Gateway through Network resource provider. This method may poll
|
||||||
// for completion. Polling can be canceled by passing the cancel channel
|
// for completion. Polling can be canceled by passing the cancel channel
|
||||||
// argument. The channel will be used to cancel polling and any outstanding
|
// argument. The channel will be used to cancel polling and any outstanding
|
||||||
|
@ -315,7 +315,7 @@ func (client LocalNetworkGatewaysClient) ListResponder(resp *http.Response) (res
|
||||||
func (client LocalNetworkGatewaysClient) ListNextResults(lastResults LocalNetworkGatewayListResult) (result LocalNetworkGatewayListResult, err error) {
|
func (client LocalNetworkGatewaysClient) ListNextResults(lastResults LocalNetworkGatewayListResult) (result LocalNetworkGatewayListResult, err error) {
|
||||||
req, err := lastResults.LocalNetworkGatewayListResultPreparer()
|
req, err := lastResults.LocalNetworkGatewayListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -324,12 +324,12 @@ func (client LocalNetworkGatewaysClient) ListNextResults(lastResults LocalNetwor
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -438,6 +438,10 @@ const (
|
||||||
// VirtualNetworkGatewaySkuNameStandard specifies the virtual network
|
// VirtualNetworkGatewaySkuNameStandard specifies the virtual network
|
||||||
// gateway sku name standard state for virtual network gateway sku name.
|
// gateway sku name standard state for virtual network gateway sku name.
|
||||||
VirtualNetworkGatewaySkuNameStandard VirtualNetworkGatewaySkuName = "Standard"
|
VirtualNetworkGatewaySkuNameStandard VirtualNetworkGatewaySkuName = "Standard"
|
||||||
|
// VirtualNetworkGatewaySkuNameUltraPerformance specifies the virtual
|
||||||
|
// network gateway sku name ultra performance state for virtual network
|
||||||
|
// gateway sku name.
|
||||||
|
VirtualNetworkGatewaySkuNameUltraPerformance VirtualNetworkGatewaySkuName = "UltraPerformance"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VirtualNetworkGatewaySkuTier enumerates the values for virtual network
|
// VirtualNetworkGatewaySkuTier enumerates the values for virtual network
|
||||||
|
@ -455,6 +459,10 @@ const (
|
||||||
// VirtualNetworkGatewaySkuTierStandard specifies the virtual network
|
// VirtualNetworkGatewaySkuTierStandard specifies the virtual network
|
||||||
// gateway sku tier standard state for virtual network gateway sku tier.
|
// gateway sku tier standard state for virtual network gateway sku tier.
|
||||||
VirtualNetworkGatewaySkuTierStandard VirtualNetworkGatewaySkuTier = "Standard"
|
VirtualNetworkGatewaySkuTierStandard VirtualNetworkGatewaySkuTier = "Standard"
|
||||||
|
// VirtualNetworkGatewaySkuTierUltraPerformance specifies the virtual
|
||||||
|
// network gateway sku tier ultra performance state for virtual network
|
||||||
|
// gateway sku tier.
|
||||||
|
VirtualNetworkGatewaySkuTierUltraPerformance VirtualNetworkGatewaySkuTier = "UltraPerformance"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VirtualNetworkGatewayType enumerates the values for virtual network gateway
|
// VirtualNetworkGatewayType enumerates the values for virtual network gateway
|
||||||
|
@ -816,10 +824,10 @@ type AuthorizationPropertiesFormat struct {
|
||||||
|
|
||||||
// AzureAsyncOperationResult is the response body contains the status of the
|
// AzureAsyncOperationResult is the response body contains the status of the
|
||||||
// specified asynchronous operation, indicating whether it has succeeded, is
|
// specified asynchronous operation, indicating whether it has succeeded, is
|
||||||
// inprogress, or has failed. Note that this status is distinct from the HTTP
|
// in progress, or has failed. Note that this status is distinct from the
|
||||||
// status code returned for the Get Operation Status operation itself. If the
|
// HTTP status code returned for the Get Operation Status operation itself.
|
||||||
// asynchronous operation succeeded, the response body includes the HTTP
|
// If the asynchronous operation succeeded, the response body includes the
|
||||||
// status code for the successful request. If the asynchronous operation
|
// HTTP status code for the successful request. If the asynchronous operation
|
||||||
// failed, the response body includes the HTTP status code for the failed
|
// failed, the response body includes the HTTP status code for the failed
|
||||||
// request and error information regarding the failure.
|
// request and error information regarding the failure.
|
||||||
type AzureAsyncOperationResult struct {
|
type AzureAsyncOperationResult struct {
|
||||||
|
@ -827,7 +835,7 @@ type AzureAsyncOperationResult struct {
|
||||||
Error *Error `json:"error,omitempty"`
|
Error *Error `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BackendAddressPool is pool of backend IP addresseses
|
// BackendAddressPool is pool of backend IP addresses
|
||||||
type BackendAddressPool struct {
|
type BackendAddressPool struct {
|
||||||
ID *string `json:"id,omitempty"`
|
ID *string `json:"id,omitempty"`
|
||||||
Properties *BackendAddressPoolPropertiesFormat `json:"properties,omitempty"`
|
Properties *BackendAddressPoolPropertiesFormat `json:"properties,omitempty"`
|
||||||
|
@ -856,14 +864,14 @@ type ConnectionResetSharedKey struct {
|
||||||
KeyLength *int64 `json:"keyLength,omitempty"`
|
KeyLength *int64 `json:"keyLength,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectionSharedKey is response for GetConnectionSharedKey Api servive call
|
// ConnectionSharedKey is response for GetConnectionSharedKey Api service call
|
||||||
type ConnectionSharedKey struct {
|
type ConnectionSharedKey struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
Value *string `json:"value,omitempty"`
|
Value *string `json:"value,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectionSharedKeyResult is response for CheckConnectionSharedKey Api
|
// ConnectionSharedKeyResult is response for CheckConnectionSharedKey Api
|
||||||
// servive call
|
// service call
|
||||||
type ConnectionSharedKeyResult struct {
|
type ConnectionSharedKeyResult struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
Value *string `json:"value,omitempty"`
|
Value *string `json:"value,omitempty"`
|
||||||
|
@ -877,7 +885,7 @@ type DhcpOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DNSNameAvailabilityResult is response for CheckDnsNameAvailability Api
|
// DNSNameAvailabilityResult is response for CheckDnsNameAvailability Api
|
||||||
// servive call
|
// service call
|
||||||
type DNSNameAvailabilityResult struct {
|
type DNSNameAvailabilityResult struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
Available *bool `json:"available,omitempty"`
|
Available *bool `json:"available,omitempty"`
|
||||||
|
@ -898,7 +906,7 @@ type EffectiveNetworkSecurityGroupAssociation struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// EffectiveNetworkSecurityGroupListResult is response for list effective
|
// EffectiveNetworkSecurityGroupListResult is response for list effective
|
||||||
// network security groups api servive call
|
// network security groups api service call
|
||||||
type EffectiveNetworkSecurityGroupListResult struct {
|
type EffectiveNetworkSecurityGroupListResult struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
Value *[]EffectiveNetworkSecurityGroup `json:"value,omitempty"`
|
Value *[]EffectiveNetworkSecurityGroup `json:"value,omitempty"`
|
||||||
|
@ -930,7 +938,7 @@ type EffectiveRoute struct {
|
||||||
NextHopType RouteNextHopType `json:"nextHopType,omitempty"`
|
NextHopType RouteNextHopType `json:"nextHopType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EffectiveRouteListResult is response for list effective route api servive
|
// EffectiveRouteListResult is response for list effective route api service
|
||||||
// call
|
// call
|
||||||
type EffectiveRouteListResult struct {
|
type EffectiveRouteListResult struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
|
@ -1015,7 +1023,7 @@ type ExpressRouteCircuitPeering struct {
|
||||||
Etag *string `json:"etag,omitempty"`
|
Etag *string `json:"etag,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpressRouteCircuitPeeringConfig is specfies the peering config
|
// ExpressRouteCircuitPeeringConfig is specifies the peering config
|
||||||
type ExpressRouteCircuitPeeringConfig struct {
|
type ExpressRouteCircuitPeeringConfig struct {
|
||||||
AdvertisedPublicPrefixes *[]string `json:"advertisedPublicPrefixes,omitempty"`
|
AdvertisedPublicPrefixes *[]string `json:"advertisedPublicPrefixes,omitempty"`
|
||||||
AdvertisedPublicPrefixesState ExpressRouteCircuitPeeringAdvertisedPublicPrefixState `json:"advertisedPublicPrefixesState,omitempty"`
|
AdvertisedPublicPrefixesState ExpressRouteCircuitPeeringAdvertisedPublicPrefixState `json:"advertisedPublicPrefixesState,omitempty"`
|
||||||
|
@ -1211,7 +1219,7 @@ type FrontendIPConfigurationPropertiesFormat struct {
|
||||||
ProvisioningState *string `json:"provisioningState,omitempty"`
|
ProvisioningState *string `json:"provisioningState,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InboundNatPool is inbound NAT pool of the loadbalancer
|
// InboundNatPool is inbound NAT pool of the load balancer
|
||||||
type InboundNatPool struct {
|
type InboundNatPool struct {
|
||||||
ID *string `json:"id,omitempty"`
|
ID *string `json:"id,omitempty"`
|
||||||
Properties *InboundNatPoolPropertiesFormat `json:"properties,omitempty"`
|
Properties *InboundNatPoolPropertiesFormat `json:"properties,omitempty"`
|
||||||
|
@ -1456,7 +1464,7 @@ type LocalNetworkGatewayPropertiesFormat struct {
|
||||||
ProvisioningState *string `json:"provisioningState,omitempty"`
|
ProvisioningState *string `json:"provisioningState,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutboundNatRule is outbound NAT pool of the loadbalancer
|
// OutboundNatRule is outbound NAT pool of the load balancer
|
||||||
type OutboundNatRule struct {
|
type OutboundNatRule struct {
|
||||||
ID *string `json:"id,omitempty"`
|
ID *string `json:"id,omitempty"`
|
||||||
Properties *OutboundNatRulePropertiesFormat `json:"properties,omitempty"`
|
Properties *OutboundNatRulePropertiesFormat `json:"properties,omitempty"`
|
||||||
|
@ -1464,7 +1472,7 @@ type OutboundNatRule struct {
|
||||||
Etag *string `json:"etag,omitempty"`
|
Etag *string `json:"etag,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutboundNatRulePropertiesFormat is outbound NAT pool of the loadbalancer
|
// OutboundNatRulePropertiesFormat is outbound NAT pool of the load balancer
|
||||||
type OutboundNatRulePropertiesFormat struct {
|
type OutboundNatRulePropertiesFormat struct {
|
||||||
AllocatedOutboundPorts *int32 `json:"allocatedOutboundPorts,omitempty"`
|
AllocatedOutboundPorts *int32 `json:"allocatedOutboundPorts,omitempty"`
|
||||||
FrontendIPConfigurations *[]SubResource `json:"frontendIPConfigurations,omitempty"`
|
FrontendIPConfigurations *[]SubResource `json:"frontendIPConfigurations,omitempty"`
|
||||||
|
@ -1576,7 +1584,7 @@ type Route struct {
|
||||||
Etag *string `json:"etag,omitempty"`
|
Etag *string `json:"etag,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RouteListResult is response for ListRoute Api servive call
|
// RouteListResult is response for ListRoute Api service call
|
||||||
type RouteListResult struct {
|
type RouteListResult struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
Value *[]Route `json:"value,omitempty"`
|
Value *[]Route `json:"value,omitempty"`
|
||||||
|
@ -1615,7 +1623,7 @@ type RouteTable struct {
|
||||||
Etag *string `json:"etag,omitempty"`
|
Etag *string `json:"etag,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RouteTableListResult is response for ListRouteTable Api servive call
|
// RouteTableListResult is response for ListRouteTable Api service call
|
||||||
type RouteTableListResult struct {
|
type RouteTableListResult struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
Value *[]RouteTable `json:"value,omitempty"`
|
Value *[]RouteTable `json:"value,omitempty"`
|
||||||
|
@ -1654,7 +1662,7 @@ type SecurityGroup struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SecurityGroupListResult is response for ListNetworkSecurityGroups Api
|
// SecurityGroupListResult is response for ListNetworkSecurityGroups Api
|
||||||
// servive call
|
// service call
|
||||||
type SecurityGroupListResult struct {
|
type SecurityGroupListResult struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
Value *[]SecurityGroup `json:"value,omitempty"`
|
Value *[]SecurityGroup `json:"value,omitempty"`
|
||||||
|
@ -1867,7 +1875,7 @@ func (client VirtualNetworkGatewayConnectionListResult) VirtualNetworkGatewayCon
|
||||||
}
|
}
|
||||||
|
|
||||||
// VirtualNetworkGatewayConnectionPropertiesFormat is
|
// VirtualNetworkGatewayConnectionPropertiesFormat is
|
||||||
// virtualNeworkGatewayConnection properties
|
// virtualNetworkGatewayConnection properties
|
||||||
type VirtualNetworkGatewayConnectionPropertiesFormat struct {
|
type VirtualNetworkGatewayConnectionPropertiesFormat struct {
|
||||||
AuthorizationKey *string `json:"authorizationKey,omitempty"`
|
AuthorizationKey *string `json:"authorizationKey,omitempty"`
|
||||||
VirtualNetworkGateway1 *VirtualNetworkGateway `json:"virtualNetworkGateway1,omitempty"`
|
VirtualNetworkGateway1 *VirtualNetworkGateway `json:"virtualNetworkGateway1,omitempty"`
|
||||||
|
@ -1923,12 +1931,13 @@ func (client VirtualNetworkGatewayListResult) VirtualNetworkGatewayListResultPre
|
||||||
autorest.WithBaseURL(to.String(client.NextLink)))
|
autorest.WithBaseURL(to.String(client.NextLink)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// VirtualNetworkGatewayPropertiesFormat is virtualNeworkGateay properties
|
// VirtualNetworkGatewayPropertiesFormat is virtualNetworkGateway properties
|
||||||
type VirtualNetworkGatewayPropertiesFormat struct {
|
type VirtualNetworkGatewayPropertiesFormat struct {
|
||||||
IPConfigurations *[]VirtualNetworkGatewayIPConfiguration `json:"ipConfigurations,omitempty"`
|
IPConfigurations *[]VirtualNetworkGatewayIPConfiguration `json:"ipConfigurations,omitempty"`
|
||||||
GatewayType VirtualNetworkGatewayType `json:"gatewayType,omitempty"`
|
GatewayType VirtualNetworkGatewayType `json:"gatewayType,omitempty"`
|
||||||
VpnType VpnType `json:"vpnType,omitempty"`
|
VpnType VpnType `json:"vpnType,omitempty"`
|
||||||
EnableBgp *bool `json:"enableBgp,omitempty"`
|
EnableBgp *bool `json:"enableBgp,omitempty"`
|
||||||
|
ActiveActive *bool `json:"activeActive,omitempty"`
|
||||||
GatewayDefaultSite *SubResource `json:"gatewayDefaultSite,omitempty"`
|
GatewayDefaultSite *SubResource `json:"gatewayDefaultSite,omitempty"`
|
||||||
Sku *VirtualNetworkGatewaySku `json:"sku,omitempty"`
|
Sku *VirtualNetworkGatewaySku `json:"sku,omitempty"`
|
||||||
VpnClientConfiguration *VpnClientConfiguration `json:"vpnClientConfiguration,omitempty"`
|
VpnClientConfiguration *VpnClientConfiguration `json:"vpnClientConfiguration,omitempty"`
|
||||||
|
@ -1944,7 +1953,7 @@ type VirtualNetworkGatewaySku struct {
|
||||||
Capacity *int32 `json:"capacity,omitempty"`
|
Capacity *int32 `json:"capacity,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// VirtualNetworkListResult is response for ListVirtualNetworks Api servive
|
// VirtualNetworkListResult is response for ListVirtualNetworks Api service
|
||||||
// call
|
// call
|
||||||
type VirtualNetworkListResult struct {
|
type VirtualNetworkListResult struct {
|
||||||
autorest.Response `json:"-"`
|
autorest.Response `json:"-"`
|
||||||
|
|
|
@ -21,12 +21,13 @@ package network
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PublicIPAddressesClient is the the Microsoft Azure Network management API
|
// PublicIPAddressesClient is the the Microsoft Azure Network management API
|
||||||
// provides a RESTful set of web services that interact with Microsoft Azure
|
// provides a RESTful set of web services that interact with Microsoft Azure
|
||||||
// Networks service to manage your network resrources. The API has entities
|
// Networks service to manage your network resources. The API has entities
|
||||||
// that capture the relationship between an end user and the Microsoft Azure
|
// that capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type PublicIPAddressesClient struct {
|
type PublicIPAddressesClient struct {
|
||||||
|
@ -54,6 +55,34 @@ func NewPublicIPAddressesClientWithBaseURI(baseURI string, subscriptionID string
|
||||||
// the name of the publicIpAddress. parameters is parameters supplied to the
|
// the name of the publicIpAddress. parameters is parameters supplied to the
|
||||||
// create/update PublicIPAddress operation
|
// create/update PublicIPAddress operation
|
||||||
func (client PublicIPAddressesClient) CreateOrUpdate(resourceGroupName string, publicIPAddressName string, parameters PublicIPAddress, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client PublicIPAddressesClient) CreateOrUpdate(resourceGroupName string, publicIPAddressName string, parameters PublicIPAddress, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.IPConfiguration", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.IPConfiguration.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.IPConfiguration.Properties.Subnet", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.IPConfiguration.Properties.Subnet.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.IPConfiguration.Properties.Subnet.Properties.NetworkSecurityGroup", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.IPConfiguration.Properties.Subnet.Properties.NetworkSecurityGroup.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"NetworkInterfaces", validation.ReadOnly, true, nil},
|
||||||
|
{"Subnets", validation.ReadOnly, true, nil},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
{"parameters.Properties.IPConfiguration.Properties.Subnet.Properties.RouteTable", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.IPConfiguration.Properties.Subnet.Properties.RouteTable.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"Subnets", validation.ReadOnly, true, nil}}},
|
||||||
|
}},
|
||||||
|
{"IPConfigurations", validation.ReadOnly, true, nil},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
{"parameters.Properties.IPConfiguration.Properties.PublicIPAddress", validation.Null, false, nil},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
{"IPConfiguration", validation.ReadOnly, true, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "network.PublicIPAddressesClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, publicIPAddressName, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, publicIPAddressName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -182,7 +211,7 @@ func (client PublicIPAddressesClient) DeleteResponder(resp *http.Response) (resu
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get publicIpAddress operation retreives information about the
|
// Get the Get publicIpAddress operation retrieves information about the
|
||||||
// specified pubicIpAddress
|
// specified pubicIpAddress
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. publicIPAddressName is
|
// resourceGroupName is the name of the resource group. publicIPAddressName is
|
||||||
|
@ -315,7 +344,7 @@ func (client PublicIPAddressesClient) ListResponder(resp *http.Response) (result
|
||||||
func (client PublicIPAddressesClient) ListNextResults(lastResults PublicIPAddressListResult) (result PublicIPAddressListResult, err error) {
|
func (client PublicIPAddressesClient) ListNextResults(lastResults PublicIPAddressListResult) (result PublicIPAddressListResult, err error) {
|
||||||
req, err := lastResults.PublicIPAddressListResultPreparer()
|
req, err := lastResults.PublicIPAddressListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -324,12 +353,12 @@ func (client PublicIPAddressesClient) ListNextResults(lastResults PublicIPAddres
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -398,7 +427,7 @@ func (client PublicIPAddressesClient) ListAllResponder(resp *http.Response) (res
|
||||||
func (client PublicIPAddressesClient) ListAllNextResults(lastResults PublicIPAddressListResult) (result PublicIPAddressListResult, err error) {
|
func (client PublicIPAddressesClient) ListAllNextResults(lastResults PublicIPAddressListResult) (result PublicIPAddressListResult, err error) {
|
||||||
req, err := lastResults.PublicIPAddressListResultPreparer()
|
req, err := lastResults.PublicIPAddressListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -407,12 +436,12 @@ func (client PublicIPAddressesClient) ListAllNextResults(lastResults PublicIPAdd
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
// RoutesClient is the the Microsoft Azure Network management API provides a
|
// RoutesClient is the the Microsoft Azure Network management API provides a
|
||||||
// RESTful set of web services that interact with Microsoft Azure Networks
|
// RESTful set of web services that interact with Microsoft Azure Networks
|
||||||
// service to manage your network resrources. The API has entities that
|
// service to manage your network resources. The API has entities that
|
||||||
// capture the relationship between an end user and the Microsoft Azure
|
// capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type RoutesClient struct {
|
type RoutesClient struct {
|
||||||
|
@ -50,7 +50,8 @@ func NewRoutesClientWithBaseURI(baseURI string, subscriptionID string) RoutesCli
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. routeTableName is the
|
// resourceGroupName is the name of the resource group. routeTableName is the
|
||||||
// name of the route table. routeName is the name of the route.
|
// name of the route table. routeName is the name of the route.
|
||||||
// routeParameters is parameters supplied to the create/update routeoperation
|
// routeParameters is parameters supplied to the create/update route
|
||||||
|
// operation
|
||||||
func (client RoutesClient) CreateOrUpdate(resourceGroupName string, routeTableName string, routeName string, routeParameters Route, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client RoutesClient) CreateOrUpdate(resourceGroupName string, routeTableName string, routeName string, routeParameters Route, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, routeTableName, routeName, routeParameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, routeTableName, routeName, routeParameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -182,7 +183,7 @@ func (client RoutesClient) DeleteResponder(resp *http.Response) (result autorest
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get route operation retreives information about the specified route
|
// Get the Get route operation retrieves information about the specified route
|
||||||
// from the route table.
|
// from the route table.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. routeTableName is the
|
// resourceGroupName is the name of the resource group. routeTableName is the
|
||||||
|
@ -315,7 +316,7 @@ func (client RoutesClient) ListResponder(resp *http.Response) (result RouteListR
|
||||||
func (client RoutesClient) ListNextResults(lastResults RouteListResult) (result RouteListResult, err error) {
|
func (client RoutesClient) ListNextResults(lastResults RouteListResult) (result RouteListResult, err error) {
|
||||||
req, err := lastResults.RouteListResultPreparer()
|
req, err := lastResults.RouteListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.RoutesClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.RoutesClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -324,12 +325,12 @@ func (client RoutesClient) ListNextResults(lastResults RouteListResult) (result
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.RoutesClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.RoutesClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.RoutesClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.RoutesClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,12 +21,13 @@ package network
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RouteTablesClient is the the Microsoft Azure Network management API
|
// RouteTablesClient is the the Microsoft Azure Network management API
|
||||||
// provides a RESTful set of web services that interact with Microsoft Azure
|
// provides a RESTful set of web services that interact with Microsoft Azure
|
||||||
// Networks service to manage your network resrources. The API has entities
|
// Networks service to manage your network resources. The API has entities
|
||||||
// that capture the relationship between an end user and the Microsoft Azure
|
// that capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type RouteTablesClient struct {
|
type RouteTablesClient struct {
|
||||||
|
@ -44,15 +45,22 @@ func NewRouteTablesClientWithBaseURI(baseURI string, subscriptionID string) Rout
|
||||||
return RouteTablesClient{NewWithBaseURI(baseURI, subscriptionID)}
|
return RouteTablesClient{NewWithBaseURI(baseURI, subscriptionID)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrUpdate the Put RouteTable operation creates/updates a route tablein
|
// CreateOrUpdate the Put RouteTable operation creates/updates a route table
|
||||||
// the specified resource group. This method may poll for completion. Polling
|
// in the specified resource group. This method may poll for completion.
|
||||||
// can be canceled by passing the cancel channel argument. The channel will
|
// Polling can be canceled by passing the cancel channel argument. The
|
||||||
// be used to cancel polling and any outstanding HTTP requests.
|
// channel will be used to cancel polling and any outstanding HTTP requests.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. routeTableName is the
|
// resourceGroupName is the name of the resource group. routeTableName is the
|
||||||
// name of the route table. parameters is parameters supplied to the
|
// name of the route table. parameters is parameters supplied to the
|
||||||
// create/update Route Table operation
|
// create/update Route Table operation
|
||||||
func (client RouteTablesClient) CreateOrUpdate(resourceGroupName string, routeTableName string, parameters RouteTable, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client RouteTablesClient) CreateOrUpdate(resourceGroupName string, routeTableName string, parameters RouteTable, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"Subnets", validation.ReadOnly, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "network.RouteTablesClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, routeTableName, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, routeTableName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -114,7 +122,7 @@ func (client RouteTablesClient) CreateOrUpdateResponder(resp *http.Response) (re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the Delete RouteTable operation deletes the specifed Route Table
|
// Delete the Delete RouteTable operation deletes the specified Route Table
|
||||||
// This method may poll for completion. Polling can be canceled by passing
|
// This method may poll for completion. Polling can be canceled by passing
|
||||||
// the cancel channel argument. The channel will be used to cancel polling
|
// the cancel channel argument. The channel will be used to cancel polling
|
||||||
// and any outstanding HTTP requests.
|
// and any outstanding HTTP requests.
|
||||||
|
@ -313,7 +321,7 @@ func (client RouteTablesClient) ListResponder(resp *http.Response) (result Route
|
||||||
func (client RouteTablesClient) ListNextResults(lastResults RouteTableListResult) (result RouteTableListResult, err error) {
|
func (client RouteTablesClient) ListNextResults(lastResults RouteTableListResult) (result RouteTableListResult, err error) {
|
||||||
req, err := lastResults.RouteTableListResultPreparer()
|
req, err := lastResults.RouteTableListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -322,12 +330,12 @@ func (client RouteTablesClient) ListNextResults(lastResults RouteTableListResult
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -395,7 +403,7 @@ func (client RouteTablesClient) ListAllResponder(resp *http.Response) (result Ro
|
||||||
func (client RouteTablesClient) ListAllNextResults(lastResults RouteTableListResult) (result RouteTableListResult, err error) {
|
func (client RouteTablesClient) ListAllNextResults(lastResults RouteTableListResult) (result RouteTableListResult, err error) {
|
||||||
req, err := lastResults.RouteTableListResultPreparer()
|
req, err := lastResults.RouteTableListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -404,12 +412,12 @@ func (client RouteTablesClient) ListAllNextResults(lastResults RouteTableListRes
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.RouteTablesClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,12 +21,13 @@ package network
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SecurityGroupsClient is the the Microsoft Azure Network management API
|
// SecurityGroupsClient is the the Microsoft Azure Network management API
|
||||||
// provides a RESTful set of web services that interact with Microsoft Azure
|
// provides a RESTful set of web services that interact with Microsoft Azure
|
||||||
// Networks service to manage your network resrources. The API has entities
|
// Networks service to manage your network resources. The API has entities
|
||||||
// that capture the relationship between an end user and the Microsoft Azure
|
// that capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type SecurityGroupsClient struct {
|
type SecurityGroupsClient struct {
|
||||||
|
@ -46,7 +47,7 @@ func NewSecurityGroupsClientWithBaseURI(baseURI string, subscriptionID string) S
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrUpdate the Put NetworkSecurityGroup operation creates/updates a
|
// CreateOrUpdate the Put NetworkSecurityGroup operation creates/updates a
|
||||||
// network security groupin the specified resource group. This method may
|
// network security group in the specified resource group. This method may
|
||||||
// poll for completion. Polling can be canceled by passing the cancel channel
|
// poll for completion. Polling can be canceled by passing the cancel channel
|
||||||
// argument. The channel will be used to cancel polling and any outstanding
|
// argument. The channel will be used to cancel polling and any outstanding
|
||||||
// HTTP requests.
|
// HTTP requests.
|
||||||
|
@ -56,6 +57,15 @@ func NewSecurityGroupsClientWithBaseURI(baseURI string, subscriptionID string) S
|
||||||
// parameters is parameters supplied to the create/update Network Security
|
// parameters is parameters supplied to the create/update Network Security
|
||||||
// Group operation
|
// Group operation
|
||||||
func (client SecurityGroupsClient) CreateOrUpdate(resourceGroupName string, networkSecurityGroupName string, parameters SecurityGroup, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client SecurityGroupsClient) CreateOrUpdate(resourceGroupName string, networkSecurityGroupName string, parameters SecurityGroup, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"NetworkInterfaces", validation.ReadOnly, true, nil},
|
||||||
|
{"Subnets", validation.ReadOnly, true, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "network.SecurityGroupsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, networkSecurityGroupName, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, networkSecurityGroupName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -117,7 +127,7 @@ func (client SecurityGroupsClient) CreateOrUpdateResponder(resp *http.Response)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the Delete NetworkSecurityGroup operation deletes the specifed
|
// Delete the Delete NetworkSecurityGroup operation deletes the specified
|
||||||
// network security group This method may poll for completion. Polling can be
|
// network security group This method may poll for completion. Polling can be
|
||||||
// canceled by passing the cancel channel argument. The channel will be used
|
// canceled by passing the cancel channel argument. The channel will be used
|
||||||
// to cancel polling and any outstanding HTTP requests.
|
// to cancel polling and any outstanding HTTP requests.
|
||||||
|
@ -318,7 +328,7 @@ func (client SecurityGroupsClient) ListResponder(resp *http.Response) (result Se
|
||||||
func (client SecurityGroupsClient) ListNextResults(lastResults SecurityGroupListResult) (result SecurityGroupListResult, err error) {
|
func (client SecurityGroupsClient) ListNextResults(lastResults SecurityGroupListResult) (result SecurityGroupListResult, err error) {
|
||||||
req, err := lastResults.SecurityGroupListResultPreparer()
|
req, err := lastResults.SecurityGroupListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -327,12 +337,12 @@ func (client SecurityGroupsClient) ListNextResults(lastResults SecurityGroupList
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -401,7 +411,7 @@ func (client SecurityGroupsClient) ListAllResponder(resp *http.Response) (result
|
||||||
func (client SecurityGroupsClient) ListAllNextResults(lastResults SecurityGroupListResult) (result SecurityGroupListResult, err error) {
|
func (client SecurityGroupsClient) ListAllNextResults(lastResults SecurityGroupListResult) (result SecurityGroupListResult, err error) {
|
||||||
req, err := lastResults.SecurityGroupListResultPreparer()
|
req, err := lastResults.SecurityGroupListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -410,12 +420,12 @@ func (client SecurityGroupsClient) ListAllNextResults(lastResults SecurityGroupL
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.SecurityGroupsClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,12 +21,13 @@ package network
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SecurityRulesClient is the the Microsoft Azure Network management API
|
// SecurityRulesClient is the the Microsoft Azure Network management API
|
||||||
// provides a RESTful set of web services that interact with Microsoft Azure
|
// provides a RESTful set of web services that interact with Microsoft Azure
|
||||||
// Networks service to manage your network resrources. The API has entities
|
// Networks service to manage your network resources. The API has entities
|
||||||
// that capture the relationship between an end user and the Microsoft Azure
|
// that capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type SecurityRulesClient struct {
|
type SecurityRulesClient struct {
|
||||||
|
@ -57,6 +58,15 @@ func NewSecurityRulesClientWithBaseURI(baseURI string, subscriptionID string) Se
|
||||||
// is parameters supplied to the create/update network security rule
|
// is parameters supplied to the create/update network security rule
|
||||||
// operation
|
// operation
|
||||||
func (client SecurityRulesClient) CreateOrUpdate(resourceGroupName string, networkSecurityGroupName string, securityRuleName string, securityRuleParameters SecurityRule, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client SecurityRulesClient) CreateOrUpdate(resourceGroupName string, networkSecurityGroupName string, securityRuleName string, securityRuleParameters SecurityRule, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{securityRuleParameters,
|
||||||
|
[]validation.Constraint{{"securityRuleParameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"securityRuleParameters.Properties.SourceAddressPrefix", validation.Null, true, nil},
|
||||||
|
{"securityRuleParameters.Properties.DestinationAddressPrefix", validation.Null, true, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "network.SecurityRulesClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, networkSecurityGroupName, securityRuleName, securityRuleParameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, networkSecurityGroupName, securityRuleName, securityRuleParameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.SecurityRulesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "network.SecurityRulesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -188,7 +198,7 @@ func (client SecurityRulesClient) DeleteResponder(resp *http.Response) (result a
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get NetworkSecurityRule operation retreives information about the
|
// Get the Get NetworkSecurityRule operation retrieves information about the
|
||||||
// specified network security rule.
|
// specified network security rule.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group.
|
// resourceGroupName is the name of the resource group.
|
||||||
|
@ -322,7 +332,7 @@ func (client SecurityRulesClient) ListResponder(resp *http.Response) (result Sec
|
||||||
func (client SecurityRulesClient) ListNextResults(lastResults SecurityRuleListResult) (result SecurityRuleListResult, err error) {
|
func (client SecurityRulesClient) ListNextResults(lastResults SecurityRuleListResult) (result SecurityRuleListResult, err error) {
|
||||||
req, err := lastResults.SecurityRuleListResultPreparer()
|
req, err := lastResults.SecurityRuleListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.SecurityRulesClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.SecurityRulesClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -331,12 +341,12 @@ func (client SecurityRulesClient) ListNextResults(lastResults SecurityRuleListRe
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.SecurityRulesClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.SecurityRulesClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.SecurityRulesClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.SecurityRulesClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,12 +21,13 @@ package network
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SubnetsClient is the the Microsoft Azure Network management API provides a
|
// SubnetsClient is the the Microsoft Azure Network management API provides a
|
||||||
// RESTful set of web services that interact with Microsoft Azure Networks
|
// RESTful set of web services that interact with Microsoft Azure Networks
|
||||||
// service to manage your network resrources. The API has entities that
|
// service to manage your network resources. The API has entities that
|
||||||
// capture the relationship between an end user and the Microsoft Azure
|
// capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type SubnetsClient struct {
|
type SubnetsClient struct {
|
||||||
|
@ -43,16 +44,34 @@ func NewSubnetsClientWithBaseURI(baseURI string, subscriptionID string) SubnetsC
|
||||||
return SubnetsClient{NewWithBaseURI(baseURI, subscriptionID)}
|
return SubnetsClient{NewWithBaseURI(baseURI, subscriptionID)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrUpdate the Put Subnet operation creates/updates a subnet in
|
// CreateOrUpdate the Put Subnet operation creates/updates a subnet in the
|
||||||
// thespecified virtual network This method may poll for completion. Polling
|
// specified virtual network This method may poll for completion. Polling can
|
||||||
// can be canceled by passing the cancel channel argument. The channel will
|
// be canceled by passing the cancel channel argument. The channel will be
|
||||||
// be used to cancel polling and any outstanding HTTP requests.
|
// used to cancel polling and any outstanding HTTP requests.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. virtualNetworkName is
|
// resourceGroupName is the name of the resource group. virtualNetworkName is
|
||||||
// the name of the virtual network. subnetName is the name of the subnet.
|
// the name of the virtual network. subnetName is the name of the subnet.
|
||||||
// subnetParameters is parameters supplied to the create/update Subnet
|
// subnetParameters is parameters supplied to the create/update Subnet
|
||||||
// operation
|
// operation
|
||||||
func (client SubnetsClient) CreateOrUpdate(resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters Subnet, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client SubnetsClient) CreateOrUpdate(resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters Subnet, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{subnetParameters,
|
||||||
|
[]validation.Constraint{{"subnetParameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"subnetParameters.Properties.NetworkSecurityGroup", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"subnetParameters.Properties.NetworkSecurityGroup.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"NetworkInterfaces", validation.ReadOnly, true, nil},
|
||||||
|
{"Subnets", validation.ReadOnly, true, nil},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
{"subnetParameters.Properties.RouteTable", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"subnetParameters.Properties.RouteTable.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"Subnets", validation.ReadOnly, true, nil}}},
|
||||||
|
}},
|
||||||
|
{"IPConfigurations", validation.ReadOnly, true, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "network.SubnetsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, virtualNetworkName, subnetName, subnetParameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, virtualNetworkName, subnetName, subnetParameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.SubnetsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "network.SubnetsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -183,7 +202,7 @@ func (client SubnetsClient) DeleteResponder(resp *http.Response) (result autores
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get subnet operation retreives information about the specified
|
// Get the Get subnet operation retrieves information about the specified
|
||||||
// subnet.
|
// subnet.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. virtualNetworkName is
|
// resourceGroupName is the name of the resource group. virtualNetworkName is
|
||||||
|
@ -320,7 +339,7 @@ func (client SubnetsClient) ListResponder(resp *http.Response) (result SubnetLis
|
||||||
func (client SubnetsClient) ListNextResults(lastResults SubnetListResult) (result SubnetListResult, err error) {
|
func (client SubnetsClient) ListNextResults(lastResults SubnetListResult) (result SubnetListResult, err error) {
|
||||||
req, err := lastResults.SubnetListResultPreparer()
|
req, err := lastResults.SubnetListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.SubnetsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.SubnetsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -329,12 +348,12 @@ func (client SubnetsClient) ListNextResults(lastResults SubnetListResult) (resul
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.SubnetsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.SubnetsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.SubnetsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.SubnetsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,12 +21,13 @@ package network
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UsagesClient is the the Microsoft Azure Network management API provides a
|
// UsagesClient is the the Microsoft Azure Network management API provides a
|
||||||
// RESTful set of web services that interact with Microsoft Azure Networks
|
// RESTful set of web services that interact with Microsoft Azure Networks
|
||||||
// service to manage your network resrources. The API has entities that
|
// service to manage your network resources. The API has entities that
|
||||||
// capture the relationship between an end user and the Microsoft Azure
|
// capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type UsagesClient struct {
|
type UsagesClient struct {
|
||||||
|
@ -47,6 +48,12 @@ func NewUsagesClientWithBaseURI(baseURI string, subscriptionID string) UsagesCli
|
||||||
//
|
//
|
||||||
// location is the location upon which resource usage is queried.
|
// location is the location upon which resource usage is queried.
|
||||||
func (client UsagesClient) List(location string) (result UsagesListResult, err error) {
|
func (client UsagesClient) List(location string) (result UsagesListResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{location,
|
||||||
|
[]validation.Constraint{{"location", validation.Pattern, `^[-\w\._]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "network.UsagesClient", "List")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListPreparer(location)
|
req, err := client.ListPreparer(location)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.UsagesClient", "List", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "network.UsagesClient", "List", nil, "Failure preparing request")
|
||||||
|
@ -108,7 +115,7 @@ func (client UsagesClient) ListResponder(resp *http.Response) (result UsagesList
|
||||||
func (client UsagesClient) ListNextResults(lastResults UsagesListResult) (result UsagesListResult, err error) {
|
func (client UsagesClient) ListNextResults(lastResults UsagesListResult) (result UsagesListResult, err error) {
|
||||||
req, err := lastResults.UsagesListResultPreparer()
|
req, err := lastResults.UsagesListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.UsagesClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.UsagesClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -117,12 +124,12 @@ func (client UsagesClient) ListNextResults(lastResults UsagesListResult) (result
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.UsagesClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.UsagesClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.UsagesClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.UsagesClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
major = "3"
|
major = "4"
|
||||||
minor = "2"
|
minor = "0"
|
||||||
patch = "0"
|
patch = "0"
|
||||||
// Always begin a "tag" with a dash (as per http://semver.org)
|
// Always begin a "tag" with a dash (as per http://semver.org)
|
||||||
tag = "-beta"
|
tag = "-beta"
|
||||||
|
|
16
vendor/github.com/Azure/azure-sdk-for-go/arm/network/virtualnetworkgatewayconnections.go
generated
vendored
16
vendor/github.com/Azure/azure-sdk-for-go/arm/network/virtualnetworkgatewayconnections.go
generated
vendored
|
@ -26,8 +26,8 @@ import (
|
||||||
|
|
||||||
// VirtualNetworkGatewayConnectionsClient is the the Microsoft Azure Network
|
// VirtualNetworkGatewayConnectionsClient is the the Microsoft Azure Network
|
||||||
// management API provides a RESTful set of web services that interact with
|
// management API provides a RESTful set of web services that interact with
|
||||||
// Microsoft Azure Networks service to manage your network resrources. The
|
// Microsoft Azure Networks service to manage your network resources. The API
|
||||||
// API has entities that capture the relationship between an end user and the
|
// has entities that capture the relationship between an end user and the
|
||||||
// Microsoft Azure Networks service.
|
// Microsoft Azure Networks service.
|
||||||
type VirtualNetworkGatewayConnectionsClient struct {
|
type VirtualNetworkGatewayConnectionsClient struct {
|
||||||
ManagementClient
|
ManagementClient
|
||||||
|
@ -54,7 +54,7 @@ func NewVirtualNetworkGatewayConnectionsClientWithBaseURI(baseURI string, subscr
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group.
|
// resourceGroupName is the name of the resource group.
|
||||||
// virtualNetworkGatewayConnectionName is the name of the virtual network
|
// virtualNetworkGatewayConnectionName is the name of the virtual network
|
||||||
// gateway conenction. parameters is parameters supplied to the Begin Create
|
// gateway connection. parameters is parameters supplied to the Begin Create
|
||||||
// or update Virtual Network Gateway connection operation through Network
|
// or update Virtual Network Gateway connection operation through Network
|
||||||
// resource provider.
|
// resource provider.
|
||||||
func (client VirtualNetworkGatewayConnectionsClient) CreateOrUpdate(resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters VirtualNetworkGatewayConnection, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client VirtualNetworkGatewayConnectionsClient) CreateOrUpdate(resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters VirtualNetworkGatewayConnection, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
@ -120,7 +120,7 @@ func (client VirtualNetworkGatewayConnectionsClient) CreateOrUpdateResponder(res
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the Delete VirtualNetworkGatewayConnection operation deletes the
|
// Delete the Delete VirtualNetworkGatewayConnection operation deletes the
|
||||||
// specifed virtual network Gateway connection through Network resource
|
// specified virtual network Gateway connection through Network resource
|
||||||
// provider. This method may poll for completion. Polling can be canceled by
|
// provider. This method may poll for completion. Polling can be canceled by
|
||||||
// passing the cancel channel argument. The channel will be used to cancel
|
// passing the cancel channel argument. The channel will be used to cancel
|
||||||
// polling and any outstanding HTTP requests.
|
// polling and any outstanding HTTP requests.
|
||||||
|
@ -386,7 +386,7 @@ func (client VirtualNetworkGatewayConnectionsClient) ListResponder(resp *http.Re
|
||||||
func (client VirtualNetworkGatewayConnectionsClient) ListNextResults(lastResults VirtualNetworkGatewayConnectionListResult) (result VirtualNetworkGatewayConnectionListResult, err error) {
|
func (client VirtualNetworkGatewayConnectionsClient) ListNextResults(lastResults VirtualNetworkGatewayConnectionListResult) (result VirtualNetworkGatewayConnectionListResult, err error) {
|
||||||
req, err := lastResults.VirtualNetworkGatewayConnectionListResultPreparer()
|
req, err := lastResults.VirtualNetworkGatewayConnectionListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewayConnectionsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewayConnectionsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -395,12 +395,12 @@ func (client VirtualNetworkGatewayConnectionsClient) ListNextResults(lastResults
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewayConnectionsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewayConnectionsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewayConnectionsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewayConnectionsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -490,7 +490,7 @@ func (client VirtualNetworkGatewayConnectionsClient) ResetSharedKeyResponder(res
|
||||||
// resourceGroupName is the name of the resource group.
|
// resourceGroupName is the name of the resource group.
|
||||||
// virtualNetworkGatewayConnectionName is the virtual network gateway
|
// virtualNetworkGatewayConnectionName is the virtual network gateway
|
||||||
// connection name. parameters is parameters supplied to the Begin Set
|
// connection name. parameters is parameters supplied to the Begin Set
|
||||||
// Virtual Network Gateway conection Shared key operation throughNetwork
|
// Virtual Network Gateway connection Shared key operation throughNetwork
|
||||||
// resource provider.
|
// resource provider.
|
||||||
func (client VirtualNetworkGatewayConnectionsClient) SetSharedKey(resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters ConnectionSharedKey, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client VirtualNetworkGatewayConnectionsClient) SetSharedKey(resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters ConnectionSharedKey, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
req, err := client.SetSharedKeyPreparer(resourceGroupName, virtualNetworkGatewayConnectionName, parameters, cancel)
|
req, err := client.SetSharedKeyPreparer(resourceGroupName, virtualNetworkGatewayConnectionName, parameters, cancel)
|
||||||
|
|
10
vendor/github.com/Azure/azure-sdk-for-go/arm/network/virtualnetworkgateways.go
generated
vendored
10
vendor/github.com/Azure/azure-sdk-for-go/arm/network/virtualnetworkgateways.go
generated
vendored
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
// VirtualNetworkGatewaysClient is the the Microsoft Azure Network management
|
// VirtualNetworkGatewaysClient is the the Microsoft Azure Network management
|
||||||
// API provides a RESTful set of web services that interact with Microsoft
|
// API provides a RESTful set of web services that interact with Microsoft
|
||||||
// Azure Networks service to manage your network resrources. The API has
|
// Azure Networks service to manage your network resources. The API has
|
||||||
// entities that capture the relationship between an end user and the
|
// entities that capture the relationship between an end user and the
|
||||||
// Microsoft Azure Networks service.
|
// Microsoft Azure Networks service.
|
||||||
type VirtualNetworkGatewaysClient struct {
|
type VirtualNetworkGatewaysClient struct {
|
||||||
|
@ -117,7 +117,7 @@ func (client VirtualNetworkGatewaysClient) CreateOrUpdateResponder(resp *http.Re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the Delete VirtualNetworkGateway operation deletes the specifed
|
// Delete the Delete VirtualNetworkGateway operation deletes the specified
|
||||||
// virtual network Gateway through Network resource provider. This method may
|
// virtual network Gateway through Network resource provider. This method may
|
||||||
// poll for completion. Polling can be canceled by passing the cancel channel
|
// poll for completion. Polling can be canceled by passing the cancel channel
|
||||||
// argument. The channel will be used to cancel polling and any outstanding
|
// argument. The channel will be used to cancel polling and any outstanding
|
||||||
|
@ -384,7 +384,7 @@ func (client VirtualNetworkGatewaysClient) ListResponder(resp *http.Response) (r
|
||||||
func (client VirtualNetworkGatewaysClient) ListNextResults(lastResults VirtualNetworkGatewayListResult) (result VirtualNetworkGatewayListResult, err error) {
|
func (client VirtualNetworkGatewaysClient) ListNextResults(lastResults VirtualNetworkGatewayListResult) (result VirtualNetworkGatewayListResult, err error) {
|
||||||
req, err := lastResults.VirtualNetworkGatewayListResultPreparer()
|
req, err := lastResults.VirtualNetworkGatewayListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -393,12 +393,12 @@ func (client VirtualNetworkGatewaysClient) ListNextResults(lastResults VirtualNe
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.VirtualNetworkGatewaysClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
10
vendor/github.com/Azure/azure-sdk-for-go/arm/network/virtualnetworkpeerings.go
generated
vendored
10
vendor/github.com/Azure/azure-sdk-for-go/arm/network/virtualnetworkpeerings.go
generated
vendored
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
// VirtualNetworkPeeringsClient is the the Microsoft Azure Network management
|
// VirtualNetworkPeeringsClient is the the Microsoft Azure Network management
|
||||||
// API provides a RESTful set of web services that interact with Microsoft
|
// API provides a RESTful set of web services that interact with Microsoft
|
||||||
// Azure Networks service to manage your network resrources. The API has
|
// Azure Networks service to manage your network resources. The API has
|
||||||
// entities that capture the relationship between an end user and the
|
// entities that capture the relationship between an end user and the
|
||||||
// Microsoft Azure Networks service.
|
// Microsoft Azure Networks service.
|
||||||
type VirtualNetworkPeeringsClient struct {
|
type VirtualNetworkPeeringsClient struct {
|
||||||
|
@ -187,7 +187,7 @@ func (client VirtualNetworkPeeringsClient) DeleteResponder(resp *http.Response)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Get virtual network peering operation retreives information about
|
// Get the Get virtual network peering operation retrieves information about
|
||||||
// the specified virtual network peering.
|
// the specified virtual network peering.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. virtualNetworkName is
|
// resourceGroupName is the name of the resource group. virtualNetworkName is
|
||||||
|
@ -321,7 +321,7 @@ func (client VirtualNetworkPeeringsClient) ListResponder(resp *http.Response) (r
|
||||||
func (client VirtualNetworkPeeringsClient) ListNextResults(lastResults VirtualNetworkPeeringListResult) (result VirtualNetworkPeeringListResult, err error) {
|
func (client VirtualNetworkPeeringsClient) ListNextResults(lastResults VirtualNetworkPeeringListResult) (result VirtualNetworkPeeringListResult, err error) {
|
||||||
req, err := lastResults.VirtualNetworkPeeringListResultPreparer()
|
req, err := lastResults.VirtualNetworkPeeringListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkPeeringsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkPeeringsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -330,12 +330,12 @@ func (client VirtualNetworkPeeringsClient) ListNextResults(lastResults VirtualNe
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkPeeringsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworkPeeringsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.VirtualNetworkPeeringsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.VirtualNetworkPeeringsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
// VirtualNetworksClient is the the Microsoft Azure Network management API
|
// VirtualNetworksClient is the the Microsoft Azure Network management API
|
||||||
// provides a RESTful set of web services that interact with Microsoft Azure
|
// provides a RESTful set of web services that interact with Microsoft Azure
|
||||||
// Networks service to manage your network resrources. The API has entities
|
// Networks service to manage your network resources. The API has entities
|
||||||
// that capture the relationship between an end user and the Microsoft Azure
|
// that capture the relationship between an end user and the Microsoft Azure
|
||||||
// Networks service.
|
// Networks service.
|
||||||
type VirtualNetworksClient struct {
|
type VirtualNetworksClient struct {
|
||||||
|
@ -184,7 +184,7 @@ func (client VirtualNetworksClient) CreateOrUpdateResponder(resp *http.Response)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the Delete VirtualNetwork operation deletes the specifed virtual
|
// Delete the Delete VirtualNetwork operation deletes the specified virtual
|
||||||
// network This method may poll for completion. Polling can be canceled by
|
// network This method may poll for completion. Polling can be canceled by
|
||||||
// passing the cancel channel argument. The channel will be used to cancel
|
// passing the cancel channel argument. The channel will be used to cancel
|
||||||
// polling and any outstanding HTTP requests.
|
// polling and any outstanding HTTP requests.
|
||||||
|
@ -384,7 +384,7 @@ func (client VirtualNetworksClient) ListResponder(resp *http.Response) (result V
|
||||||
func (client VirtualNetworksClient) ListNextResults(lastResults VirtualNetworkListResult) (result VirtualNetworkListResult, err error) {
|
func (client VirtualNetworksClient) ListNextResults(lastResults VirtualNetworkListResult) (result VirtualNetworkListResult, err error) {
|
||||||
req, err := lastResults.VirtualNetworkListResultPreparer()
|
req, err := lastResults.VirtualNetworkListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -393,12 +393,12 @@ func (client VirtualNetworksClient) ListNextResults(lastResults VirtualNetworkLi
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -467,7 +467,7 @@ func (client VirtualNetworksClient) ListAllResponder(resp *http.Response) (resul
|
||||||
func (client VirtualNetworksClient) ListAllNextResults(lastResults VirtualNetworkListResult) (result VirtualNetworkListResult, err error) {
|
func (client VirtualNetworksClient) ListAllNextResults(lastResults VirtualNetworkListResult) (result VirtualNetworkListResult, err error) {
|
||||||
req, err := lastResults.VirtualNetworkListResultPreparer()
|
req, err := lastResults.VirtualNetworkListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -476,12 +476,12 @@ func (client VirtualNetworksClient) ListAllNextResults(lastResults VirtualNetwor
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -24,6 +24,7 @@ package resources
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,6 +66,14 @@ func NewWithBaseURI(baseURI string, subscriptionID string) ManagementClient {
|
||||||
// parentResourcePath is resource identity. resourceType is resource
|
// parentResourcePath is resource identity. resourceType is resource
|
||||||
// identity. resourceName is resource identity.
|
// identity. resourceName is resource identity.
|
||||||
func (client ManagementClient) CheckExistence(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) {
|
func (client ManagementClient) CheckExistence(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.ManagementClient", "CheckExistence")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CheckExistencePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
req, err := client.CheckExistencePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "CheckExistence", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "CheckExistence", nil, "Failure preparing request")
|
||||||
|
@ -133,6 +142,19 @@ func (client ManagementClient) CheckExistenceResponder(resp *http.Response) (res
|
||||||
// identity. resourceName is resource identity. parameters is create or
|
// identity. resourceName is resource identity. parameters is create or
|
||||||
// update resource parameters.
|
// update resource parameters.
|
||||||
func (client ManagementClient) CreateOrUpdate(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters GenericResource) (result GenericResource, err error) {
|
func (client ManagementClient) CreateOrUpdate(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters GenericResource) (result GenericResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}},
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Identity", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"PrincipalID", validation.ReadOnly, true, nil},
|
||||||
|
{"TenantID", validation.ReadOnly, true, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.ManagementClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -203,6 +225,14 @@ func (client ManagementClient) CreateOrUpdateResponder(resp *http.Response) (res
|
||||||
// parentResourcePath is resource identity. resourceType is resource
|
// parentResourcePath is resource identity. resourceType is resource
|
||||||
// identity. resourceName is resource identity.
|
// identity. resourceName is resource identity.
|
||||||
func (client ManagementClient) Delete(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) {
|
func (client ManagementClient) Delete(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.ManagementClient", "Delete")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.DeletePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
req, err := client.DeletePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "Delete", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "Delete", nil, "Failure preparing request")
|
||||||
|
@ -270,6 +300,14 @@ func (client ManagementClient) DeleteResponder(resp *http.Response) (result auto
|
||||||
// parentResourcePath is resource identity. resourceType is resource
|
// parentResourcePath is resource identity. resourceType is resource
|
||||||
// identity. resourceName is resource identity.
|
// identity. resourceName is resource identity.
|
||||||
func (client ManagementClient) Get(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result GenericResource, err error) {
|
func (client ManagementClient) Get(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result GenericResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.ManagementClient", "Get")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.GetPreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
req, err := client.GetPreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "Get", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "Get", nil, "Failure preparing request")
|
||||||
|
@ -406,7 +444,7 @@ func (client ManagementClient) ListResponder(resp *http.Response) (result Resour
|
||||||
func (client ManagementClient) ListNextResults(lastResults ResourceListResult) (result ResourceListResult, err error) {
|
func (client ManagementClient) ListNextResults(lastResults ResourceListResult) (result ResourceListResult, err error) {
|
||||||
req, err := lastResults.ResourceListResultPreparer()
|
req, err := lastResults.ResourceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -415,12 +453,12 @@ func (client ManagementClient) ListNextResults(lastResults ResourceListResult) (
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "resources.ManagementClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "resources.ManagementClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -435,6 +473,14 @@ func (client ManagementClient) ListNextResults(lastResults ResourceListResult) (
|
||||||
// sourceResourceGroupName is source resource group name. parameters is move
|
// sourceResourceGroupName is source resource group name. parameters is move
|
||||||
// resources' parameters.
|
// resources' parameters.
|
||||||
func (client ManagementClient) MoveResources(sourceResourceGroupName string, parameters MoveInfo, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client ManagementClient) MoveResources(sourceResourceGroupName string, parameters MoveInfo, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{sourceResourceGroupName,
|
||||||
|
[]validation.Constraint{{"sourceResourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"sourceResourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"sourceResourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.ManagementClient", "MoveResources")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.MoveResourcesPreparer(sourceResourceGroupName, parameters, cancel)
|
req, err := client.MoveResourcesPreparer(sourceResourceGroupName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "MoveResources", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.ManagementClient", "MoveResources", nil, "Failure preparing request")
|
||||||
|
|
23
vendor/github.com/Azure/azure-sdk-for-go/arm/resources/resources/deploymentoperations.go
generated
vendored
23
vendor/github.com/Azure/azure-sdk-for-go/arm/resources/resources/deploymentoperations.go
generated
vendored
|
@ -21,6 +21,7 @@ package resources
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,6 +49,14 @@ func NewDeploymentOperationsClientWithBaseURI(baseURI string, subscriptionID str
|
||||||
// insensitive. deploymentName is the name of the deployment. operationID is
|
// insensitive. deploymentName is the name of the deployment. operationID is
|
||||||
// operation Id.
|
// operation Id.
|
||||||
func (client DeploymentOperationsClient) Get(resourceGroupName string, deploymentName string, operationID string) (result DeploymentOperation, err error) {
|
func (client DeploymentOperationsClient) Get(resourceGroupName string, deploymentName string, operationID string) (result DeploymentOperation, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentOperationsClient", "Get")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.GetPreparer(resourceGroupName, deploymentName, operationID)
|
req, err := client.GetPreparer(resourceGroupName, deploymentName, operationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "Get", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "Get", nil, "Failure preparing request")
|
||||||
|
@ -113,6 +122,14 @@ func (client DeploymentOperationsClient) GetResponder(resp *http.Response) (resu
|
||||||
// insensitive. deploymentName is the name of the deployment. top is query
|
// insensitive. deploymentName is the name of the deployment. top is query
|
||||||
// parameters.
|
// parameters.
|
||||||
func (client DeploymentOperationsClient) List(resourceGroupName string, deploymentName string, top *int32) (result DeploymentOperationsListResult, err error) {
|
func (client DeploymentOperationsClient) List(resourceGroupName string, deploymentName string, top *int32) (result DeploymentOperationsListResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentOperationsClient", "List")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListPreparer(resourceGroupName, deploymentName, top)
|
req, err := client.ListPreparer(resourceGroupName, deploymentName, top)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "List", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "List", nil, "Failure preparing request")
|
||||||
|
@ -178,7 +195,7 @@ func (client DeploymentOperationsClient) ListResponder(resp *http.Response) (res
|
||||||
func (client DeploymentOperationsClient) ListNextResults(lastResults DeploymentOperationsListResult) (result DeploymentOperationsListResult, err error) {
|
func (client DeploymentOperationsClient) ListNextResults(lastResults DeploymentOperationsListResult) (result DeploymentOperationsListResult, err error) {
|
||||||
req, err := lastResults.DeploymentOperationsListResultPreparer()
|
req, err := lastResults.DeploymentOperationsListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -187,12 +204,12 @@ func (client DeploymentOperationsClient) ListNextResults(lastResults DeploymentO
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "resources.DeploymentOperationsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
85
vendor/github.com/Azure/azure-sdk-for-go/arm/resources/resources/deployments.go
generated
vendored
85
vendor/github.com/Azure/azure-sdk-for-go/arm/resources/resources/deployments.go
generated
vendored
|
@ -21,6 +21,7 @@ package resources
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,6 +47,14 @@ func NewDeploymentsClientWithBaseURI(baseURI string, subscriptionID string) Depl
|
||||||
// resourceGroupName is the name of the resource group. The name is case
|
// resourceGroupName is the name of the resource group. The name is case
|
||||||
// insensitive. deploymentName is the name of the deployment.
|
// insensitive. deploymentName is the name of the deployment.
|
||||||
func (client DeploymentsClient) Cancel(resourceGroupName string, deploymentName string) (result autorest.Response, err error) {
|
func (client DeploymentsClient) Cancel(resourceGroupName string, deploymentName string) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentsClient", "Cancel")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CancelPreparer(resourceGroupName, deploymentName)
|
req, err := client.CancelPreparer(resourceGroupName, deploymentName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Cancel", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Cancel", nil, "Failure preparing request")
|
||||||
|
@ -108,6 +117,14 @@ func (client DeploymentsClient) CancelResponder(resp *http.Response) (result aut
|
||||||
// resourceGroupName is the name of the resource group to check. The name is
|
// resourceGroupName is the name of the resource group to check. The name is
|
||||||
// case insensitive. deploymentName is the name of the deployment.
|
// case insensitive. deploymentName is the name of the deployment.
|
||||||
func (client DeploymentsClient) CheckExistence(resourceGroupName string, deploymentName string) (result autorest.Response, err error) {
|
func (client DeploymentsClient) CheckExistence(resourceGroupName string, deploymentName string) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentsClient", "CheckExistence")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CheckExistencePreparer(resourceGroupName, deploymentName)
|
req, err := client.CheckExistencePreparer(resourceGroupName, deploymentName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "CheckExistence", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "CheckExistence", nil, "Failure preparing request")
|
||||||
|
@ -174,6 +191,21 @@ func (client DeploymentsClient) CheckExistenceResponder(resp *http.Response) (re
|
||||||
// insensitive. deploymentName is the name of the deployment. parameters is
|
// insensitive. deploymentName is the name of the deployment. parameters is
|
||||||
// additional parameters supplied to the operation.
|
// additional parameters supplied to the operation.
|
||||||
func (client DeploymentsClient) CreateOrUpdate(resourceGroupName string, deploymentName string, parameters Deployment, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client DeploymentsClient) CreateOrUpdate(resourceGroupName string, deploymentName string, parameters Deployment, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}},
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.TemplateLink", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.TemplateLink.URI", validation.Null, true, nil}}},
|
||||||
|
{"parameters.Properties.ParametersLink", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.ParametersLink.URI", validation.Null, true, nil}}},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, deploymentName, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, deploymentName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -242,6 +274,14 @@ func (client DeploymentsClient) CreateOrUpdateResponder(resp *http.Response) (re
|
||||||
// resourceGroupName is the name of the resource group. The name is case
|
// resourceGroupName is the name of the resource group. The name is case
|
||||||
// insensitive. deploymentName is the name of the deployment to be deleted.
|
// insensitive. deploymentName is the name of the deployment to be deleted.
|
||||||
func (client DeploymentsClient) Delete(resourceGroupName string, deploymentName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client DeploymentsClient) Delete(resourceGroupName string, deploymentName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentsClient", "Delete")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.DeletePreparer(resourceGroupName, deploymentName, cancel)
|
req, err := client.DeletePreparer(resourceGroupName, deploymentName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Delete", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Delete", nil, "Failure preparing request")
|
||||||
|
@ -306,6 +346,14 @@ func (client DeploymentsClient) DeleteResponder(resp *http.Response) (result aut
|
||||||
// resourceGroupName is the name of the resource group. The name is case
|
// resourceGroupName is the name of the resource group. The name is case
|
||||||
// insensitive. deploymentName is the name of the deployment.
|
// insensitive. deploymentName is the name of the deployment.
|
||||||
func (client DeploymentsClient) ExportTemplate(resourceGroupName string, deploymentName string) (result DeploymentExportResult, err error) {
|
func (client DeploymentsClient) ExportTemplate(resourceGroupName string, deploymentName string) (result DeploymentExportResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentsClient", "ExportTemplate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ExportTemplatePreparer(resourceGroupName, deploymentName)
|
req, err := client.ExportTemplatePreparer(resourceGroupName, deploymentName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "ExportTemplate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "ExportTemplate", nil, "Failure preparing request")
|
||||||
|
@ -369,6 +417,14 @@ func (client DeploymentsClient) ExportTemplateResponder(resp *http.Response) (re
|
||||||
// resourceGroupName is the name of the resource group to get. The name is
|
// resourceGroupName is the name of the resource group to get. The name is
|
||||||
// case insensitive. deploymentName is the name of the deployment.
|
// case insensitive. deploymentName is the name of the deployment.
|
||||||
func (client DeploymentsClient) Get(resourceGroupName string, deploymentName string) (result DeploymentExtended, err error) {
|
func (client DeploymentsClient) Get(resourceGroupName string, deploymentName string) (result DeploymentExtended, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentsClient", "Get")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.GetPreparer(resourceGroupName, deploymentName)
|
req, err := client.GetPreparer(resourceGroupName, deploymentName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Get", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Get", nil, "Failure preparing request")
|
||||||
|
@ -433,6 +489,14 @@ func (client DeploymentsClient) GetResponder(resp *http.Response) (result Deploy
|
||||||
// is case insensitive. filter is the filter to apply on the operation. top
|
// is case insensitive. filter is the filter to apply on the operation. top
|
||||||
// is query parameters. If null is passed returns all deployments.
|
// is query parameters. If null is passed returns all deployments.
|
||||||
func (client DeploymentsClient) List(resourceGroupName string, filter string, top *int32) (result DeploymentListResult, err error) {
|
func (client DeploymentsClient) List(resourceGroupName string, filter string, top *int32) (result DeploymentListResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentsClient", "List")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListPreparer(resourceGroupName, filter, top)
|
req, err := client.ListPreparer(resourceGroupName, filter, top)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "List", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "List", nil, "Failure preparing request")
|
||||||
|
@ -500,7 +564,7 @@ func (client DeploymentsClient) ListResponder(resp *http.Response) (result Deplo
|
||||||
func (client DeploymentsClient) ListNextResults(lastResults DeploymentListResult) (result DeploymentListResult, err error) {
|
func (client DeploymentsClient) ListNextResults(lastResults DeploymentListResult) (result DeploymentListResult, err error) {
|
||||||
req, err := lastResults.DeploymentListResultPreparer()
|
req, err := lastResults.DeploymentListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -509,12 +573,12 @@ func (client DeploymentsClient) ListNextResults(lastResults DeploymentListResult
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "resources.DeploymentsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "resources.DeploymentsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -526,6 +590,21 @@ func (client DeploymentsClient) ListNextResults(lastResults DeploymentListResult
|
||||||
// insensitive. deploymentName is the name of the deployment. parameters is
|
// insensitive. deploymentName is the name of the deployment. parameters is
|
||||||
// deployment to validate.
|
// deployment to validate.
|
||||||
func (client DeploymentsClient) Validate(resourceGroupName string, deploymentName string, parameters Deployment) (result DeploymentValidateResult, err error) {
|
func (client DeploymentsClient) Validate(resourceGroupName string, deploymentName string, parameters Deployment) (result DeploymentValidateResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}},
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.TemplateLink", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.TemplateLink.URI", validation.Null, true, nil}}},
|
||||||
|
{"parameters.Properties.ParametersLink", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.ParametersLink.URI", validation.Null, true, nil}}},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.DeploymentsClient", "Validate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ValidatePreparer(resourceGroupName, deploymentName, parameters)
|
req, err := client.ValidatePreparer(resourceGroupName, deploymentName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Validate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Validate", nil, "Failure preparing request")
|
||||||
|
|
|
@ -21,6 +21,7 @@ package resources
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,6 +45,14 @@ func NewGroupsClientWithBaseURI(baseURI string, subscriptionID string) GroupsCli
|
||||||
// resourceGroupName is the name of the resource group to check. The name is
|
// resourceGroupName is the name of the resource group to check. The name is
|
||||||
// case insensitive.
|
// case insensitive.
|
||||||
func (client GroupsClient) CheckExistence(resourceGroupName string) (result autorest.Response, err error) {
|
func (client GroupsClient) CheckExistence(resourceGroupName string) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.GroupsClient", "CheckExistence")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CheckExistencePreparer(resourceGroupName)
|
req, err := client.CheckExistencePreparer(resourceGroupName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "CheckExistence", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "CheckExistence", nil, "Failure preparing request")
|
||||||
|
@ -106,6 +115,19 @@ func (client GroupsClient) CheckExistenceResponder(resp *http.Response) (result
|
||||||
// updated. parameters is parameters supplied to the create or update
|
// updated. parameters is parameters supplied to the create or update
|
||||||
// resource group service operation.
|
// resource group service operation.
|
||||||
func (client GroupsClient) CreateOrUpdate(resourceGroupName string, parameters ResourceGroup) (result ResourceGroup, err error) {
|
func (client GroupsClient) CreateOrUpdate(resourceGroupName string, parameters ResourceGroup) (result ResourceGroup, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}},
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"ProvisioningState", validation.ReadOnly, true, nil}}},
|
||||||
|
{"parameters.Location", validation.Null, true, nil},
|
||||||
|
{"ID", validation.ReadOnly, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.GroupsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, parameters)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -172,6 +194,14 @@ func (client GroupsClient) CreateOrUpdateResponder(resp *http.Response) (result
|
||||||
// resourceGroupName is the name of the resource group to be deleted. The name
|
// resourceGroupName is the name of the resource group to be deleted. The name
|
||||||
// is case insensitive.
|
// is case insensitive.
|
||||||
func (client GroupsClient) Delete(resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client GroupsClient) Delete(resourceGroupName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.GroupsClient", "Delete")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.DeletePreparer(resourceGroupName, cancel)
|
req, err := client.DeletePreparer(resourceGroupName, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "Delete", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "Delete", nil, "Failure preparing request")
|
||||||
|
@ -236,6 +266,14 @@ func (client GroupsClient) DeleteResponder(resp *http.Response) (result autorest
|
||||||
// updated. parameters is parameters supplied to the export template resource
|
// updated. parameters is parameters supplied to the export template resource
|
||||||
// group operation.
|
// group operation.
|
||||||
func (client GroupsClient) ExportTemplate(resourceGroupName string, parameters ExportTemplateRequest) (result ResourceGroupExportResult, err error) {
|
func (client GroupsClient) ExportTemplate(resourceGroupName string, parameters ExportTemplateRequest) (result ResourceGroupExportResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.GroupsClient", "ExportTemplate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ExportTemplatePreparer(resourceGroupName, parameters)
|
req, err := client.ExportTemplatePreparer(resourceGroupName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "ExportTemplate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "ExportTemplate", nil, "Failure preparing request")
|
||||||
|
@ -300,6 +338,14 @@ func (client GroupsClient) ExportTemplateResponder(resp *http.Response) (result
|
||||||
// resourceGroupName is the name of the resource group to get. The name is
|
// resourceGroupName is the name of the resource group to get. The name is
|
||||||
// case insensitive.
|
// case insensitive.
|
||||||
func (client GroupsClient) Get(resourceGroupName string) (result ResourceGroup, err error) {
|
func (client GroupsClient) Get(resourceGroupName string) (result ResourceGroup, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.GroupsClient", "Get")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.GetPreparer(resourceGroupName)
|
req, err := client.GetPreparer(resourceGroupName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "Get", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "Get", nil, "Failure preparing request")
|
||||||
|
@ -428,7 +474,7 @@ func (client GroupsClient) ListResponder(resp *http.Response) (result ResourceGr
|
||||||
func (client GroupsClient) ListNextResults(lastResults ResourceGroupListResult) (result ResourceGroupListResult, err error) {
|
func (client GroupsClient) ListNextResults(lastResults ResourceGroupListResult) (result ResourceGroupListResult, err error) {
|
||||||
req, err := lastResults.ResourceGroupListResultPreparer()
|
req, err := lastResults.ResourceGroupListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -437,12 +483,12 @@ func (client GroupsClient) ListNextResults(lastResults ResourceGroupListResult)
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "resources.GroupsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "resources.GroupsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -455,6 +501,14 @@ func (client GroupsClient) ListNextResults(lastResults ResourceGroupListResult)
|
||||||
// the $expand query parameter top is query parameters. If null is passed
|
// the $expand query parameter top is query parameters. If null is passed
|
||||||
// returns all resource groups.
|
// returns all resource groups.
|
||||||
func (client GroupsClient) ListResources(resourceGroupName string, filter string, expand string, top *int32) (result ResourceListResult, err error) {
|
func (client GroupsClient) ListResources(resourceGroupName string, filter string, expand string, top *int32) (result ResourceListResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.GroupsClient", "ListResources")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListResourcesPreparer(resourceGroupName, filter, expand, top)
|
req, err := client.ListResourcesPreparer(resourceGroupName, filter, expand, top)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "ListResources", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "ListResources", nil, "Failure preparing request")
|
||||||
|
@ -525,7 +579,7 @@ func (client GroupsClient) ListResourcesResponder(resp *http.Response) (result R
|
||||||
func (client GroupsClient) ListResourcesNextResults(lastResults ResourceListResult) (result ResourceListResult, err error) {
|
func (client GroupsClient) ListResourcesNextResults(lastResults ResourceListResult) (result ResourceListResult, err error) {
|
||||||
req, err := lastResults.ResourceListResultPreparer()
|
req, err := lastResults.ResourceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "ListResources", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "ListResources", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -534,12 +588,12 @@ func (client GroupsClient) ListResourcesNextResults(lastResults ResourceListResu
|
||||||
resp, err := client.ListResourcesSender(req)
|
resp, err := client.ListResourcesSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "ListResources", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "ListResources", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResourcesResponder(resp)
|
result, err = client.ListResourcesResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "resources.GroupsClient", "ListResources", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "resources.GroupsClient", "ListResources", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -554,6 +608,16 @@ func (client GroupsClient) ListResourcesNextResults(lastResults ResourceListResu
|
||||||
// updated. The name is case insensitive. parameters is parameters supplied
|
// updated. The name is case insensitive. parameters is parameters supplied
|
||||||
// to the update state resource group service operation.
|
// to the update state resource group service operation.
|
||||||
func (client GroupsClient) Patch(resourceGroupName string, parameters ResourceGroup) (result ResourceGroup, err error) {
|
func (client GroupsClient) Patch(resourceGroupName string, parameters ResourceGroup) (result ResourceGroup, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}},
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"ID", validation.ReadOnly, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.GroupsClient", "Patch")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.PatchPreparer(resourceGroupName, parameters)
|
req, err := client.PatchPreparer(resourceGroupName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "Patch", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.GroupsClient", "Patch", nil, "Failure preparing request")
|
||||||
|
|
|
@ -179,7 +179,7 @@ func (client ProvidersClient) ListResponder(resp *http.Response) (result Provide
|
||||||
func (client ProvidersClient) ListNextResults(lastResults ProviderListResult) (result ProviderListResult, err error) {
|
func (client ProvidersClient) ListNextResults(lastResults ProviderListResult) (result ProviderListResult, err error) {
|
||||||
req, err := lastResults.ProviderListResultPreparer()
|
req, err := lastResults.ProviderListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ProvidersClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.ProvidersClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -188,12 +188,12 @@ func (client ProvidersClient) ListNextResults(lastResults ProviderListResult) (r
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "resources.ProvidersClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.ProvidersClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "resources.ProvidersClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "resources.ProvidersClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,6 +21,7 @@ package resources
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,6 +47,14 @@ func NewClientWithBaseURI(baseURI string, subscriptionID string) Client {
|
||||||
// parentResourcePath is resource identity. resourceType is resource
|
// parentResourcePath is resource identity. resourceType is resource
|
||||||
// identity. resourceName is resource identity.
|
// identity. resourceName is resource identity.
|
||||||
func (client Client) CheckExistence(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) {
|
func (client Client) CheckExistence(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.Client", "CheckExistence")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CheckExistencePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
req, err := client.CheckExistencePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.Client", "CheckExistence", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.Client", "CheckExistence", nil, "Failure preparing request")
|
||||||
|
@ -114,6 +123,19 @@ func (client Client) CheckExistenceResponder(resp *http.Response) (result autore
|
||||||
// identity. resourceName is resource identity. parameters is create or
|
// identity. resourceName is resource identity. parameters is create or
|
||||||
// update resource parameters.
|
// update resource parameters.
|
||||||
func (client Client) CreateOrUpdate(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters GenericResource) (result GenericResource, err error) {
|
func (client Client) CreateOrUpdate(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters GenericResource) (result GenericResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}},
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Identity", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"PrincipalID", validation.ReadOnly, true, nil},
|
||||||
|
{"TenantID", validation.ReadOnly, true, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.Client", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.Client", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.Client", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -184,6 +206,14 @@ func (client Client) CreateOrUpdateResponder(resp *http.Response) (result Generi
|
||||||
// parentResourcePath is resource identity. resourceType is resource
|
// parentResourcePath is resource identity. resourceType is resource
|
||||||
// identity. resourceName is resource identity.
|
// identity. resourceName is resource identity.
|
||||||
func (client Client) Delete(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) {
|
func (client Client) Delete(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.Client", "Delete")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.DeletePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
req, err := client.DeletePreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.Client", "Delete", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.Client", "Delete", nil, "Failure preparing request")
|
||||||
|
@ -251,6 +281,14 @@ func (client Client) DeleteResponder(resp *http.Response) (result autorest.Respo
|
||||||
// parentResourcePath is resource identity. resourceType is resource
|
// parentResourcePath is resource identity. resourceType is resource
|
||||||
// identity. resourceName is resource identity.
|
// identity. resourceName is resource identity.
|
||||||
func (client Client) Get(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result GenericResource, err error) {
|
func (client Client) Get(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result GenericResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{resourceGroupName,
|
||||||
|
[]validation.Constraint{{"resourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"resourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"resourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.Client", "Get")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.GetPreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
req, err := client.GetPreparer(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.Client", "Get", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.Client", "Get", nil, "Failure preparing request")
|
||||||
|
@ -387,7 +425,7 @@ func (client Client) ListResponder(resp *http.Response) (result ResourceListResu
|
||||||
func (client Client) ListNextResults(lastResults ResourceListResult) (result ResourceListResult, err error) {
|
func (client Client) ListNextResults(lastResults ResourceListResult) (result ResourceListResult, err error) {
|
||||||
req, err := lastResults.ResourceListResultPreparer()
|
req, err := lastResults.ResourceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.Client", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.Client", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -396,12 +434,12 @@ func (client Client) ListNextResults(lastResults ResourceListResult) (result Res
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "resources.Client", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.Client", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "resources.Client", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "resources.Client", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -416,6 +454,14 @@ func (client Client) ListNextResults(lastResults ResourceListResult) (result Res
|
||||||
// sourceResourceGroupName is source resource group name. parameters is move
|
// sourceResourceGroupName is source resource group name. parameters is move
|
||||||
// resources' parameters.
|
// resources' parameters.
|
||||||
func (client Client) MoveResources(sourceResourceGroupName string, parameters MoveInfo, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client Client) MoveResources(sourceResourceGroupName string, parameters MoveInfo, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{sourceResourceGroupName,
|
||||||
|
[]validation.Constraint{{"sourceResourceGroupName", validation.MaxLength, 90, nil},
|
||||||
|
{"sourceResourceGroupName", validation.MinLength, 1, nil},
|
||||||
|
{"sourceResourceGroupName", validation.Pattern, `^[-\w\._\(\)]+$`, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "resources.Client", "MoveResources")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.MoveResourcesPreparer(sourceResourceGroupName, parameters, cancel)
|
req, err := client.MoveResourcesPreparer(sourceResourceGroupName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.Client", "MoveResources", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "resources.Client", "MoveResources", nil, "Failure preparing request")
|
||||||
|
|
|
@ -345,7 +345,7 @@ func (client TagsClient) ListResponder(resp *http.Response) (result TagsListResu
|
||||||
func (client TagsClient) ListNextResults(lastResults TagsListResult) (result TagsListResult, err error) {
|
func (client TagsClient) ListNextResults(lastResults TagsListResult) (result TagsListResult, err error) {
|
||||||
req, err := lastResults.TagsListResultPreparer()
|
req, err := lastResults.TagsListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "resources.TagsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.TagsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -354,12 +354,12 @@ func (client TagsClient) ListNextResults(lastResults TagsListResult) (result Tag
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "resources.TagsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "resources.TagsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "resources.TagsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "resources.TagsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
major = "3"
|
major = "4"
|
||||||
minor = "2"
|
minor = "0"
|
||||||
patch = "0"
|
patch = "0"
|
||||||
// Always begin a "tag" with a dash (as per http://semver.org)
|
// Always begin a "tag" with a dash (as per http://semver.org)
|
||||||
tag = "-beta"
|
tag = "-beta"
|
||||||
|
|
|
@ -21,6 +21,7 @@ package scheduler
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,6 +49,13 @@ func NewJobCollectionsClientWithBaseURI(baseURI string, subscriptionID string) J
|
||||||
// resourceGroupName is the resource group name. jobCollectionName is the job
|
// resourceGroupName is the resource group name. jobCollectionName is the job
|
||||||
// collection name. jobCollection is the job collection definition.
|
// collection name. jobCollection is the job collection definition.
|
||||||
func (client JobCollectionsClient) CreateOrUpdate(resourceGroupName string, jobCollectionName string, jobCollection JobCollectionDefinition) (result JobCollectionDefinition, err error) {
|
func (client JobCollectionsClient) CreateOrUpdate(resourceGroupName string, jobCollectionName string, jobCollection JobCollectionDefinition) (result JobCollectionDefinition, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{jobCollection,
|
||||||
|
[]validation.Constraint{{"ID", validation.ReadOnly, true, nil},
|
||||||
|
{"Type", validation.ReadOnly, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "scheduler.JobCollectionsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, jobCollectionName, jobCollection)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, jobCollectionName, jobCollection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -436,7 +444,7 @@ func (client JobCollectionsClient) ListByResourceGroupResponder(resp *http.Respo
|
||||||
func (client JobCollectionsClient) ListByResourceGroupNextResults(lastResults JobCollectionListResult) (result JobCollectionListResult, err error) {
|
func (client JobCollectionsClient) ListByResourceGroupNextResults(lastResults JobCollectionListResult) (result JobCollectionListResult, err error) {
|
||||||
req, err := lastResults.JobCollectionListResultPreparer()
|
req, err := lastResults.JobCollectionListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListByResourceGroup", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListByResourceGroup", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -445,12 +453,12 @@ func (client JobCollectionsClient) ListByResourceGroupNextResults(lastResults Jo
|
||||||
resp, err := client.ListByResourceGroupSender(req)
|
resp, err := client.ListByResourceGroupSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListByResourceGroup", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListByResourceGroup", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListByResourceGroupResponder(resp)
|
result, err = client.ListByResourceGroupResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListByResourceGroup", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListByResourceGroup", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -518,7 +526,7 @@ func (client JobCollectionsClient) ListBySubscriptionResponder(resp *http.Respon
|
||||||
func (client JobCollectionsClient) ListBySubscriptionNextResults(lastResults JobCollectionListResult) (result JobCollectionListResult, err error) {
|
func (client JobCollectionsClient) ListBySubscriptionNextResults(lastResults JobCollectionListResult) (result JobCollectionListResult, err error) {
|
||||||
req, err := lastResults.JobCollectionListResultPreparer()
|
req, err := lastResults.JobCollectionListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListBySubscription", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListBySubscription", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -527,12 +535,12 @@ func (client JobCollectionsClient) ListBySubscriptionNextResults(lastResults Job
|
||||||
resp, err := client.ListBySubscriptionSender(req)
|
resp, err := client.ListBySubscriptionSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListBySubscription", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListBySubscription", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListBySubscriptionResponder(resp)
|
result, err = client.ListBySubscriptionResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListBySubscription", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "ListBySubscription", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -543,6 +551,13 @@ func (client JobCollectionsClient) ListBySubscriptionNextResults(lastResults Job
|
||||||
// resourceGroupName is the resource group name. jobCollectionName is the job
|
// resourceGroupName is the resource group name. jobCollectionName is the job
|
||||||
// collection name. jobCollection is the job collection definition.
|
// collection name. jobCollection is the job collection definition.
|
||||||
func (client JobCollectionsClient) Patch(resourceGroupName string, jobCollectionName string, jobCollection JobCollectionDefinition) (result JobCollectionDefinition, err error) {
|
func (client JobCollectionsClient) Patch(resourceGroupName string, jobCollectionName string, jobCollection JobCollectionDefinition) (result JobCollectionDefinition, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{jobCollection,
|
||||||
|
[]validation.Constraint{{"ID", validation.ReadOnly, true, nil},
|
||||||
|
{"Type", validation.ReadOnly, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "scheduler.JobCollectionsClient", "Patch")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.PatchPreparer(resourceGroupName, jobCollectionName, jobCollection)
|
req, err := client.PatchPreparer(resourceGroupName, jobCollectionName, jobCollection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "Patch", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "Patch", nil, "Failure preparing request")
|
||||||
|
|
|
@ -21,6 +21,7 @@ package scheduler
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,6 +45,24 @@ func NewJobsClientWithBaseURI(baseURI string, subscriptionID string) JobsClient
|
||||||
// resourceGroupName is the resource group name. jobCollectionName is the job
|
// resourceGroupName is the resource group name. jobCollectionName is the job
|
||||||
// collection name. jobName is the job name. job is the job definition.
|
// collection name. jobName is the job name. job is the job definition.
|
||||||
func (client JobsClient) CreateOrUpdate(resourceGroupName string, jobCollectionName string, jobName string, job JobDefinition) (result JobDefinition, err error) {
|
func (client JobsClient) CreateOrUpdate(resourceGroupName string, jobCollectionName string, jobName string, job JobDefinition) (result JobDefinition, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{job,
|
||||||
|
[]validation.Constraint{{"job.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"job.Properties.Status", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"ExecutionCount", validation.ReadOnly, true, nil},
|
||||||
|
{"FailureCount", validation.ReadOnly, true, nil},
|
||||||
|
{"FaultedCount", validation.ReadOnly, true, nil},
|
||||||
|
{"LastExecutionTime", validation.ReadOnly, true, nil},
|
||||||
|
{"NextExecutionTime", validation.ReadOnly, true, nil},
|
||||||
|
}},
|
||||||
|
{"Status", validation.ReadOnly, true, nil},
|
||||||
|
}},
|
||||||
|
{"ID", validation.ReadOnly, true, nil},
|
||||||
|
{"Type", validation.ReadOnly, true, nil},
|
||||||
|
{"Name", validation.ReadOnly, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "scheduler.JobsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, jobCollectionName, jobName, job)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, jobCollectionName, jobName, job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -240,6 +259,15 @@ func (client JobsClient) GetResponder(resp *http.Response) (result JobDefinition
|
||||||
// to begin requesting entries. filter is the filter to apply on the job
|
// to begin requesting entries. filter is the filter to apply on the job
|
||||||
// state.
|
// state.
|
||||||
func (client JobsClient) List(resourceGroupName string, jobCollectionName string, top *int32, skip *int32, filter string) (result JobListResult, err error) {
|
func (client JobsClient) List(resourceGroupName string, jobCollectionName string, top *int32, skip *int32, filter string) (result JobListResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{top,
|
||||||
|
[]validation.Constraint{{"top", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"top", validation.InclusiveMaximum, 100, nil},
|
||||||
|
{"top", validation.InclusiveMinimum, 1, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "scheduler.JobsClient", "List")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListPreparer(resourceGroupName, jobCollectionName, top, skip, filter)
|
req, err := client.ListPreparer(resourceGroupName, jobCollectionName, top, skip, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "List", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "List", nil, "Failure preparing request")
|
||||||
|
@ -311,7 +339,7 @@ func (client JobsClient) ListResponder(resp *http.Response) (result JobListResul
|
||||||
func (client JobsClient) ListNextResults(lastResults JobListResult) (result JobListResult, err error) {
|
func (client JobsClient) ListNextResults(lastResults JobListResult) (result JobListResult, err error) {
|
||||||
req, err := lastResults.JobListResultPreparer()
|
req, err := lastResults.JobListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "List", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "List", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -320,12 +348,12 @@ func (client JobsClient) ListNextResults(lastResults JobListResult) (result JobL
|
||||||
resp, err := client.ListSender(req)
|
resp, err := client.ListSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "List", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "List", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListResponder(resp)
|
result, err = client.ListResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "scheduler.JobsClient", "List", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "scheduler.JobsClient", "List", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -339,6 +367,15 @@ func (client JobsClient) ListNextResults(lastResults JobListResult) (result JobL
|
||||||
// job history list from which to begin requesting entries. filter is the
|
// job history list from which to begin requesting entries. filter is the
|
||||||
// filter to apply on the job state.
|
// filter to apply on the job state.
|
||||||
func (client JobsClient) ListJobHistory(resourceGroupName string, jobCollectionName string, jobName string, top *int32, skip *int32, filter string) (result JobHistoryListResult, err error) {
|
func (client JobsClient) ListJobHistory(resourceGroupName string, jobCollectionName string, jobName string, top *int32, skip *int32, filter string) (result JobHistoryListResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{top,
|
||||||
|
[]validation.Constraint{{"top", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"top", validation.InclusiveMaximum, 100, nil},
|
||||||
|
{"top", validation.InclusiveMinimum, 1, nil},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "scheduler.JobsClient", "ListJobHistory")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListJobHistoryPreparer(resourceGroupName, jobCollectionName, jobName, top, skip, filter)
|
req, err := client.ListJobHistoryPreparer(resourceGroupName, jobCollectionName, jobName, top, skip, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "ListJobHistory", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "ListJobHistory", nil, "Failure preparing request")
|
||||||
|
@ -411,7 +448,7 @@ func (client JobsClient) ListJobHistoryResponder(resp *http.Response) (result Jo
|
||||||
func (client JobsClient) ListJobHistoryNextResults(lastResults JobHistoryListResult) (result JobHistoryListResult, err error) {
|
func (client JobsClient) ListJobHistoryNextResults(lastResults JobHistoryListResult) (result JobHistoryListResult, err error) {
|
||||||
req, err := lastResults.JobHistoryListResultPreparer()
|
req, err := lastResults.JobHistoryListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "ListJobHistory", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "ListJobHistory", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -420,12 +457,12 @@ func (client JobsClient) ListJobHistoryNextResults(lastResults JobHistoryListRes
|
||||||
resp, err := client.ListJobHistorySender(req)
|
resp, err := client.ListJobHistorySender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "ListJobHistory", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "ListJobHistory", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListJobHistoryResponder(resp)
|
result, err = client.ListJobHistoryResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "scheduler.JobsClient", "ListJobHistory", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "scheduler.JobsClient", "ListJobHistory", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -436,6 +473,14 @@ func (client JobsClient) ListJobHistoryNextResults(lastResults JobHistoryListRes
|
||||||
// resourceGroupName is the resource group name. jobCollectionName is the job
|
// resourceGroupName is the resource group name. jobCollectionName is the job
|
||||||
// collection name. jobName is the job name. job is the job definition.
|
// collection name. jobName is the job name. job is the job definition.
|
||||||
func (client JobsClient) Patch(resourceGroupName string, jobCollectionName string, jobName string, job JobDefinition) (result JobDefinition, err error) {
|
func (client JobsClient) Patch(resourceGroupName string, jobCollectionName string, jobName string, job JobDefinition) (result JobDefinition, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{job,
|
||||||
|
[]validation.Constraint{{"ID", validation.ReadOnly, true, nil},
|
||||||
|
{"Type", validation.ReadOnly, true, nil},
|
||||||
|
{"Name", validation.ReadOnly, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "scheduler.JobsClient", "Patch")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.PatchPreparer(resourceGroupName, jobCollectionName, jobName, job)
|
req, err := client.PatchPreparer(resourceGroupName, jobCollectionName, jobName, job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "Patch", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "scheduler.JobsClient", "Patch", nil, "Failure preparing request")
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
major = "3"
|
major = "4"
|
||||||
minor = "2"
|
minor = "0"
|
||||||
patch = "0"
|
patch = "0"
|
||||||
// Always begin a "tag" with a dash (as per http://semver.org)
|
// Always begin a "tag" with a dash (as per http://semver.org)
|
||||||
tag = "-beta"
|
tag = "-beta"
|
||||||
|
|
|
@ -37,20 +37,21 @@ const (
|
||||||
Send AccessRights = "Send"
|
Send AccessRights = "Send"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AvailabilityStatus enumerates the values for availability status.
|
// EntityAvailabilityStatus enumerates the values for entity availability
|
||||||
type AvailabilityStatus string
|
// status.
|
||||||
|
type EntityAvailabilityStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Available specifies the available state for availability status.
|
// Available specifies the available state for entity availability status.
|
||||||
Available AvailabilityStatus = "Available"
|
Available EntityAvailabilityStatus = "Available"
|
||||||
// Limited specifies the limited state for availability status.
|
// Limited specifies the limited state for entity availability status.
|
||||||
Limited AvailabilityStatus = "Limited"
|
Limited EntityAvailabilityStatus = "Limited"
|
||||||
// Renaming specifies the renaming state for availability status.
|
// Renaming specifies the renaming state for entity availability status.
|
||||||
Renaming AvailabilityStatus = "Renaming"
|
Renaming EntityAvailabilityStatus = "Renaming"
|
||||||
// Restoring specifies the restoring state for availability status.
|
// Restoring specifies the restoring state for entity availability status.
|
||||||
Restoring AvailabilityStatus = "Restoring"
|
Restoring EntityAvailabilityStatus = "Restoring"
|
||||||
// Unknown specifies the unknown state for availability status.
|
// Unknown specifies the unknown state for entity availability status.
|
||||||
Unknown AvailabilityStatus = "Unknown"
|
Unknown EntityAvailabilityStatus = "Unknown"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EntityStatus enumerates the values for entity status.
|
// EntityStatus enumerates the values for entity status.
|
||||||
|
@ -86,14 +87,6 @@ const (
|
||||||
EntityStatusUnknown EntityStatus = "Unknown"
|
EntityStatusUnknown EntityStatus = "Unknown"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Kind enumerates the values for kind.
|
|
||||||
type Kind string
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Messaging specifies the messaging state for kind.
|
|
||||||
Messaging Kind = "Messaging"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NamespaceState enumerates the values for namespace state.
|
// NamespaceState enumerates the values for namespace state.
|
||||||
type NamespaceState string
|
type NamespaceState string
|
||||||
|
|
||||||
|
@ -145,8 +138,8 @@ type Policykey string
|
||||||
const (
|
const (
|
||||||
// PrimaryKey specifies the primary key state for policykey.
|
// PrimaryKey specifies the primary key state for policykey.
|
||||||
PrimaryKey Policykey = "PrimaryKey"
|
PrimaryKey Policykey = "PrimaryKey"
|
||||||
// SecondayKey specifies the seconday key state for policykey.
|
// SecondaryKey specifies the secondary key state for policykey.
|
||||||
SecondayKey Policykey = "SecondayKey"
|
SecondaryKey Policykey = "SecondaryKey"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SkuName enumerates the values for sku name.
|
// SkuName enumerates the values for sku name.
|
||||||
|
@ -175,11 +168,11 @@ const (
|
||||||
|
|
||||||
// MessageCountDetails is message Count Details.
|
// MessageCountDetails is message Count Details.
|
||||||
type MessageCountDetails struct {
|
type MessageCountDetails struct {
|
||||||
ActiveMessageCount *int64 `json:"ActiveMessageCount,omitempty"`
|
ActiveMessageCount *int64 `json:"activeMessageCount,omitempty"`
|
||||||
DeadLetterMessageCount *int64 `json:"DeadLetterMessageCount,omitempty"`
|
DeadLetterMessageCount *int64 `json:"deadLetterMessageCount,omitempty"`
|
||||||
ScheduledMessageCount *int64 `json:"ScheduledMessageCount,omitempty"`
|
ScheduledMessageCount *int64 `json:"scheduledMessageCount,omitempty"`
|
||||||
TransferDeadLetterMessageCount *int64 `json:"TransferDeadLetterMessageCount,omitempty"`
|
TransferDeadLetterMessageCount *int64 `json:"transferDeadLetterMessageCount,omitempty"`
|
||||||
TransferMessageCount *int64 `json:"TransferMessageCount,omitempty"`
|
TransferMessageCount *int64 `json:"transferMessageCount,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NamespaceCreateOrUpdateParameters is parameters supplied to the
|
// NamespaceCreateOrUpdateParameters is parameters supplied to the
|
||||||
|
@ -188,7 +181,6 @@ type NamespaceCreateOrUpdateParameters struct {
|
||||||
Location *string `json:"location,omitempty"`
|
Location *string `json:"location,omitempty"`
|
||||||
Sku *Sku `json:"sku,omitempty"`
|
Sku *Sku `json:"sku,omitempty"`
|
||||||
Tags *map[string]*string `json:"tags,omitempty"`
|
Tags *map[string]*string `json:"tags,omitempty"`
|
||||||
Kind Kind `json:"kind,omitempty"`
|
|
||||||
Properties *NamespaceProperties `json:"properties,omitempty"`
|
Properties *NamespaceProperties `json:"properties,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +222,6 @@ type NamespaceResource struct {
|
||||||
Type *string `json:"type,omitempty"`
|
Type *string `json:"type,omitempty"`
|
||||||
Location *string `json:"location,omitempty"`
|
Location *string `json:"location,omitempty"`
|
||||||
Tags *map[string]*string `json:"tags,omitempty"`
|
Tags *map[string]*string `json:"tags,omitempty"`
|
||||||
Kind Kind `json:"kind,omitempty"`
|
|
||||||
Sku *Sku `json:"sku,omitempty"`
|
Sku *Sku `json:"sku,omitempty"`
|
||||||
Properties *NamespaceProperties `json:"properties,omitempty"`
|
Properties *NamespaceProperties `json:"properties,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -264,32 +255,28 @@ func (client QueueListResult) QueueListResultPreparer() (*http.Request, error) {
|
||||||
|
|
||||||
// QueueProperties is
|
// QueueProperties is
|
||||||
type QueueProperties struct {
|
type QueueProperties struct {
|
||||||
AccessedAt *date.Time `json:"AccessedAt,omitempty"`
|
LockDuration *string `json:"lockDuration ,omitempty"`
|
||||||
AutoDeleteOnIdle *string `json:"AutoDeleteOnIdle,omitempty"`
|
AccessedAt *date.Time `json:"accessedAt,omitempty"`
|
||||||
AvailabilityStatus AvailabilityStatus `json:"AvailabilityStatus ,omitempty"`
|
AutoDeleteOnIdle *string `json:"autoDeleteOnIdle,omitempty"`
|
||||||
CreatedAt *date.Time `json:"CreatedAt,omitempty"`
|
EntityAvailabilityStatus EntityAvailabilityStatus `json:"entityAvailabilityStatus ,omitempty"`
|
||||||
DefaultMessageTimeToLive *string `json:"DefaultMessageTimeToLive,omitempty"`
|
CreatedAt *date.Time `json:"createdAt,omitempty"`
|
||||||
DuplicateDetectionHistoryTimeWindow *string `json:"DuplicateDetectionHistoryTimeWindow ,omitempty"`
|
DefaultMessageTimeToLive *string `json:"defaultMessageTimeToLive,omitempty"`
|
||||||
EnableBatchedOperations *bool `json:"EnableBatchedOperations,omitempty"`
|
DuplicateDetectionHistoryTimeWindow *string `json:"duplicateDetectionHistoryTimeWindow ,omitempty"`
|
||||||
EnableDeadLetteringOnMessageExpiration *bool `json:"EnableDeadLetteringOnMessageExpiration,omitempty"`
|
EnableBatchedOperations *bool `json:"enableBatchedOperations,omitempty"`
|
||||||
EnableExpress *bool `json:"EnableExpress,omitempty"`
|
DeadLetteringOnMessageExpiration *bool `json:"deadLetteringOnMessageExpiration,omitempty"`
|
||||||
EnablePartitioning *bool `json:"EnablePartitioning,omitempty"`
|
EnableExpress *bool `json:"enableExpress,omitempty"`
|
||||||
ForwardDeadLetteredMessagesTo *string `json:"ForwardDeadLetteredMessagesTo,omitempty"`
|
EnablePartitioning *bool `json:"enablePartitioning,omitempty"`
|
||||||
ForwardTo *string `json:"ForwardTo,omitempty"`
|
IsAnonymousAccessible *bool `json:"isAnonymousAccessible,omitempty"`
|
||||||
IsAnonymousAccessible *bool `json:"IsAnonymousAccessible,omitempty"`
|
MaxDeliveryCount *int32 `json:"maxDeliveryCount ,omitempty"`
|
||||||
LockDuration *string `json:"LockDuration ,omitempty"`
|
MaxSizeInMegabytes *int64 `json:"maxSizeInMegabytes,omitempty"`
|
||||||
MaxDeliveryCount *int32 `json:"MaxDeliveryCount ,omitempty"`
|
MessageCount *int64 `json:"messageCount ,omitempty"`
|
||||||
MaxSizeInMegabytes *int64 `json:"MaxSizeInMegabytes ,omitempty"`
|
CountDetails *MessageCountDetails `json:"countDetails,omitempty"`
|
||||||
MessageCount *int64 `json:"MessageCount ,omitempty"`
|
RequiresDuplicateDetection *bool `json:"requiresDuplicateDetection,omitempty"`
|
||||||
MessageCountDetails *MessageCountDetails `json:"MessageCountDetails,omitempty"`
|
RequiresSession *bool `json:"requiresSession,omitempty"`
|
||||||
Path *string `json:"Path,omitempty"`
|
SizeInBytes *int64 `json:"sizeInBytes ,omitempty"`
|
||||||
RequiresDuplicateDetection *bool `json:"RequiresDuplicateDetection,omitempty"`
|
Status EntityStatus `json:"status,omitempty"`
|
||||||
RequiresSession *bool `json:"RequiresSession,omitempty"`
|
SupportOrdering *bool `json:"supportOrdering,omitempty"`
|
||||||
SizeInBytes *int64 `json:"SizeInBytes ,omitempty"`
|
UpdatedAt *date.Time `json:"updatedAt,omitempty"`
|
||||||
Status EntityStatus `json:"Status,omitempty"`
|
|
||||||
SupportOrdering *bool `json:"SupportOrdering,omitempty"`
|
|
||||||
UpdatedAt *date.Time `json:"UpdatedAt,omitempty"`
|
|
||||||
UserMetadata *string `json:"UserMetadata,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueueResource is description of queue Resource.
|
// QueueResource is description of queue Resource.
|
||||||
|
@ -409,26 +396,22 @@ func (client SubscriptionListResult) SubscriptionListResultPreparer() (*http.Req
|
||||||
|
|
||||||
// SubscriptionProperties is description of Subscription Resource.
|
// SubscriptionProperties is description of Subscription Resource.
|
||||||
type SubscriptionProperties struct {
|
type SubscriptionProperties struct {
|
||||||
AccessedAt *date.Time `json:"AccessedAt,omitempty"`
|
AccessedAt *date.Time `json:"accessedAt,omitempty"`
|
||||||
AutoDeleteOnIdle *string `json:"AutoDeleteOnIdle,omitempty"`
|
AutoDeleteOnIdle *string `json:"autoDeleteOnIdle,omitempty"`
|
||||||
AvailabilityStatus AvailabilityStatus `json:"AvailabilityStatus ,omitempty"`
|
CountDetails *MessageCountDetails `json:"countDetails,omitempty"`
|
||||||
CreatedAt *date.Time `json:"CreatedAt,omitempty"`
|
CreatedAt *date.Time `json:"createdAt,omitempty"`
|
||||||
DefaultMessageTimeToLive *string `json:"DefaultMessageTimeToLive,omitempty"`
|
DefaultMessageTimeToLive *string `json:"defaultMessageTimeToLive,omitempty"`
|
||||||
EnableBatchedOperations *bool `json:"EnableBatchedOperations,omitempty"`
|
DeadLetteringOnFilterEvaluationExceptions *bool `json:"deadLetteringOnFilterEvaluationExceptions,omitempty"`
|
||||||
EnableDeadLetteringOnFilterEvaluationExceptions *bool `json:"EnableDeadLetteringOnFilterEvaluationExceptions,omitempty"`
|
DeadLetteringOnMessageExpiration *bool `json:"deadLetteringOnMessageExpiration,omitempty"`
|
||||||
EnableDeadLetteringOnMessageExpiration *bool `json:"EnableDeadLetteringOnMessageExpiration,omitempty"`
|
EnableBatchedOperations *bool `json:"enableBatchedOperations,omitempty"`
|
||||||
ForwardDeadLetteredMessagesTo *string `json:"ForwardDeadLetteredMessagesTo,omitempty"`
|
EntityAvailabilityStatus EntityAvailabilityStatus `json:"entityAvailabilityStatus,omitempty"`
|
||||||
ForwardTo *string `json:"ForwardTo,omitempty"`
|
IsReadOnly *bool `json:"isReadOnly,omitempty"`
|
||||||
IsReadOnly *bool `json:"IsReadOnly,omitempty"`
|
LockDuration *string `json:"lockDuration,omitempty"`
|
||||||
LockDuration *string `json:"LockDuration,omitempty"`
|
MaxDeliveryCount *int32 `json:"maxDeliveryCount,omitempty"`
|
||||||
MaxDeliveryCount *int32 `json:"MaxDeliveryCount,omitempty"`
|
MessageCount *int64 `json:"messageCount,omitempty"`
|
||||||
MessageCount *int64 `json:"MessageCount,omitempty"`
|
RequiresSession *bool `json:"requiresSession,omitempty"`
|
||||||
MessageCountDetails *MessageCountDetails `json:"MessageCountDetails,omitempty"`
|
Status EntityStatus `json:"status,omitempty"`
|
||||||
RequiresSession *bool `json:"RequiresSession,omitempty"`
|
UpdatedAt *date.Time `json:"updatedAt,omitempty"`
|
||||||
Status EntityStatus `json:"Status,omitempty"`
|
|
||||||
TopicPath *string `json:"TopicPath,omitempty"`
|
|
||||||
UpdatedAt *date.Time `json:"UpdatedAt,omitempty"`
|
|
||||||
UserMetadata *string `json:"UserMetadata,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubscriptionResource is description of Subscription Resource.
|
// SubscriptionResource is description of Subscription Resource.
|
||||||
|
@ -471,27 +454,27 @@ func (client TopicListResult) TopicListResultPreparer() (*http.Request, error) {
|
||||||
|
|
||||||
// TopicProperties is
|
// TopicProperties is
|
||||||
type TopicProperties struct {
|
type TopicProperties struct {
|
||||||
AccessedAt *date.Time `json:"AccessedAt,omitempty"`
|
AccessedAt *date.Time `json:"accessedAt,omitempty"`
|
||||||
AutoDeleteOnIdle *string `json:"AutoDeleteOnIdle,omitempty"`
|
AutoDeleteOnIdle *string `json:"autoDeleteOnIdle,omitempty"`
|
||||||
AvailabilityStatus AvailabilityStatus `json:"AvailabilityStatus ,omitempty"`
|
EntityAvailabilityStatus EntityAvailabilityStatus `json:"entityAvailabilityStatus ,omitempty"`
|
||||||
CreatedAt *date.Time `json:"CreatedAt,omitempty"`
|
CreatedAt *date.Time `json:"createdAt,omitempty"`
|
||||||
DefaultMessageTimeToLive *string `json:"DefaultMessageTimeToLive,omitempty"`
|
CountDetails *MessageCountDetails `json:"countDetails,omitempty"`
|
||||||
DuplicateDetectionHistoryTimeWindow *string `json:"DuplicateDetectionHistoryTimeWindow ,omitempty"`
|
DefaultMessageTimeToLive *string `json:"defaultMessageTimeToLive,omitempty"`
|
||||||
EnableBatchedOperations *bool `json:"EnableBatchedOperations,omitempty"`
|
DuplicateDetectionHistoryTimeWindow *string `json:"duplicateDetectionHistoryTimeWindow ,omitempty"`
|
||||||
EnableExpress *bool `json:"EnableExpress,omitempty"`
|
EnableBatchedOperations *bool `json:"enableBatchedOperations,omitempty"`
|
||||||
EnableFilteringMessagesBeforePublishing *bool `json:"EnableFilteringMessagesBeforePublishing,omitempty"`
|
EnableExpress *bool `json:"enableExpress,omitempty"`
|
||||||
EnablePartitioning *bool `json:"EnablePartitioning,omitempty"`
|
EnablePartitioning *bool `json:"enablePartitioning,omitempty"`
|
||||||
IsAnonymousAccessible *bool `json:"IsAnonymousAccessible,omitempty"`
|
EnableSubscriptionPartitioning *bool `json:"enableSubscriptionPartitioning,omitempty"`
|
||||||
MaxSizeInMegabytes *int64 `json:"MaxSizeInMegabytes ,omitempty"`
|
FilteringMessagesBeforePublishing *bool `json:"filteringMessagesBeforePublishing,omitempty"`
|
||||||
MessageCountDetails *MessageCountDetails `json:"MessageCountDetails,omitempty"`
|
IsAnonymousAccessible *bool `json:"isAnonymousAccessible,omitempty"`
|
||||||
Path *string `json:"Path,omitempty"`
|
IsExpress *bool `json:"isExpress,omitempty"`
|
||||||
RequiresDuplicateDetection *bool `json:"RequiresDuplicateDetection,omitempty"`
|
MaxSizeInMegabytes *int64 `json:"maxSizeInMegabytes,omitempty"`
|
||||||
SizeInBytes *int64 `json:"SizeInBytes ,omitempty"`
|
RequiresDuplicateDetection *bool `json:"requiresDuplicateDetection,omitempty"`
|
||||||
Status EntityStatus `json:"Status,omitempty"`
|
SizeInBytes *int64 `json:"sizeInBytes,omitempty"`
|
||||||
SubscriptionCount *int32 `json:"SubscriptionCount,omitempty"`
|
Status EntityStatus `json:"status,omitempty"`
|
||||||
SupportOrdering *bool `json:"SupportOrdering,omitempty"`
|
SubscriptionCount *int32 `json:"subscriptionCount,omitempty"`
|
||||||
UpdatedAt *date.Time `json:"UpdatedAt,omitempty"`
|
SupportOrdering *bool `json:"supportOrdering,omitempty"`
|
||||||
UserMetadata *string `json:"UserMetadata,omitempty"`
|
UpdatedAt *date.Time `json:"updatedAt,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TopicResource is description of topic Resource.
|
// TopicResource is description of topic Resource.
|
||||||
|
|
|
@ -21,6 +21,7 @@ package servicebus
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,6 +51,12 @@ func NewNamespacesClientWithBaseURI(baseURI string, subscriptionID string) Names
|
||||||
// namespace name. parameters is parameters supplied to create a Namespace
|
// namespace name. parameters is parameters supplied to create a Namespace
|
||||||
// Resource.
|
// Resource.
|
||||||
func (client NamespacesClient) CreateOrUpdate(resourceGroupName string, namespaceName string, parameters NamespaceCreateOrUpdateParameters, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client NamespacesClient) CreateOrUpdate(resourceGroupName string, namespaceName string, parameters NamespaceCreateOrUpdateParameters, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Location", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "servicebus.NamespacesClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, namespaceName, parameters, cancel)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, namespaceName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -118,6 +125,13 @@ func (client NamespacesClient) CreateOrUpdateResponder(resp *http.Response) (res
|
||||||
// namespace name. authorizationRuleName is namespace Aauthorization Rule
|
// namespace name. authorizationRuleName is namespace Aauthorization Rule
|
||||||
// Name. parameters is the shared access authorization rule.
|
// Name. parameters is the shared access authorization rule.
|
||||||
func (client NamespacesClient) CreateOrUpdateAuthorizationRule(resourceGroupName string, namespaceName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) {
|
func (client NamespacesClient) CreateOrUpdateAuthorizationRule(resourceGroupName string, namespaceName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.Rights", validation.Null, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "servicebus.NamespacesClient", "CreateOrUpdateAuthorizationRule")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdateAuthorizationRulePreparer(resourceGroupName, namespaceName, authorizationRuleName, parameters)
|
req, err := client.CreateOrUpdateAuthorizationRulePreparer(resourceGroupName, namespaceName, authorizationRuleName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request")
|
||||||
|
@ -241,7 +255,7 @@ func (client NamespacesClient) DeleteResponder(resp *http.Response) (result auto
|
||||||
err = autorest.Respond(
|
err = autorest.Respond(
|
||||||
resp,
|
resp,
|
||||||
client.ByInspecting(),
|
client.ByInspecting(),
|
||||||
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
|
azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK, http.StatusAccepted),
|
||||||
autorest.ByClosing())
|
autorest.ByClosing())
|
||||||
result.Response = resp
|
result.Response = resp
|
||||||
return
|
return
|
||||||
|
@ -304,7 +318,7 @@ func (client NamespacesClient) DeleteAuthorizationRuleResponder(resp *http.Respo
|
||||||
err = autorest.Respond(
|
err = autorest.Respond(
|
||||||
resp,
|
resp,
|
||||||
client.ByInspecting(),
|
client.ByInspecting(),
|
||||||
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK),
|
||||||
autorest.ByClosing())
|
autorest.ByClosing())
|
||||||
result.Response = resp
|
result.Response = resp
|
||||||
return
|
return
|
||||||
|
@ -504,7 +518,7 @@ func (client NamespacesClient) ListAuthorizationRulesResponder(resp *http.Respon
|
||||||
func (client NamespacesClient) ListAuthorizationRulesNextResults(lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) {
|
func (client NamespacesClient) ListAuthorizationRulesNextResults(lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) {
|
||||||
req, err := lastResults.SharedAccessAuthorizationRuleListResultPreparer()
|
req, err := lastResults.SharedAccessAuthorizationRuleListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListAuthorizationRules", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListAuthorizationRules", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -513,12 +527,12 @@ func (client NamespacesClient) ListAuthorizationRulesNextResults(lastResults Sha
|
||||||
resp, err := client.ListAuthorizationRulesSender(req)
|
resp, err := client.ListAuthorizationRulesSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListAuthorizationRules", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListAuthorizationRules", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAuthorizationRulesResponder(resp)
|
result, err = client.ListAuthorizationRulesResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListAuthorizationRules", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListAuthorizationRules", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -589,7 +603,7 @@ func (client NamespacesClient) ListByResourceGroupResponder(resp *http.Response)
|
||||||
func (client NamespacesClient) ListByResourceGroupNextResults(lastResults NamespaceListResult) (result NamespaceListResult, err error) {
|
func (client NamespacesClient) ListByResourceGroupNextResults(lastResults NamespaceListResult) (result NamespaceListResult, err error) {
|
||||||
req, err := lastResults.NamespaceListResultPreparer()
|
req, err := lastResults.NamespaceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListByResourceGroup", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListByResourceGroup", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -598,12 +612,12 @@ func (client NamespacesClient) ListByResourceGroupNextResults(lastResults Namesp
|
||||||
resp, err := client.ListByResourceGroupSender(req)
|
resp, err := client.ListByResourceGroupSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListByResourceGroup", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListByResourceGroup", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListByResourceGroupResponder(resp)
|
result, err = client.ListByResourceGroupResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListByResourceGroup", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListByResourceGroup", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -672,7 +686,7 @@ func (client NamespacesClient) ListBySubscriptionResponder(resp *http.Response)
|
||||||
func (client NamespacesClient) ListBySubscriptionNextResults(lastResults NamespaceListResult) (result NamespaceListResult, err error) {
|
func (client NamespacesClient) ListBySubscriptionNextResults(lastResults NamespaceListResult) (result NamespaceListResult, err error) {
|
||||||
req, err := lastResults.NamespaceListResultPreparer()
|
req, err := lastResults.NamespaceListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListBySubscription", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListBySubscription", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -681,12 +695,12 @@ func (client NamespacesClient) ListBySubscriptionNextResults(lastResults Namespa
|
||||||
resp, err := client.ListBySubscriptionSender(req)
|
resp, err := client.ListBySubscriptionSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListBySubscription", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListBySubscription", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListBySubscriptionResponder(resp)
|
result, err = client.ListBySubscriptionResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListBySubscription", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "servicebus.NamespacesClient", "ListBySubscription", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,6 +21,7 @@ package servicebus
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,6 +47,12 @@ func NewQueuesClientWithBaseURI(baseURI string, subscriptionID string) QueuesCli
|
||||||
// namespace name. queueName is the queue name. parameters is parameters
|
// namespace name. queueName is the queue name. parameters is parameters
|
||||||
// supplied to create a Queue Resource.
|
// supplied to create a Queue Resource.
|
||||||
func (client QueuesClient) CreateOrUpdate(resourceGroupName string, namespaceName string, queueName string, parameters QueueCreateOrUpdateParameters) (result QueueResource, err error) {
|
func (client QueuesClient) CreateOrUpdate(resourceGroupName string, namespaceName string, queueName string, parameters QueueCreateOrUpdateParameters) (result QueueResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Location", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "servicebus.QueuesClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, namespaceName, queueName, parameters)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, namespaceName, queueName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -114,6 +121,13 @@ func (client QueuesClient) CreateOrUpdateResponder(resp *http.Response) (result
|
||||||
// aauthorization Rule Name. parameters is the shared access authorization
|
// aauthorization Rule Name. parameters is the shared access authorization
|
||||||
// rule.
|
// rule.
|
||||||
func (client QueuesClient) CreateOrUpdateAuthorizationRule(resourceGroupName string, namespaceName string, queueName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) {
|
func (client QueuesClient) CreateOrUpdateAuthorizationRule(resourceGroupName string, namespaceName string, queueName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.Rights", validation.Null, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "servicebus.QueuesClient", "CreateOrUpdateAuthorizationRule")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdateAuthorizationRulePreparer(resourceGroupName, namespaceName, queueName, authorizationRuleName, parameters)
|
req, err := client.CreateOrUpdateAuthorizationRulePreparer(resourceGroupName, namespaceName, queueName, authorizationRuleName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request")
|
||||||
|
@ -233,7 +247,7 @@ func (client QueuesClient) DeleteResponder(resp *http.Response) (result autorest
|
||||||
err = autorest.Respond(
|
err = autorest.Respond(
|
||||||
resp,
|
resp,
|
||||||
client.ByInspecting(),
|
client.ByInspecting(),
|
||||||
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK),
|
||||||
autorest.ByClosing())
|
autorest.ByClosing())
|
||||||
result.Response = resp
|
result.Response = resp
|
||||||
return
|
return
|
||||||
|
@ -298,7 +312,7 @@ func (client QueuesClient) DeleteAuthorizationRuleResponder(resp *http.Response)
|
||||||
err = autorest.Respond(
|
err = autorest.Respond(
|
||||||
resp,
|
resp,
|
||||||
client.ByInspecting(),
|
client.ByInspecting(),
|
||||||
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK),
|
||||||
autorest.ByClosing())
|
autorest.ByClosing())
|
||||||
result.Response = resp
|
result.Response = resp
|
||||||
return
|
return
|
||||||
|
@ -501,7 +515,7 @@ func (client QueuesClient) ListAllResponder(resp *http.Response) (result QueueLi
|
||||||
func (client QueuesClient) ListAllNextResults(lastResults QueueListResult) (result QueueListResult, err error) {
|
func (client QueuesClient) ListAllNextResults(lastResults QueueListResult) (result QueueListResult, err error) {
|
||||||
req, err := lastResults.QueueListResultPreparer()
|
req, err := lastResults.QueueListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -510,12 +524,12 @@ func (client QueuesClient) ListAllNextResults(lastResults QueueListResult) (resu
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -589,7 +603,7 @@ func (client QueuesClient) ListAuthorizationRulesResponder(resp *http.Response)
|
||||||
func (client QueuesClient) ListAuthorizationRulesNextResults(lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) {
|
func (client QueuesClient) ListAuthorizationRulesNextResults(lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) {
|
||||||
req, err := lastResults.SharedAccessAuthorizationRuleListResultPreparer()
|
req, err := lastResults.SharedAccessAuthorizationRuleListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAuthorizationRules", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAuthorizationRules", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -598,12 +612,12 @@ func (client QueuesClient) ListAuthorizationRulesNextResults(lastResults SharedA
|
||||||
resp, err := client.ListAuthorizationRulesSender(req)
|
resp, err := client.ListAuthorizationRulesSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAuthorizationRules", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAuthorizationRules", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAuthorizationRulesResponder(resp)
|
result, err = client.ListAuthorizationRulesResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAuthorizationRules", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "servicebus.QueuesClient", "ListAuthorizationRules", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,6 +21,7 @@ package servicebus
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,6 +49,12 @@ func NewSubscriptionsClientWithBaseURI(baseURI string, subscriptionID string) Su
|
||||||
// subscriptionName name. parameters is parameters supplied to create a
|
// subscriptionName name. parameters is parameters supplied to create a
|
||||||
// subscription Resource.
|
// subscription Resource.
|
||||||
func (client SubscriptionsClient) CreateOrUpdate(resourceGroupName string, namespaceName string, topicName string, subscriptionName string, parameters SubscriptionCreateOrUpdateParameters) (result SubscriptionResource, err error) {
|
func (client SubscriptionsClient) CreateOrUpdate(resourceGroupName string, namespaceName string, topicName string, subscriptionName string, parameters SubscriptionCreateOrUpdateParameters) (result SubscriptionResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Location", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "servicebus.SubscriptionsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, namespaceName, topicName, subscriptionName, parameters)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, namespaceName, topicName, subscriptionName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.SubscriptionsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.SubscriptionsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -169,7 +176,7 @@ func (client SubscriptionsClient) DeleteResponder(resp *http.Response) (result a
|
||||||
err = autorest.Respond(
|
err = autorest.Respond(
|
||||||
resp,
|
resp,
|
||||||
client.ByInspecting(),
|
client.ByInspecting(),
|
||||||
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK),
|
||||||
autorest.ByClosing())
|
autorest.ByClosing())
|
||||||
result.Response = resp
|
result.Response = resp
|
||||||
return
|
return
|
||||||
|
@ -309,7 +316,7 @@ func (client SubscriptionsClient) ListAllResponder(resp *http.Response) (result
|
||||||
func (client SubscriptionsClient) ListAllNextResults(lastResults SubscriptionListResult) (result SubscriptionListResult, err error) {
|
func (client SubscriptionsClient) ListAllNextResults(lastResults SubscriptionListResult) (result SubscriptionListResult, err error) {
|
||||||
req, err := lastResults.SubscriptionListResultPreparer()
|
req, err := lastResults.SubscriptionListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.SubscriptionsClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.SubscriptionsClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -318,12 +325,12 @@ func (client SubscriptionsClient) ListAllNextResults(lastResults SubscriptionLis
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.SubscriptionsClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.SubscriptionsClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.SubscriptionsClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "servicebus.SubscriptionsClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,6 +21,7 @@ package servicebus
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,6 +46,12 @@ func NewTopicsClientWithBaseURI(baseURI string, subscriptionID string) TopicsCli
|
||||||
// namespace name. topicName is the topic name. parameters is parameters
|
// namespace name. topicName is the topic name. parameters is parameters
|
||||||
// supplied to create a Topic Resource.
|
// supplied to create a Topic Resource.
|
||||||
func (client TopicsClient) CreateOrUpdate(resourceGroupName string, namespaceName string, topicName string, parameters TopicCreateOrUpdateParameters) (result TopicResource, err error) {
|
func (client TopicsClient) CreateOrUpdate(resourceGroupName string, namespaceName string, topicName string, parameters TopicCreateOrUpdateParameters) (result TopicResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Location", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "servicebus.TopicsClient", "CreateOrUpdate")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdatePreparer(resourceGroupName, namespaceName, topicName, parameters)
|
req, err := client.CreateOrUpdatePreparer(resourceGroupName, namespaceName, topicName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "CreateOrUpdate", nil, "Failure preparing request")
|
||||||
|
@ -114,6 +121,13 @@ func (client TopicsClient) CreateOrUpdateResponder(resp *http.Response) (result
|
||||||
// aauthorization Rule Name. parameters is the shared access authorization
|
// aauthorization Rule Name. parameters is the shared access authorization
|
||||||
// rule.
|
// rule.
|
||||||
func (client TopicsClient) CreateOrUpdateAuthorizationRule(resourceGroupName string, namespaceName string, topicName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) {
|
func (client TopicsClient) CreateOrUpdateAuthorizationRule(resourceGroupName string, namespaceName string, topicName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.Rights", validation.Null, true, nil}}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "servicebus.TopicsClient", "CreateOrUpdateAuthorizationRule")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreateOrUpdateAuthorizationRulePreparer(resourceGroupName, namespaceName, topicName, authorizationRuleName, parameters)
|
req, err := client.CreateOrUpdateAuthorizationRulePreparer(resourceGroupName, namespaceName, topicName, authorizationRuleName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request")
|
||||||
|
@ -177,14 +191,11 @@ func (client TopicsClient) CreateOrUpdateAuthorizationRuleResponder(resp *http.R
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes a topic from the specified namespace and resource group.
|
// Delete deletes a topic from the specified namespace and resource group.
|
||||||
// This method may poll for completion. Polling can be canceled by passing
|
|
||||||
// the cancel channel argument. The channel will be used to cancel polling
|
|
||||||
// and any outstanding HTTP requests.
|
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. namespaceName is the
|
// resourceGroupName is the name of the resource group. namespaceName is the
|
||||||
// topics name. topicName is the topics name.
|
// topics name. topicName is the topics name.
|
||||||
func (client TopicsClient) Delete(resourceGroupName string, namespaceName string, topicName string, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client TopicsClient) Delete(resourceGroupName string, namespaceName string, topicName string) (result autorest.Response, err error) {
|
||||||
req, err := client.DeletePreparer(resourceGroupName, namespaceName, topicName, cancel)
|
req, err := client.DeletePreparer(resourceGroupName, namespaceName, topicName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "Delete", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "Delete", nil, "Failure preparing request")
|
||||||
}
|
}
|
||||||
|
@ -204,7 +215,7 @@ func (client TopicsClient) Delete(resourceGroupName string, namespaceName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePreparer prepares the Delete request.
|
// DeletePreparer prepares the Delete request.
|
||||||
func (client TopicsClient) DeletePreparer(resourceGroupName string, namespaceName string, topicName string, cancel <-chan struct{}) (*http.Request, error) {
|
func (client TopicsClient) DeletePreparer(resourceGroupName string, namespaceName string, topicName string) (*http.Request, error) {
|
||||||
pathParameters := map[string]interface{}{
|
pathParameters := map[string]interface{}{
|
||||||
"namespaceName": autorest.Encode("path", namespaceName),
|
"namespaceName": autorest.Encode("path", namespaceName),
|
||||||
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
||||||
|
@ -221,15 +232,13 @@ func (client TopicsClient) DeletePreparer(resourceGroupName string, namespaceNam
|
||||||
autorest.WithBaseURL(client.BaseURI),
|
autorest.WithBaseURL(client.BaseURI),
|
||||||
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceBus/namespaces/{namespaceName}/topics/{topicName}", pathParameters),
|
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceBus/namespaces/{namespaceName}/topics/{topicName}", pathParameters),
|
||||||
autorest.WithQueryParameters(queryParameters))
|
autorest.WithQueryParameters(queryParameters))
|
||||||
return preparer.Prepare(&http.Request{Cancel: cancel})
|
return preparer.Prepare(&http.Request{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteSender sends the Delete request. The method will close the
|
// DeleteSender sends the Delete request. The method will close the
|
||||||
// http.Response Body if it receives an error.
|
// http.Response Body if it receives an error.
|
||||||
func (client TopicsClient) DeleteSender(req *http.Request) (*http.Response, error) {
|
func (client TopicsClient) DeleteSender(req *http.Request) (*http.Response, error) {
|
||||||
return autorest.SendWithSender(client,
|
return autorest.SendWithSender(client, req)
|
||||||
req,
|
|
||||||
azure.DoPollForAsynchronous(client.PollingDelay))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteResponder handles the response to the Delete request. The method always
|
// DeleteResponder handles the response to the Delete request. The method always
|
||||||
|
@ -238,7 +247,7 @@ func (client TopicsClient) DeleteResponder(resp *http.Response) (result autorest
|
||||||
err = autorest.Respond(
|
err = autorest.Respond(
|
||||||
resp,
|
resp,
|
||||||
client.ByInspecting(),
|
client.ByInspecting(),
|
||||||
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK),
|
||||||
autorest.ByClosing())
|
autorest.ByClosing())
|
||||||
result.Response = resp
|
result.Response = resp
|
||||||
return
|
return
|
||||||
|
@ -303,19 +312,83 @@ func (client TopicsClient) DeleteAuthorizationRuleResponder(resp *http.Response)
|
||||||
err = autorest.Respond(
|
err = autorest.Respond(
|
||||||
resp,
|
resp,
|
||||||
client.ByInspecting(),
|
client.ByInspecting(),
|
||||||
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK),
|
||||||
autorest.ByClosing())
|
autorest.ByClosing())
|
||||||
result.Response = resp
|
result.Response = resp
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get returns the description for the specified topic
|
||||||
|
//
|
||||||
|
// resourceGroupName is the name of the resource group. namespaceName is the
|
||||||
|
// namespace name. topicName is the topic name.
|
||||||
|
func (client TopicsClient) Get(resourceGroupName string, namespaceName string, topicName string) (result TopicResource, err error) {
|
||||||
|
req, err := client.GetPreparer(resourceGroupName, namespaceName, topicName)
|
||||||
|
if err != nil {
|
||||||
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "Get", nil, "Failure preparing request")
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.GetSender(req)
|
||||||
|
if err != nil {
|
||||||
|
result.Response = autorest.Response{Response: resp}
|
||||||
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "Get", resp, "Failure sending request")
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err = client.GetResponder(resp)
|
||||||
|
if err != nil {
|
||||||
|
err = autorest.NewErrorWithError(err, "servicebus.TopicsClient", "Get", resp, "Failure responding to request")
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPreparer prepares the Get request.
|
||||||
|
func (client TopicsClient) GetPreparer(resourceGroupName string, namespaceName string, topicName string) (*http.Request, error) {
|
||||||
|
pathParameters := map[string]interface{}{
|
||||||
|
"namespaceName": autorest.Encode("path", namespaceName),
|
||||||
|
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
||||||
|
"subscriptionId": autorest.Encode("path", client.SubscriptionID),
|
||||||
|
"topicName": autorest.Encode("path", topicName),
|
||||||
|
}
|
||||||
|
|
||||||
|
queryParameters := map[string]interface{}{
|
||||||
|
"api-version": client.APIVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
preparer := autorest.CreatePreparer(
|
||||||
|
autorest.AsGet(),
|
||||||
|
autorest.WithBaseURL(client.BaseURI),
|
||||||
|
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceBus/namespaces/{namespaceName}/topics/{topicName}", pathParameters),
|
||||||
|
autorest.WithQueryParameters(queryParameters))
|
||||||
|
return preparer.Prepare(&http.Request{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSender sends the Get request. The method will close the
|
||||||
|
// http.Response Body if it receives an error.
|
||||||
|
func (client TopicsClient) GetSender(req *http.Request) (*http.Response, error) {
|
||||||
|
return autorest.SendWithSender(client, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetResponder handles the response to the Get request. The method always
|
||||||
|
// closes the http.Response Body.
|
||||||
|
func (client TopicsClient) GetResponder(resp *http.Response) (result TopicResource, err error) {
|
||||||
|
err = autorest.Respond(
|
||||||
|
resp,
|
||||||
|
client.ByInspecting(),
|
||||||
|
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
||||||
|
autorest.ByUnmarshallingJSON(&result),
|
||||||
|
autorest.ByClosing())
|
||||||
|
result.Response = autorest.Response{Response: resp}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// GetAuthorizationRule returns the specified authorizationRule.
|
// GetAuthorizationRule returns the specified authorizationRule.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. namespaceName is the
|
// resourceGroupName is the name of the resource group. namespaceName is the
|
||||||
// namespace name authorizationRuleName is authorization rule name. topicName
|
// namespace name topicName is the topic name. authorizationRuleName is
|
||||||
// is the topic name.
|
// authorization rule name.
|
||||||
func (client TopicsClient) GetAuthorizationRule(resourceGroupName string, namespaceName string, authorizationRuleName string, topicName string) (result SharedAccessAuthorizationRuleResource, err error) {
|
func (client TopicsClient) GetAuthorizationRule(resourceGroupName string, namespaceName string, topicName string, authorizationRuleName string) (result SharedAccessAuthorizationRuleResource, err error) {
|
||||||
req, err := client.GetAuthorizationRulePreparer(resourceGroupName, namespaceName, authorizationRuleName, topicName)
|
req, err := client.GetAuthorizationRulePreparer(resourceGroupName, namespaceName, topicName, authorizationRuleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "GetAuthorizationRule", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "GetAuthorizationRule", nil, "Failure preparing request")
|
||||||
}
|
}
|
||||||
|
@ -335,7 +408,7 @@ func (client TopicsClient) GetAuthorizationRule(resourceGroupName string, namesp
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAuthorizationRulePreparer prepares the GetAuthorizationRule request.
|
// GetAuthorizationRulePreparer prepares the GetAuthorizationRule request.
|
||||||
func (client TopicsClient) GetAuthorizationRulePreparer(resourceGroupName string, namespaceName string, authorizationRuleName string, topicName string) (*http.Request, error) {
|
func (client TopicsClient) GetAuthorizationRulePreparer(resourceGroupName string, namespaceName string, topicName string, authorizationRuleName string) (*http.Request, error) {
|
||||||
pathParameters := map[string]interface{}{
|
pathParameters := map[string]interface{}{
|
||||||
"authorizationRuleName": autorest.Encode("path", authorizationRuleName),
|
"authorizationRuleName": autorest.Encode("path", authorizationRuleName),
|
||||||
"namespaceName": autorest.Encode("path", namespaceName),
|
"namespaceName": autorest.Encode("path", namespaceName),
|
||||||
|
@ -375,70 +448,6 @@ func (client TopicsClient) GetAuthorizationRuleResponder(resp *http.Response) (r
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTopic returns the description for the specified topic
|
|
||||||
//
|
|
||||||
// resourceGroupName is the name of the resource group. namespaceName is the
|
|
||||||
// namespace name. topicName is the topic name.
|
|
||||||
func (client TopicsClient) GetTopic(resourceGroupName string, namespaceName string, topicName string) (result TopicResource, err error) {
|
|
||||||
req, err := client.GetTopicPreparer(resourceGroupName, namespaceName, topicName)
|
|
||||||
if err != nil {
|
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "GetTopic", nil, "Failure preparing request")
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := client.GetTopicSender(req)
|
|
||||||
if err != nil {
|
|
||||||
result.Response = autorest.Response{Response: resp}
|
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "GetTopic", resp, "Failure sending request")
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err = client.GetTopicResponder(resp)
|
|
||||||
if err != nil {
|
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.TopicsClient", "GetTopic", resp, "Failure responding to request")
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTopicPreparer prepares the GetTopic request.
|
|
||||||
func (client TopicsClient) GetTopicPreparer(resourceGroupName string, namespaceName string, topicName string) (*http.Request, error) {
|
|
||||||
pathParameters := map[string]interface{}{
|
|
||||||
"namespaceName": autorest.Encode("path", namespaceName),
|
|
||||||
"resourceGroupName": autorest.Encode("path", resourceGroupName),
|
|
||||||
"subscriptionId": autorest.Encode("path", client.SubscriptionID),
|
|
||||||
"topicName": autorest.Encode("path", topicName),
|
|
||||||
}
|
|
||||||
|
|
||||||
queryParameters := map[string]interface{}{
|
|
||||||
"api-version": client.APIVersion,
|
|
||||||
}
|
|
||||||
|
|
||||||
preparer := autorest.CreatePreparer(
|
|
||||||
autorest.AsGet(),
|
|
||||||
autorest.WithBaseURL(client.BaseURI),
|
|
||||||
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceBus/namespaces/{namespaceName}/topics/{topicName}", pathParameters),
|
|
||||||
autorest.WithQueryParameters(queryParameters))
|
|
||||||
return preparer.Prepare(&http.Request{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTopicSender sends the GetTopic request. The method will close the
|
|
||||||
// http.Response Body if it receives an error.
|
|
||||||
func (client TopicsClient) GetTopicSender(req *http.Request) (*http.Response, error) {
|
|
||||||
return autorest.SendWithSender(client, req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTopicResponder handles the response to the GetTopic request. The method always
|
|
||||||
// closes the http.Response Body.
|
|
||||||
func (client TopicsClient) GetTopicResponder(resp *http.Response) (result TopicResource, err error) {
|
|
||||||
err = autorest.Respond(
|
|
||||||
resp,
|
|
||||||
client.ByInspecting(),
|
|
||||||
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
|
||||||
autorest.ByUnmarshallingJSON(&result),
|
|
||||||
autorest.ByClosing())
|
|
||||||
result.Response = autorest.Response{Response: resp}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListAll lists all the topics in a namespace.
|
// ListAll lists all the topics in a namespace.
|
||||||
//
|
//
|
||||||
// resourceGroupName is the name of the resource group. namespaceName is the
|
// resourceGroupName is the name of the resource group. namespaceName is the
|
||||||
|
@ -506,7 +515,7 @@ func (client TopicsClient) ListAllResponder(resp *http.Response) (result TopicLi
|
||||||
func (client TopicsClient) ListAllNextResults(lastResults TopicListResult) (result TopicListResult, err error) {
|
func (client TopicsClient) ListAllNextResults(lastResults TopicListResult) (result TopicListResult, err error) {
|
||||||
req, err := lastResults.TopicListResultPreparer()
|
req, err := lastResults.TopicListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAll", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAll", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -515,12 +524,12 @@ func (client TopicsClient) ListAllNextResults(lastResults TopicListResult) (resu
|
||||||
resp, err := client.ListAllSender(req)
|
resp, err := client.ListAllSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAll", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAll", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAllResponder(resp)
|
result, err = client.ListAllResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAll", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAll", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -594,7 +603,7 @@ func (client TopicsClient) ListAuthorizationRulesResponder(resp *http.Response)
|
||||||
func (client TopicsClient) ListAuthorizationRulesNextResults(lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) {
|
func (client TopicsClient) ListAuthorizationRulesNextResults(lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) {
|
||||||
req, err := lastResults.SharedAccessAuthorizationRuleListResultPreparer()
|
req, err := lastResults.SharedAccessAuthorizationRuleListResultPreparer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAuthorizationRules", nil, "Failure preparing next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAuthorizationRules", nil, "Failure preparing next results request")
|
||||||
}
|
}
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return
|
return
|
||||||
|
@ -603,12 +612,12 @@ func (client TopicsClient) ListAuthorizationRulesNextResults(lastResults SharedA
|
||||||
resp, err := client.ListAuthorizationRulesSender(req)
|
resp, err := client.ListAuthorizationRulesSender(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Response = autorest.Response{Response: resp}
|
result.Response = autorest.Response{Response: resp}
|
||||||
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAuthorizationRules", resp, "Failure sending next results request request")
|
return result, autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAuthorizationRules", resp, "Failure sending next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = client.ListAuthorizationRulesResponder(resp)
|
result, err = client.ListAuthorizationRulesResponder(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAuthorizationRules", resp, "Failure responding to next results request request")
|
err = autorest.NewErrorWithError(err, "servicebus.TopicsClient", "ListAuthorizationRules", resp, "Failure responding to next results request")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
major = "3"
|
major = "4"
|
||||||
minor = "2"
|
minor = "0"
|
||||||
patch = "0"
|
patch = "0"
|
||||||
// Always begin a "tag" with a dash (as per http://semver.org)
|
// Always begin a "tag" with a dash (as per http://semver.org)
|
||||||
tag = "-beta"
|
tag = "-beta"
|
||||||
|
|
|
@ -21,6 +21,7 @@ package storage
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
"github.com/Azure/go-autorest/autorest/azure"
|
||||||
|
"github.com/Azure/go-autorest/autorest/validation"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,6 +47,13 @@ func NewAccountsClientWithBaseURI(baseURI string, subscriptionID string) Account
|
||||||
// resource group. Storage account names must be between 3 and 24 characters
|
// resource group. Storage account names must be between 3 and 24 characters
|
||||||
// in length and use numbers and lower-case letters only.
|
// in length and use numbers and lower-case letters only.
|
||||||
func (client AccountsClient) CheckNameAvailability(accountName AccountCheckNameAvailabilityParameters) (result CheckNameAvailabilityResult, err error) {
|
func (client AccountsClient) CheckNameAvailability(accountName AccountCheckNameAvailabilityParameters) (result CheckNameAvailabilityResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{accountName,
|
||||||
|
[]validation.Constraint{{"accountName.Name", validation.Null, true, nil},
|
||||||
|
{"accountName.Type", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "storage.AccountsClient", "CheckNameAvailability")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CheckNameAvailabilityPreparer(accountName)
|
req, err := client.CheckNameAvailabilityPreparer(accountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "CheckNameAvailability", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "CheckNameAvailability", nil, "Failure preparing request")
|
||||||
|
@ -119,6 +127,28 @@ func (client AccountsClient) CheckNameAvailabilityResponder(resp *http.Response)
|
||||||
// characters in length and use numbers and lower-case letters only.
|
// characters in length and use numbers and lower-case letters only.
|
||||||
// parameters is the parameters to provide for the created account.
|
// parameters is the parameters to provide for the created account.
|
||||||
func (client AccountsClient) Create(resourceGroupName string, accountName string, parameters AccountCreateParameters, cancel <-chan struct{}) (result autorest.Response, err error) {
|
func (client AccountsClient) Create(resourceGroupName string, accountName string, parameters AccountCreateParameters, cancel <-chan struct{}) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{accountName,
|
||||||
|
[]validation.Constraint{{"accountName", validation.MaxLength, 24, nil},
|
||||||
|
{"accountName", validation.MinLength, 3, nil}}},
|
||||||
|
{parameters,
|
||||||
|
[]validation.Constraint{{"parameters.Sku", validation.Null, true,
|
||||||
|
[]validation.Constraint{{"Tier", validation.ReadOnly, true, nil}}},
|
||||||
|
{"parameters.Location", validation.Null, true, nil},
|
||||||
|
{"parameters.Properties", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.CustomDomain", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.CustomDomain.Name", validation.Null, true, nil}}},
|
||||||
|
{"parameters.Properties.Encryption", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.Encryption.Services", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"parameters.Properties.Encryption.Services.Blob", validation.Null, false,
|
||||||
|
[]validation.Constraint{{"LastEnabledTime", validation.ReadOnly, true, nil}}},
|
||||||
|
}},
|
||||||
|
{"parameters.Properties.Encryption.KeySource", validation.Null, true, nil},
|
||||||
|
}},
|
||||||
|
}}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "storage.AccountsClient", "Create")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.CreatePreparer(resourceGroupName, accountName, parameters, cancel)
|
req, err := client.CreatePreparer(resourceGroupName, accountName, parameters, cancel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "Create", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "Create", nil, "Failure preparing request")
|
||||||
|
@ -187,6 +217,13 @@ func (client AccountsClient) CreateResponder(resp *http.Response) (result autore
|
||||||
// specified resource group. Storage account names must be between 3 and 24
|
// specified resource group. Storage account names must be between 3 and 24
|
||||||
// characters in length and use numbers and lower-case letters only.
|
// characters in length and use numbers and lower-case letters only.
|
||||||
func (client AccountsClient) Delete(resourceGroupName string, accountName string) (result autorest.Response, err error) {
|
func (client AccountsClient) Delete(resourceGroupName string, accountName string) (result autorest.Response, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{accountName,
|
||||||
|
[]validation.Constraint{{"accountName", validation.MaxLength, 24, nil},
|
||||||
|
{"accountName", validation.MinLength, 3, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "storage.AccountsClient", "Delete")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.DeletePreparer(resourceGroupName, accountName)
|
req, err := client.DeletePreparer(resourceGroupName, accountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "Delete", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "Delete", nil, "Failure preparing request")
|
||||||
|
@ -253,6 +290,13 @@ func (client AccountsClient) DeleteResponder(resp *http.Response) (result autore
|
||||||
// specified resource group. Storage account names must be between 3 and 24
|
// specified resource group. Storage account names must be between 3 and 24
|
||||||
// characters in length and use numbers and lower-case letters only.
|
// characters in length and use numbers and lower-case letters only.
|
||||||
func (client AccountsClient) GetProperties(resourceGroupName string, accountName string) (result Account, err error) {
|
func (client AccountsClient) GetProperties(resourceGroupName string, accountName string) (result Account, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{accountName,
|
||||||
|
[]validation.Constraint{{"accountName", validation.MaxLength, 24, nil},
|
||||||
|
{"accountName", validation.MinLength, 3, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "storage.AccountsClient", "GetProperties")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.GetPropertiesPreparer(resourceGroupName, accountName)
|
req, err := client.GetPropertiesPreparer(resourceGroupName, accountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "GetProperties", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "GetProperties", nil, "Failure preparing request")
|
||||||
|
@ -439,6 +483,13 @@ func (client AccountsClient) ListByResourceGroupResponder(resp *http.Response) (
|
||||||
// resourceGroupName is the name of the resource group. accountName is the
|
// resourceGroupName is the name of the resource group. accountName is the
|
||||||
// name of the storage account.
|
// name of the storage account.
|
||||||
func (client AccountsClient) ListKeys(resourceGroupName string, accountName string) (result AccountListKeysResult, err error) {
|
func (client AccountsClient) ListKeys(resourceGroupName string, accountName string) (result AccountListKeysResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{accountName,
|
||||||
|
[]validation.Constraint{{"accountName", validation.MaxLength, 24, nil},
|
||||||
|
{"accountName", validation.MinLength, 3, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "storage.AccountsClient", "ListKeys")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.ListKeysPreparer(resourceGroupName, accountName)
|
req, err := client.ListKeysPreparer(resourceGroupName, accountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "ListKeys", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "ListKeys", nil, "Failure preparing request")
|
||||||
|
@ -506,6 +557,15 @@ func (client AccountsClient) ListKeysResponder(resp *http.Response) (result Acco
|
||||||
// regenerateKey is specifies name of the key which should be regenerated.
|
// regenerateKey is specifies name of the key which should be regenerated.
|
||||||
// key1 or key2 for the default keys
|
// key1 or key2 for the default keys
|
||||||
func (client AccountsClient) RegenerateKey(resourceGroupName string, accountName string, regenerateKey AccountRegenerateKeyParameters) (result AccountListKeysResult, err error) {
|
func (client AccountsClient) RegenerateKey(resourceGroupName string, accountName string, regenerateKey AccountRegenerateKeyParameters) (result AccountListKeysResult, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{accountName,
|
||||||
|
[]validation.Constraint{{"accountName", validation.MaxLength, 24, nil},
|
||||||
|
{"accountName", validation.MinLength, 3, nil}}},
|
||||||
|
{regenerateKey,
|
||||||
|
[]validation.Constraint{{"regenerateKey.KeyName", validation.Null, true, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "storage.AccountsClient", "RegenerateKey")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.RegenerateKeyPreparer(resourceGroupName, accountName, regenerateKey)
|
req, err := client.RegenerateKeyPreparer(resourceGroupName, accountName, regenerateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "RegenerateKey", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "RegenerateKey", nil, "Failure preparing request")
|
||||||
|
@ -583,6 +643,13 @@ func (client AccountsClient) RegenerateKeyResponder(resp *http.Response) (result
|
||||||
// characters in length and use numbers and lower-case letters only.
|
// characters in length and use numbers and lower-case letters only.
|
||||||
// parameters is the parameters to provide for the updated account.
|
// parameters is the parameters to provide for the updated account.
|
||||||
func (client AccountsClient) Update(resourceGroupName string, accountName string, parameters AccountUpdateParameters) (result Account, err error) {
|
func (client AccountsClient) Update(resourceGroupName string, accountName string, parameters AccountUpdateParameters) (result Account, err error) {
|
||||||
|
if err := validation.Validate([]validation.Validation{
|
||||||
|
{accountName,
|
||||||
|
[]validation.Constraint{{"accountName", validation.MaxLength, 24, nil},
|
||||||
|
{"accountName", validation.MinLength, 3, nil}}}}); err != nil {
|
||||||
|
return result, validation.NewErrorWithValidationError(err, "storage.AccountsClient", "Update")
|
||||||
|
}
|
||||||
|
|
||||||
req, err := client.UpdatePreparer(resourceGroupName, accountName, parameters)
|
req, err := client.UpdatePreparer(resourceGroupName, accountName, parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "Update", nil, "Failure preparing request")
|
return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "Update", nil, "Failure preparing request")
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
major = "3"
|
major = "4"
|
||||||
minor = "2"
|
minor = "0"
|
||||||
patch = "0"
|
patch = "0"
|
||||||
// Always begin a "tag" with a dash (as per http://semver.org)
|
// Always begin a "tag" with a dash (as per http://semver.org)
|
||||||
tag = "-beta"
|
tag = "-beta"
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
major = "3"
|
major = "4"
|
||||||
minor = "2"
|
minor = "0"
|
||||||
patch = "0"
|
patch = "0"
|
||||||
// Always begin a "tag" with a dash (as per http://semver.org)
|
// Always begin a "tag" with a dash (as per http://semver.org)
|
||||||
tag = "-beta"
|
tag = "-beta"
|
||||||
|
|
|
@ -1,203 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// The wire protocol for HTTP's "chunked" Transfer-Encoding.
|
|
||||||
|
|
||||||
// This code is duplicated in net/http and net/http/httputil.
|
|
||||||
// Please make any changes in both files.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
const maxLineLength = 4096 // assumed <= bufio.defaultBufSize
|
|
||||||
|
|
||||||
var ErrLineTooLong = errors.New("header line too long")
|
|
||||||
|
|
||||||
// newChunkedReader returns a new chunkedReader that translates the data read from r
|
|
||||||
// out of HTTP "chunked" format before returning it.
|
|
||||||
// The chunkedReader returns io.EOF when the final 0-length chunk is read.
|
|
||||||
//
|
|
||||||
// newChunkedReader is not needed by normal applications. The http package
|
|
||||||
// automatically decodes chunking when reading response bodies.
|
|
||||||
func newChunkedReader(r io.Reader) io.Reader {
|
|
||||||
br, ok := r.(*bufio.Reader)
|
|
||||||
if !ok {
|
|
||||||
br = bufio.NewReader(r)
|
|
||||||
}
|
|
||||||
return &chunkedReader{r: br}
|
|
||||||
}
|
|
||||||
|
|
||||||
type chunkedReader struct {
|
|
||||||
r *bufio.Reader
|
|
||||||
n uint64 // unread bytes in chunk
|
|
||||||
err error
|
|
||||||
buf [2]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cr *chunkedReader) beginChunk() {
|
|
||||||
// chunk-size CRLF
|
|
||||||
var line []byte
|
|
||||||
line, cr.err = readLine(cr.r)
|
|
||||||
if cr.err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cr.n, cr.err = parseHexUint(line)
|
|
||||||
if cr.err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if cr.n == 0 {
|
|
||||||
cr.err = io.EOF
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cr *chunkedReader) chunkHeaderAvailable() bool {
|
|
||||||
n := cr.r.Buffered()
|
|
||||||
if n > 0 {
|
|
||||||
peek, _ := cr.r.Peek(n)
|
|
||||||
return bytes.IndexByte(peek, '\n') >= 0
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cr *chunkedReader) Read(b []uint8) (n int, err error) {
|
|
||||||
for cr.err == nil {
|
|
||||||
if cr.n == 0 {
|
|
||||||
if n > 0 && !cr.chunkHeaderAvailable() {
|
|
||||||
// We've read enough. Don't potentially block
|
|
||||||
// reading a new chunk header.
|
|
||||||
break
|
|
||||||
}
|
|
||||||
cr.beginChunk()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(b) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rbuf := b
|
|
||||||
if uint64(len(rbuf)) > cr.n {
|
|
||||||
rbuf = rbuf[:cr.n]
|
|
||||||
}
|
|
||||||
var n0 int
|
|
||||||
n0, cr.err = cr.r.Read(rbuf)
|
|
||||||
n += n0
|
|
||||||
b = b[n0:]
|
|
||||||
cr.n -= uint64(n0)
|
|
||||||
// If we're at the end of a chunk, read the next two
|
|
||||||
// bytes to verify they are "\r\n".
|
|
||||||
if cr.n == 0 && cr.err == nil {
|
|
||||||
if _, cr.err = io.ReadFull(cr.r, cr.buf[:2]); cr.err == nil {
|
|
||||||
if cr.buf[0] != '\r' || cr.buf[1] != '\n' {
|
|
||||||
cr.err = errors.New("malformed chunked encoding")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return n, cr.err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read a line of bytes (up to \n) from b.
|
|
||||||
// Give up if the line exceeds maxLineLength.
|
|
||||||
// The returned bytes are a pointer into storage in
|
|
||||||
// the bufio, so they are only valid until the next bufio read.
|
|
||||||
func readLine(b *bufio.Reader) (p []byte, err error) {
|
|
||||||
if p, err = b.ReadSlice('\n'); err != nil {
|
|
||||||
// We always know when EOF is coming.
|
|
||||||
// If the caller asked for a line, there should be a line.
|
|
||||||
if err == io.EOF {
|
|
||||||
err = io.ErrUnexpectedEOF
|
|
||||||
} else if err == bufio.ErrBufferFull {
|
|
||||||
err = ErrLineTooLong
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(p) >= maxLineLength {
|
|
||||||
return nil, ErrLineTooLong
|
|
||||||
}
|
|
||||||
return trimTrailingWhitespace(p), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func trimTrailingWhitespace(b []byte) []byte {
|
|
||||||
for len(b) > 0 && isASCIISpace(b[len(b)-1]) {
|
|
||||||
b = b[:len(b)-1]
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func isASCIISpace(b byte) bool {
|
|
||||||
return b == ' ' || b == '\t' || b == '\n' || b == '\r'
|
|
||||||
}
|
|
||||||
|
|
||||||
// newChunkedWriter returns a new chunkedWriter that translates writes into HTTP
|
|
||||||
// "chunked" format before writing them to w. Closing the returned chunkedWriter
|
|
||||||
// sends the final 0-length chunk that marks the end of the stream.
|
|
||||||
//
|
|
||||||
// newChunkedWriter is not needed by normal applications. The http
|
|
||||||
// package adds chunking automatically if handlers don't set a
|
|
||||||
// Content-Length header. Using newChunkedWriter inside a handler
|
|
||||||
// would result in double chunking or chunking with a Content-Length
|
|
||||||
// length, both of which are wrong.
|
|
||||||
func newChunkedWriter(w io.Writer) io.WriteCloser {
|
|
||||||
return &chunkedWriter{w}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Writing to chunkedWriter translates to writing in HTTP chunked Transfer
|
|
||||||
// Encoding wire format to the underlying Wire chunkedWriter.
|
|
||||||
type chunkedWriter struct {
|
|
||||||
Wire io.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the contents of data as one chunk to Wire.
|
|
||||||
// NOTE: Note that the corresponding chunk-writing procedure in Conn.Write has
|
|
||||||
// a bug since it does not check for success of io.WriteString
|
|
||||||
func (cw *chunkedWriter) Write(data []byte) (n int, err error) {
|
|
||||||
|
|
||||||
// Don't send 0-length data. It looks like EOF for chunked encoding.
|
|
||||||
if len(data) == 0 {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = fmt.Fprintf(cw.Wire, "%x\r\n", len(data)); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
if n, err = cw.Wire.Write(data); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if n != len(data) {
|
|
||||||
err = io.ErrShortWrite
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = io.WriteString(cw.Wire, "\r\n")
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cw *chunkedWriter) Close() error {
|
|
||||||
_, err := io.WriteString(cw.Wire, "0\r\n")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseHexUint(v []byte) (n uint64, err error) {
|
|
||||||
for _, b := range v {
|
|
||||||
n <<= 4
|
|
||||||
switch {
|
|
||||||
case '0' <= b && b <= '9':
|
|
||||||
b = b - '0'
|
|
||||||
case 'a' <= b && b <= 'f':
|
|
||||||
b = b - 'a' + 10
|
|
||||||
case 'A' <= b && b <= 'F':
|
|
||||||
b = b - 'A' + 10
|
|
||||||
default:
|
|
||||||
return 0, errors.New("invalid byte in chunk length")
|
|
||||||
}
|
|
||||||
n |= uint64(b)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,487 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// HTTP client. See RFC 2616.
|
|
||||||
//
|
|
||||||
// This is the high-level Client interface.
|
|
||||||
// The low-level implementation is in transport.go.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/base64"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Client is an HTTP client. Its zero value (DefaultClient) is a
|
|
||||||
// usable client that uses DefaultTransport.
|
|
||||||
//
|
|
||||||
// The Client's Transport typically has internal state (cached TCP
|
|
||||||
// connections), so Clients should be reused instead of created as
|
|
||||||
// needed. Clients are safe for concurrent use by multiple goroutines.
|
|
||||||
//
|
|
||||||
// A Client is higher-level than a RoundTripper (such as Transport)
|
|
||||||
// and additionally handles HTTP details such as cookies and
|
|
||||||
// redirects.
|
|
||||||
type Client struct {
|
|
||||||
// Transport specifies the mechanism by which individual
|
|
||||||
// HTTP requests are made.
|
|
||||||
// If nil, DefaultTransport is used.
|
|
||||||
Transport RoundTripper
|
|
||||||
|
|
||||||
// CheckRedirect specifies the policy for handling redirects.
|
|
||||||
// If CheckRedirect is not nil, the client calls it before
|
|
||||||
// following an HTTP redirect. The arguments req and via are
|
|
||||||
// the upcoming request and the requests made already, oldest
|
|
||||||
// first. If CheckRedirect returns an error, the Client's Get
|
|
||||||
// method returns both the previous Response and
|
|
||||||
// CheckRedirect's error (wrapped in a url.Error) instead of
|
|
||||||
// issuing the Request req.
|
|
||||||
//
|
|
||||||
// If CheckRedirect is nil, the Client uses its default policy,
|
|
||||||
// which is to stop after 10 consecutive requests.
|
|
||||||
CheckRedirect func(req *Request, via []*Request) error
|
|
||||||
|
|
||||||
// Jar specifies the cookie jar.
|
|
||||||
// If Jar is nil, cookies are not sent in requests and ignored
|
|
||||||
// in responses.
|
|
||||||
Jar CookieJar
|
|
||||||
|
|
||||||
// Timeout specifies a time limit for requests made by this
|
|
||||||
// Client. The timeout includes connection time, any
|
|
||||||
// redirects, and reading the response body. The timer remains
|
|
||||||
// running after Get, Head, Post, or Do return and will
|
|
||||||
// interrupt reading of the Response.Body.
|
|
||||||
//
|
|
||||||
// A Timeout of zero means no timeout.
|
|
||||||
//
|
|
||||||
// The Client's Transport must support the CancelRequest
|
|
||||||
// method or Client will return errors when attempting to make
|
|
||||||
// a request with Get, Head, Post, or Do. Client's default
|
|
||||||
// Transport (DefaultTransport) supports CancelRequest.
|
|
||||||
Timeout time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultClient is the default Client and is used by Get, Head, and Post.
|
|
||||||
var DefaultClient = &Client{}
|
|
||||||
|
|
||||||
// RoundTripper is an interface representing the ability to execute a
|
|
||||||
// single HTTP transaction, obtaining the Response for a given Request.
|
|
||||||
//
|
|
||||||
// A RoundTripper must be safe for concurrent use by multiple
|
|
||||||
// goroutines.
|
|
||||||
type RoundTripper interface {
|
|
||||||
// RoundTrip executes a single HTTP transaction, returning
|
|
||||||
// the Response for the request req. RoundTrip should not
|
|
||||||
// attempt to interpret the response. In particular,
|
|
||||||
// RoundTrip must return err == nil if it obtained a response,
|
|
||||||
// regardless of the response's HTTP status code. A non-nil
|
|
||||||
// err should be reserved for failure to obtain a response.
|
|
||||||
// Similarly, RoundTrip should not attempt to handle
|
|
||||||
// higher-level protocol details such as redirects,
|
|
||||||
// authentication, or cookies.
|
|
||||||
//
|
|
||||||
// RoundTrip should not modify the request, except for
|
|
||||||
// consuming and closing the Body, including on errors. The
|
|
||||||
// request's URL and Header fields are guaranteed to be
|
|
||||||
// initialized.
|
|
||||||
RoundTrip(*Request) (*Response, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Given a string of the form "host", "host:port", or "[ipv6::address]:port",
|
|
||||||
// return true if the string includes a port.
|
|
||||||
func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
|
|
||||||
|
|
||||||
// Used in Send to implement io.ReadCloser by bundling together the
|
|
||||||
// bufio.Reader through which we read the response, and the underlying
|
|
||||||
// network connection.
|
|
||||||
type readClose struct {
|
|
||||||
io.Reader
|
|
||||||
io.Closer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) send(req *Request) (*Response, error) {
|
|
||||||
if c.Jar != nil {
|
|
||||||
for _, cookie := range c.Jar.Cookies(req.URL) {
|
|
||||||
req.AddCookie(cookie)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resp, err := send(req, c.transport())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if c.Jar != nil {
|
|
||||||
if rc := resp.Cookies(); len(rc) > 0 {
|
|
||||||
c.Jar.SetCookies(req.URL, rc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do sends an HTTP request and returns an HTTP response, following
|
|
||||||
// policy (e.g. redirects, cookies, auth) as configured on the client.
|
|
||||||
//
|
|
||||||
// An error is returned if caused by client policy (such as
|
|
||||||
// CheckRedirect), or if there was an HTTP protocol error.
|
|
||||||
// A non-2xx response doesn't cause an error.
|
|
||||||
//
|
|
||||||
// When err is nil, resp always contains a non-nil resp.Body.
|
|
||||||
//
|
|
||||||
// Callers should close resp.Body when done reading from it. If
|
|
||||||
// resp.Body is not closed, the Client's underlying RoundTripper
|
|
||||||
// (typically Transport) may not be able to re-use a persistent TCP
|
|
||||||
// connection to the server for a subsequent "keep-alive" request.
|
|
||||||
//
|
|
||||||
// The request Body, if non-nil, will be closed by the underlying
|
|
||||||
// Transport, even on errors.
|
|
||||||
//
|
|
||||||
// Generally Get, Post, or PostForm will be used instead of Do.
|
|
||||||
func (c *Client) Do(req *Request) (resp *Response, err error) {
|
|
||||||
if req.Method == "GET" || req.Method == "HEAD" {
|
|
||||||
return c.doFollowingRedirects(req, shouldRedirectGet)
|
|
||||||
}
|
|
||||||
if req.Method == "POST" || req.Method == "PUT" {
|
|
||||||
return c.doFollowingRedirects(req, shouldRedirectPost)
|
|
||||||
}
|
|
||||||
return c.send(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) transport() RoundTripper {
|
|
||||||
if c.Transport != nil {
|
|
||||||
return c.Transport
|
|
||||||
}
|
|
||||||
return DefaultTransport
|
|
||||||
}
|
|
||||||
|
|
||||||
// send issues an HTTP request.
|
|
||||||
// Caller should close resp.Body when done reading from it.
|
|
||||||
func send(req *Request, t RoundTripper) (resp *Response, err error) {
|
|
||||||
if t == nil {
|
|
||||||
req.closeBody()
|
|
||||||
return nil, errors.New("http: no Client.Transport or DefaultTransport")
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.URL == nil {
|
|
||||||
req.closeBody()
|
|
||||||
return nil, errors.New("http: nil Request.URL")
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.RequestURI != "" {
|
|
||||||
req.closeBody()
|
|
||||||
return nil, errors.New("http: Request.RequestURI can't be set in client requests.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Most the callers of send (Get, Post, et al) don't need
|
|
||||||
// Headers, leaving it uninitialized. We guarantee to the
|
|
||||||
// Transport that this has been initialized, though.
|
|
||||||
if req.Header == nil {
|
|
||||||
req.Header = make(Header)
|
|
||||||
}
|
|
||||||
|
|
||||||
if u := req.URL.User; u != nil {
|
|
||||||
username := u.Username()
|
|
||||||
password, _ := u.Password()
|
|
||||||
req.Header.Set("Authorization", "Basic "+basicAuth(username, password))
|
|
||||||
}
|
|
||||||
resp, err = t.RoundTrip(req)
|
|
||||||
if err != nil {
|
|
||||||
if resp != nil {
|
|
||||||
log.Printf("RoundTripper returned a response & error; ignoring response")
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// See 2 (end of page 4) http://www.ietf.org/rfc/rfc2617.txt
|
|
||||||
// "To receive authorization, the client sends the userid and password,
|
|
||||||
// separated by a single colon (":") character, within a base64
|
|
||||||
// encoded string in the credentials."
|
|
||||||
// It is not meant to be urlencoded.
|
|
||||||
func basicAuth(username, password string) string {
|
|
||||||
auth := username + ":" + password
|
|
||||||
return base64.StdEncoding.EncodeToString([]byte(auth))
|
|
||||||
}
|
|
||||||
|
|
||||||
// True if the specified HTTP status code is one for which the Get utility should
|
|
||||||
// automatically redirect.
|
|
||||||
func shouldRedirectGet(statusCode int) bool {
|
|
||||||
switch statusCode {
|
|
||||||
case StatusMovedPermanently, StatusFound, StatusSeeOther, StatusTemporaryRedirect:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// True if the specified HTTP status code is one for which the Post utility should
|
|
||||||
// automatically redirect.
|
|
||||||
func shouldRedirectPost(statusCode int) bool {
|
|
||||||
switch statusCode {
|
|
||||||
case StatusFound, StatusSeeOther:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get issues a GET to the specified URL. If the response is one of the following
|
|
||||||
// redirect codes, Get follows the redirect, up to a maximum of 10 redirects:
|
|
||||||
//
|
|
||||||
// 301 (Moved Permanently)
|
|
||||||
// 302 (Found)
|
|
||||||
// 303 (See Other)
|
|
||||||
// 307 (Temporary Redirect)
|
|
||||||
//
|
|
||||||
// An error is returned if there were too many redirects or if there
|
|
||||||
// was an HTTP protocol error. A non-2xx response doesn't cause an
|
|
||||||
// error.
|
|
||||||
//
|
|
||||||
// When err is nil, resp always contains a non-nil resp.Body.
|
|
||||||
// Caller should close resp.Body when done reading from it.
|
|
||||||
//
|
|
||||||
// Get is a wrapper around DefaultClient.Get.
|
|
||||||
func Get(url string) (resp *Response, err error) {
|
|
||||||
return DefaultClient.Get(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get issues a GET to the specified URL. If the response is one of the
|
|
||||||
// following redirect codes, Get follows the redirect after calling the
|
|
||||||
// Client's CheckRedirect function.
|
|
||||||
//
|
|
||||||
// 301 (Moved Permanently)
|
|
||||||
// 302 (Found)
|
|
||||||
// 303 (See Other)
|
|
||||||
// 307 (Temporary Redirect)
|
|
||||||
//
|
|
||||||
// An error is returned if the Client's CheckRedirect function fails
|
|
||||||
// or if there was an HTTP protocol error. A non-2xx response doesn't
|
|
||||||
// cause an error.
|
|
||||||
//
|
|
||||||
// When err is nil, resp always contains a non-nil resp.Body.
|
|
||||||
// Caller should close resp.Body when done reading from it.
|
|
||||||
func (c *Client) Get(url string) (resp *Response, err error) {
|
|
||||||
req, err := NewRequest("GET", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return c.doFollowingRedirects(req, shouldRedirectGet)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) doFollowingRedirects(ireq *Request, shouldRedirect func(int) bool) (resp *Response, err error) {
|
|
||||||
var base *url.URL
|
|
||||||
redirectChecker := c.CheckRedirect
|
|
||||||
if redirectChecker == nil {
|
|
||||||
redirectChecker = defaultCheckRedirect
|
|
||||||
}
|
|
||||||
var via []*Request
|
|
||||||
|
|
||||||
if ireq.URL == nil {
|
|
||||||
ireq.closeBody()
|
|
||||||
return nil, errors.New("http: nil Request.URL")
|
|
||||||
}
|
|
||||||
|
|
||||||
var reqmu sync.Mutex // guards req
|
|
||||||
req := ireq
|
|
||||||
|
|
||||||
var timer *time.Timer
|
|
||||||
if c.Timeout > 0 {
|
|
||||||
type canceler interface {
|
|
||||||
CancelRequest(*Request)
|
|
||||||
}
|
|
||||||
tr, ok := c.transport().(canceler)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("net/http: Client Transport of type %T doesn't support CancelRequest; Timeout not supported", c.transport())
|
|
||||||
}
|
|
||||||
timer = time.AfterFunc(c.Timeout, func() {
|
|
||||||
reqmu.Lock()
|
|
||||||
defer reqmu.Unlock()
|
|
||||||
tr.CancelRequest(req)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
urlStr := "" // next relative or absolute URL to fetch (after first request)
|
|
||||||
redirectFailed := false
|
|
||||||
for redirect := 0; ; redirect++ {
|
|
||||||
if redirect != 0 {
|
|
||||||
nreq := new(Request)
|
|
||||||
nreq.Method = ireq.Method
|
|
||||||
if ireq.Method == "POST" || ireq.Method == "PUT" {
|
|
||||||
nreq.Method = "GET"
|
|
||||||
}
|
|
||||||
nreq.Header = make(Header)
|
|
||||||
nreq.URL, err = base.Parse(urlStr)
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if len(via) > 0 {
|
|
||||||
// Add the Referer header.
|
|
||||||
lastReq := via[len(via)-1]
|
|
||||||
if lastReq.URL.Scheme != "https" {
|
|
||||||
nreq.Header.Set("Referer", lastReq.URL.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
err = redirectChecker(nreq, via)
|
|
||||||
if err != nil {
|
|
||||||
redirectFailed = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reqmu.Lock()
|
|
||||||
req = nreq
|
|
||||||
reqmu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
urlStr = req.URL.String()
|
|
||||||
if resp, err = c.send(req); err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if shouldRedirect(resp.StatusCode) {
|
|
||||||
// Read the body if small so underlying TCP connection will be re-used.
|
|
||||||
// No need to check for errors: if it fails, Transport won't reuse it anyway.
|
|
||||||
const maxBodySlurpSize = 2 << 10
|
|
||||||
if resp.ContentLength == -1 || resp.ContentLength <= maxBodySlurpSize {
|
|
||||||
io.CopyN(ioutil.Discard, resp.Body, maxBodySlurpSize)
|
|
||||||
}
|
|
||||||
resp.Body.Close()
|
|
||||||
if urlStr = resp.Header.Get("Location"); urlStr == "" {
|
|
||||||
err = errors.New(fmt.Sprintf("%d response missing Location header", resp.StatusCode))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
base = req.URL
|
|
||||||
via = append(via, req)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if timer != nil {
|
|
||||||
resp.Body = &cancelTimerBody{timer, resp.Body}
|
|
||||||
}
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
method := ireq.Method
|
|
||||||
urlErr := &url.Error{
|
|
||||||
Op: method[0:1] + strings.ToLower(method[1:]),
|
|
||||||
URL: urlStr,
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
|
|
||||||
if redirectFailed {
|
|
||||||
// Special case for Go 1 compatibility: return both the response
|
|
||||||
// and an error if the CheckRedirect function failed.
|
|
||||||
// See http://golang.org/issue/3795
|
|
||||||
return resp, urlErr
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp != nil {
|
|
||||||
resp.Body.Close()
|
|
||||||
}
|
|
||||||
return nil, urlErr
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultCheckRedirect(req *Request, via []*Request) error {
|
|
||||||
if len(via) >= 10 {
|
|
||||||
return errors.New("stopped after 10 redirects")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post issues a POST to the specified URL.
|
|
||||||
//
|
|
||||||
// Caller should close resp.Body when done reading from it.
|
|
||||||
//
|
|
||||||
// Post is a wrapper around DefaultClient.Post
|
|
||||||
func Post(url string, bodyType string, body io.Reader) (resp *Response, err error) {
|
|
||||||
return DefaultClient.Post(url, bodyType, body)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post issues a POST to the specified URL.
|
|
||||||
//
|
|
||||||
// Caller should close resp.Body when done reading from it.
|
|
||||||
//
|
|
||||||
// If the provided body is also an io.Closer, it is closed after the
|
|
||||||
// request.
|
|
||||||
func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *Response, err error) {
|
|
||||||
req, err := NewRequest("POST", url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", bodyType)
|
|
||||||
return c.doFollowingRedirects(req, shouldRedirectPost)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PostForm issues a POST to the specified URL, with data's keys and
|
|
||||||
// values URL-encoded as the request body.
|
|
||||||
//
|
|
||||||
// When err is nil, resp always contains a non-nil resp.Body.
|
|
||||||
// Caller should close resp.Body when done reading from it.
|
|
||||||
//
|
|
||||||
// PostForm is a wrapper around DefaultClient.PostForm
|
|
||||||
func PostForm(url string, data url.Values) (resp *Response, err error) {
|
|
||||||
return DefaultClient.PostForm(url, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PostForm issues a POST to the specified URL,
|
|
||||||
// with data's keys and values urlencoded as the request body.
|
|
||||||
//
|
|
||||||
// When err is nil, resp always contains a non-nil resp.Body.
|
|
||||||
// Caller should close resp.Body when done reading from it.
|
|
||||||
func (c *Client) PostForm(url string, data url.Values) (resp *Response, err error) {
|
|
||||||
return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Head issues a HEAD to the specified URL. If the response is one of the
|
|
||||||
// following redirect codes, Head follows the redirect after calling the
|
|
||||||
// Client's CheckRedirect function.
|
|
||||||
//
|
|
||||||
// 301 (Moved Permanently)
|
|
||||||
// 302 (Found)
|
|
||||||
// 303 (See Other)
|
|
||||||
// 307 (Temporary Redirect)
|
|
||||||
//
|
|
||||||
// Head is a wrapper around DefaultClient.Head
|
|
||||||
func Head(url string) (resp *Response, err error) {
|
|
||||||
return DefaultClient.Head(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Head issues a HEAD to the specified URL. If the response is one of the
|
|
||||||
// following redirect codes, Head follows the redirect after calling the
|
|
||||||
// Client's CheckRedirect function.
|
|
||||||
//
|
|
||||||
// 301 (Moved Permanently)
|
|
||||||
// 302 (Found)
|
|
||||||
// 303 (See Other)
|
|
||||||
// 307 (Temporary Redirect)
|
|
||||||
func (c *Client) Head(url string) (resp *Response, err error) {
|
|
||||||
req, err := NewRequest("HEAD", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return c.doFollowingRedirects(req, shouldRedirectGet)
|
|
||||||
}
|
|
||||||
|
|
||||||
type cancelTimerBody struct {
|
|
||||||
t *time.Timer
|
|
||||||
rc io.ReadCloser
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *cancelTimerBody) Read(p []byte) (n int, err error) {
|
|
||||||
n, err = b.rc.Read(p)
|
|
||||||
if err == io.EOF {
|
|
||||||
b.t.Stop()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *cancelTimerBody) Close() error {
|
|
||||||
err := b.rc.Close()
|
|
||||||
b.t.Stop()
|
|
||||||
return err
|
|
||||||
}
|
|
|
@ -1,363 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// This implementation is done according to RFC 6265:
|
|
||||||
//
|
|
||||||
// http://tools.ietf.org/html/rfc6265
|
|
||||||
|
|
||||||
// A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an
|
|
||||||
// HTTP response or the Cookie header of an HTTP request.
|
|
||||||
type Cookie struct {
|
|
||||||
Name string
|
|
||||||
Value string
|
|
||||||
Path string
|
|
||||||
Domain string
|
|
||||||
Expires time.Time
|
|
||||||
RawExpires string
|
|
||||||
|
|
||||||
// MaxAge=0 means no 'Max-Age' attribute specified.
|
|
||||||
// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
|
|
||||||
// MaxAge>0 means Max-Age attribute present and given in seconds
|
|
||||||
MaxAge int
|
|
||||||
Secure bool
|
|
||||||
HttpOnly bool
|
|
||||||
Raw string
|
|
||||||
Unparsed []string // Raw text of unparsed attribute-value pairs
|
|
||||||
}
|
|
||||||
|
|
||||||
// readSetCookies parses all "Set-Cookie" values from
|
|
||||||
// the header h and returns the successfully parsed Cookies.
|
|
||||||
func readSetCookies(h Header) []*Cookie {
|
|
||||||
cookies := []*Cookie{}
|
|
||||||
for _, line := range h["Set-Cookie"] {
|
|
||||||
parts := strings.Split(strings.TrimSpace(line), ";")
|
|
||||||
if len(parts) == 1 && parts[0] == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
parts[0] = strings.TrimSpace(parts[0])
|
|
||||||
j := strings.Index(parts[0], "=")
|
|
||||||
if j < 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name, value := parts[0][:j], parts[0][j+1:]
|
|
||||||
if !isCookieNameValid(name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
value, success := parseCookieValue(value)
|
|
||||||
if !success {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
c := &Cookie{
|
|
||||||
Name: name,
|
|
||||||
Value: value,
|
|
||||||
Raw: line,
|
|
||||||
}
|
|
||||||
for i := 1; i < len(parts); i++ {
|
|
||||||
parts[i] = strings.TrimSpace(parts[i])
|
|
||||||
if len(parts[i]) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
attr, val := parts[i], ""
|
|
||||||
if j := strings.Index(attr, "="); j >= 0 {
|
|
||||||
attr, val = attr[:j], attr[j+1:]
|
|
||||||
}
|
|
||||||
lowerAttr := strings.ToLower(attr)
|
|
||||||
val, success = parseCookieValue(val)
|
|
||||||
if !success {
|
|
||||||
c.Unparsed = append(c.Unparsed, parts[i])
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch lowerAttr {
|
|
||||||
case "secure":
|
|
||||||
c.Secure = true
|
|
||||||
continue
|
|
||||||
case "httponly":
|
|
||||||
c.HttpOnly = true
|
|
||||||
continue
|
|
||||||
case "domain":
|
|
||||||
c.Domain = val
|
|
||||||
continue
|
|
||||||
case "max-age":
|
|
||||||
secs, err := strconv.Atoi(val)
|
|
||||||
if err != nil || secs != 0 && val[0] == '0' {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if secs <= 0 {
|
|
||||||
c.MaxAge = -1
|
|
||||||
} else {
|
|
||||||
c.MaxAge = secs
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
case "expires":
|
|
||||||
c.RawExpires = val
|
|
||||||
exptime, err := time.Parse(time.RFC1123, val)
|
|
||||||
if err != nil {
|
|
||||||
exptime, err = time.Parse("Mon, 02-Jan-2006 15:04:05 MST", val)
|
|
||||||
if err != nil {
|
|
||||||
c.Expires = time.Time{}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.Expires = exptime.UTC()
|
|
||||||
continue
|
|
||||||
case "path":
|
|
||||||
c.Path = val
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
c.Unparsed = append(c.Unparsed, parts[i])
|
|
||||||
}
|
|
||||||
cookies = append(cookies, c)
|
|
||||||
}
|
|
||||||
return cookies
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetCookie adds a Set-Cookie header to the provided ResponseWriter's headers.
|
|
||||||
func SetCookie(w ResponseWriter, cookie *Cookie) {
|
|
||||||
w.Header().Add("Set-Cookie", cookie.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the serialization of the cookie for use in a Cookie
|
|
||||||
// header (if only Name and Value are set) or a Set-Cookie response
|
|
||||||
// header (if other fields are set).
|
|
||||||
func (c *Cookie) String() string {
|
|
||||||
var b bytes.Buffer
|
|
||||||
fmt.Fprintf(&b, "%s=%s", sanitizeCookieName(c.Name), sanitizeCookieValue(c.Value))
|
|
||||||
if len(c.Path) > 0 {
|
|
||||||
fmt.Fprintf(&b, "; Path=%s", sanitizeCookiePath(c.Path))
|
|
||||||
}
|
|
||||||
if len(c.Domain) > 0 {
|
|
||||||
if validCookieDomain(c.Domain) {
|
|
||||||
// A c.Domain containing illegal characters is not
|
|
||||||
// sanitized but simply dropped which turns the cookie
|
|
||||||
// into a host-only cookie. A leading dot is okay
|
|
||||||
// but won't be sent.
|
|
||||||
d := c.Domain
|
|
||||||
if d[0] == '.' {
|
|
||||||
d = d[1:]
|
|
||||||
}
|
|
||||||
fmt.Fprintf(&b, "; Domain=%s", d)
|
|
||||||
} else {
|
|
||||||
log.Printf("net/http: invalid Cookie.Domain %q; dropping domain attribute",
|
|
||||||
c.Domain)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if c.Expires.Unix() > 0 {
|
|
||||||
fmt.Fprintf(&b, "; Expires=%s", c.Expires.UTC().Format(time.RFC1123))
|
|
||||||
}
|
|
||||||
if c.MaxAge > 0 {
|
|
||||||
fmt.Fprintf(&b, "; Max-Age=%d", c.MaxAge)
|
|
||||||
} else if c.MaxAge < 0 {
|
|
||||||
fmt.Fprintf(&b, "; Max-Age=0")
|
|
||||||
}
|
|
||||||
if c.HttpOnly {
|
|
||||||
fmt.Fprintf(&b, "; HttpOnly")
|
|
||||||
}
|
|
||||||
if c.Secure {
|
|
||||||
fmt.Fprintf(&b, "; Secure")
|
|
||||||
}
|
|
||||||
return b.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// readCookies parses all "Cookie" values from the header h and
|
|
||||||
// returns the successfully parsed Cookies.
|
|
||||||
//
|
|
||||||
// if filter isn't empty, only cookies of that name are returned
|
|
||||||
func readCookies(h Header, filter string) []*Cookie {
|
|
||||||
cookies := []*Cookie{}
|
|
||||||
lines, ok := h["Cookie"]
|
|
||||||
if !ok {
|
|
||||||
return cookies
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line := range lines {
|
|
||||||
parts := strings.Split(strings.TrimSpace(line), ";")
|
|
||||||
if len(parts) == 1 && parts[0] == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Per-line attributes
|
|
||||||
parsedPairs := 0
|
|
||||||
for i := 0; i < len(parts); i++ {
|
|
||||||
parts[i] = strings.TrimSpace(parts[i])
|
|
||||||
if len(parts[i]) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name, val := parts[i], ""
|
|
||||||
if j := strings.Index(name, "="); j >= 0 {
|
|
||||||
name, val = name[:j], name[j+1:]
|
|
||||||
}
|
|
||||||
if !isCookieNameValid(name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if filter != "" && filter != name {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val, success := parseCookieValue(val)
|
|
||||||
if !success {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
cookies = append(cookies, &Cookie{Name: name, Value: val})
|
|
||||||
parsedPairs++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cookies
|
|
||||||
}
|
|
||||||
|
|
||||||
// validCookieDomain returns wheter v is a valid cookie domain-value.
|
|
||||||
func validCookieDomain(v string) bool {
|
|
||||||
if isCookieDomainName(v) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if net.ParseIP(v) != nil && !strings.Contains(v, ":") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// isCookieDomainName returns whether s is a valid domain name or a valid
|
|
||||||
// domain name with a leading dot '.'. It is almost a direct copy of
|
|
||||||
// package net's isDomainName.
|
|
||||||
func isCookieDomainName(s string) bool {
|
|
||||||
if len(s) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(s) > 255 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if s[0] == '.' {
|
|
||||||
// A cookie a domain attribute may start with a leading dot.
|
|
||||||
s = s[1:]
|
|
||||||
}
|
|
||||||
last := byte('.')
|
|
||||||
ok := false // Ok once we've seen a letter.
|
|
||||||
partlen := 0
|
|
||||||
for i := 0; i < len(s); i++ {
|
|
||||||
c := s[i]
|
|
||||||
switch {
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z':
|
|
||||||
// No '_' allowed here (in contrast to package net).
|
|
||||||
ok = true
|
|
||||||
partlen++
|
|
||||||
case '0' <= c && c <= '9':
|
|
||||||
// fine
|
|
||||||
partlen++
|
|
||||||
case c == '-':
|
|
||||||
// Byte before dash cannot be dot.
|
|
||||||
if last == '.' {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
partlen++
|
|
||||||
case c == '.':
|
|
||||||
// Byte before dot cannot be dot, dash.
|
|
||||||
if last == '.' || last == '-' {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if partlen > 63 || partlen == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
partlen = 0
|
|
||||||
}
|
|
||||||
last = c
|
|
||||||
}
|
|
||||||
if last == '-' || partlen > 63 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
var cookieNameSanitizer = strings.NewReplacer("\n", "-", "\r", "-")
|
|
||||||
|
|
||||||
func sanitizeCookieName(n string) string {
|
|
||||||
return cookieNameSanitizer.Replace(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://tools.ietf.org/html/rfc6265#section-4.1.1
|
|
||||||
// cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
|
|
||||||
// cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
|
|
||||||
// ; US-ASCII characters excluding CTLs,
|
|
||||||
// ; whitespace DQUOTE, comma, semicolon,
|
|
||||||
// ; and backslash
|
|
||||||
// We loosen this as spaces and commas are common in cookie values
|
|
||||||
// but we produce a quoted cookie-value in when value starts or ends
|
|
||||||
// with a comma or space.
|
|
||||||
// See http://golang.org/issue/7243 for the discussion.
|
|
||||||
func sanitizeCookieValue(v string) string {
|
|
||||||
v = sanitizeOrWarn("Cookie.Value", validCookieValueByte, v)
|
|
||||||
if len(v) == 0 {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
if v[0] == ' ' || v[0] == ',' || v[len(v)-1] == ' ' || v[len(v)-1] == ',' {
|
|
||||||
return `"` + v + `"`
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func validCookieValueByte(b byte) bool {
|
|
||||||
return 0x20 <= b && b < 0x7f && b != '"' && b != ';' && b != '\\'
|
|
||||||
}
|
|
||||||
|
|
||||||
// path-av = "Path=" path-value
|
|
||||||
// path-value = <any CHAR except CTLs or ";">
|
|
||||||
func sanitizeCookiePath(v string) string {
|
|
||||||
return sanitizeOrWarn("Cookie.Path", validCookiePathByte, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func validCookiePathByte(b byte) bool {
|
|
||||||
return 0x20 <= b && b < 0x7f && b != ';'
|
|
||||||
}
|
|
||||||
|
|
||||||
func sanitizeOrWarn(fieldName string, valid func(byte) bool, v string) string {
|
|
||||||
ok := true
|
|
||||||
for i := 0; i < len(v); i++ {
|
|
||||||
if valid(v[i]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
log.Printf("net/http: invalid byte %q in %s; dropping invalid bytes", v[i], fieldName)
|
|
||||||
ok = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
buf := make([]byte, 0, len(v))
|
|
||||||
for i := 0; i < len(v); i++ {
|
|
||||||
if b := v[i]; valid(b) {
|
|
||||||
buf = append(buf, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseCookieValue(raw string) (string, bool) {
|
|
||||||
// Strip the quotes, if present.
|
|
||||||
if len(raw) > 1 && raw[0] == '"' && raw[len(raw)-1] == '"' {
|
|
||||||
raw = raw[1 : len(raw)-1]
|
|
||||||
}
|
|
||||||
for i := 0; i < len(raw); i++ {
|
|
||||||
if !validCookieValueByte(raw[i]) {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return raw, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func isCookieNameValid(raw string) bool {
|
|
||||||
return strings.IndexFunc(raw, isNotToken) < 0
|
|
||||||
}
|
|
|
@ -1,80 +0,0 @@
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package http provides HTTP client and server implementations.
|
|
||||||
|
|
||||||
Get, Head, Post, and PostForm make HTTP (or HTTPS) requests:
|
|
||||||
|
|
||||||
resp, err := http.Get("http://example.com/")
|
|
||||||
...
|
|
||||||
resp, err := http.Post("http://example.com/upload", "image/jpeg", &buf)
|
|
||||||
...
|
|
||||||
resp, err := http.PostForm("http://example.com/form",
|
|
||||||
url.Values{"key": {"Value"}, "id": {"123"}})
|
|
||||||
|
|
||||||
The client must close the response body when finished with it:
|
|
||||||
|
|
||||||
resp, err := http.Get("http://example.com/")
|
|
||||||
if err != nil {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
For control over HTTP client headers, redirect policy, and other
|
|
||||||
settings, create a Client:
|
|
||||||
|
|
||||||
client := &http.Client{
|
|
||||||
CheckRedirect: redirectPolicyFunc,
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := client.Get("http://example.com")
|
|
||||||
// ...
|
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "http://example.com", nil)
|
|
||||||
// ...
|
|
||||||
req.Header.Add("If-None-Match", `W/"wyzzy"`)
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
// ...
|
|
||||||
|
|
||||||
For control over proxies, TLS configuration, keep-alives,
|
|
||||||
compression, and other settings, create a Transport:
|
|
||||||
|
|
||||||
tr := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{RootCAs: pool},
|
|
||||||
DisableCompression: true,
|
|
||||||
}
|
|
||||||
client := &http.Client{Transport: tr}
|
|
||||||
resp, err := client.Get("https://example.com")
|
|
||||||
|
|
||||||
Clients and Transports are safe for concurrent use by multiple
|
|
||||||
goroutines and for efficiency should only be created once and re-used.
|
|
||||||
|
|
||||||
ListenAndServe starts an HTTP server with a given address and handler.
|
|
||||||
The handler is usually nil, which means to use DefaultServeMux.
|
|
||||||
Handle and HandleFunc add handlers to DefaultServeMux:
|
|
||||||
|
|
||||||
http.Handle("/foo", fooHandler)
|
|
||||||
|
|
||||||
http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
|
||||||
})
|
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
||||||
|
|
||||||
More control over the server's behavior is available by creating a
|
|
||||||
custom Server:
|
|
||||||
|
|
||||||
s := &http.Server{
|
|
||||||
Addr: ":8080",
|
|
||||||
Handler: myHandler,
|
|
||||||
ReadTimeout: 10 * time.Second,
|
|
||||||
WriteTimeout: 10 * time.Second,
|
|
||||||
MaxHeaderBytes: 1 << 20,
|
|
||||||
}
|
|
||||||
log.Fatal(s.ListenAndServe())
|
|
||||||
*/
|
|
||||||
package http
|
|
|
@ -1,123 +0,0 @@
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// fileTransport implements RoundTripper for the 'file' protocol.
|
|
||||||
type fileTransport struct {
|
|
||||||
fh fileHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFileTransport returns a new RoundTripper, serving the provided
|
|
||||||
// FileSystem. The returned RoundTripper ignores the URL host in its
|
|
||||||
// incoming requests, as well as most other properties of the
|
|
||||||
// request.
|
|
||||||
//
|
|
||||||
// The typical use case for NewFileTransport is to register the "file"
|
|
||||||
// protocol with a Transport, as in:
|
|
||||||
//
|
|
||||||
// t := &http.Transport{}
|
|
||||||
// t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
|
|
||||||
// c := &http.Client{Transport: t}
|
|
||||||
// res, err := c.Get("file:///etc/passwd")
|
|
||||||
// ...
|
|
||||||
func NewFileTransport(fs FileSystem) RoundTripper {
|
|
||||||
return fileTransport{fileHandler{fs}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t fileTransport) RoundTrip(req *Request) (resp *Response, err error) {
|
|
||||||
// We start ServeHTTP in a goroutine, which may take a long
|
|
||||||
// time if the file is large. The newPopulateResponseWriter
|
|
||||||
// call returns a channel which either ServeHTTP or finish()
|
|
||||||
// sends our *Response on, once the *Response itself has been
|
|
||||||
// populated (even if the body itself is still being
|
|
||||||
// written to the res.Body, a pipe)
|
|
||||||
rw, resc := newPopulateResponseWriter()
|
|
||||||
go func() {
|
|
||||||
t.fh.ServeHTTP(rw, req)
|
|
||||||
rw.finish()
|
|
||||||
}()
|
|
||||||
return <-resc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newPopulateResponseWriter() (*populateResponse, <-chan *Response) {
|
|
||||||
pr, pw := io.Pipe()
|
|
||||||
rw := &populateResponse{
|
|
||||||
ch: make(chan *Response),
|
|
||||||
pw: pw,
|
|
||||||
res: &Response{
|
|
||||||
Proto: "HTTP/1.0",
|
|
||||||
ProtoMajor: 1,
|
|
||||||
Header: make(Header),
|
|
||||||
Close: true,
|
|
||||||
Body: pr,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return rw, rw.ch
|
|
||||||
}
|
|
||||||
|
|
||||||
// populateResponse is a ResponseWriter that populates the *Response
|
|
||||||
// in res, and writes its body to a pipe connected to the response
|
|
||||||
// body. Once writes begin or finish() is called, the response is sent
|
|
||||||
// on ch.
|
|
||||||
type populateResponse struct {
|
|
||||||
res *Response
|
|
||||||
ch chan *Response
|
|
||||||
wroteHeader bool
|
|
||||||
hasContent bool
|
|
||||||
sentResponse bool
|
|
||||||
pw *io.PipeWriter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pr *populateResponse) finish() {
|
|
||||||
if !pr.wroteHeader {
|
|
||||||
pr.WriteHeader(500)
|
|
||||||
}
|
|
||||||
if !pr.sentResponse {
|
|
||||||
pr.sendResponse()
|
|
||||||
}
|
|
||||||
pr.pw.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pr *populateResponse) sendResponse() {
|
|
||||||
if pr.sentResponse {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pr.sentResponse = true
|
|
||||||
|
|
||||||
if pr.hasContent {
|
|
||||||
pr.res.ContentLength = -1
|
|
||||||
}
|
|
||||||
pr.ch <- pr.res
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pr *populateResponse) Header() Header {
|
|
||||||
return pr.res.Header
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pr *populateResponse) WriteHeader(code int) {
|
|
||||||
if pr.wroteHeader {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pr.wroteHeader = true
|
|
||||||
|
|
||||||
pr.res.StatusCode = code
|
|
||||||
pr.res.Status = fmt.Sprintf("%d %s", code, StatusText(code))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pr *populateResponse) Write(p []byte) (n int, err error) {
|
|
||||||
if !pr.wroteHeader {
|
|
||||||
pr.WriteHeader(StatusOK)
|
|
||||||
}
|
|
||||||
pr.hasContent = true
|
|
||||||
if !pr.sentResponse {
|
|
||||||
pr.sendResponse()
|
|
||||||
}
|
|
||||||
return pr.pw.Write(p)
|
|
||||||
}
|
|
|
@ -1,549 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// HTTP file system request handler
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"mime"
|
|
||||||
"mime/multipart"
|
|
||||||
"net/textproto"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Dir implements http.FileSystem using the native file
|
|
||||||
// system restricted to a specific directory tree.
|
|
||||||
//
|
|
||||||
// An empty Dir is treated as ".".
|
|
||||||
type Dir string
|
|
||||||
|
|
||||||
func (d Dir) Open(name string) (File, error) {
|
|
||||||
if filepath.Separator != '/' && strings.IndexRune(name, filepath.Separator) >= 0 ||
|
|
||||||
strings.Contains(name, "\x00") {
|
|
||||||
return nil, errors.New("http: invalid character in file path")
|
|
||||||
}
|
|
||||||
dir := string(d)
|
|
||||||
if dir == "" {
|
|
||||||
dir = "."
|
|
||||||
}
|
|
||||||
f, err := os.Open(filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name))))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return f, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// A FileSystem implements access to a collection of named files.
|
|
||||||
// The elements in a file path are separated by slash ('/', U+002F)
|
|
||||||
// characters, regardless of host operating system convention.
|
|
||||||
type FileSystem interface {
|
|
||||||
Open(name string) (File, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A File is returned by a FileSystem's Open method and can be
|
|
||||||
// served by the FileServer implementation.
|
|
||||||
//
|
|
||||||
// The methods should behave the same as those on an *os.File.
|
|
||||||
type File interface {
|
|
||||||
io.Closer
|
|
||||||
io.Reader
|
|
||||||
Readdir(count int) ([]os.FileInfo, error)
|
|
||||||
Seek(offset int64, whence int) (int64, error)
|
|
||||||
Stat() (os.FileInfo, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func dirList(w ResponseWriter, f File) {
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
||||||
fmt.Fprintf(w, "<pre>\n")
|
|
||||||
for {
|
|
||||||
dirs, err := f.Readdir(100)
|
|
||||||
if err != nil || len(dirs) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
for _, d := range dirs {
|
|
||||||
name := d.Name()
|
|
||||||
if d.IsDir() {
|
|
||||||
name += "/"
|
|
||||||
}
|
|
||||||
// name may contain '?' or '#', which must be escaped to remain
|
|
||||||
// part of the URL path, and not indicate the start of a query
|
|
||||||
// string or fragment.
|
|
||||||
url := url.URL{Path: name}
|
|
||||||
fmt.Fprintf(w, "<a href=\"%s\">%s</a>\n", url.String(), htmlReplacer.Replace(name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprintf(w, "</pre>\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServeContent replies to the request using the content in the
|
|
||||||
// provided ReadSeeker. The main benefit of ServeContent over io.Copy
|
|
||||||
// is that it handles Range requests properly, sets the MIME type, and
|
|
||||||
// handles If-Modified-Since requests.
|
|
||||||
//
|
|
||||||
// If the response's Content-Type header is not set, ServeContent
|
|
||||||
// first tries to deduce the type from name's file extension and,
|
|
||||||
// if that fails, falls back to reading the first block of the content
|
|
||||||
// and passing it to DetectContentType.
|
|
||||||
// The name is otherwise unused; in particular it can be empty and is
|
|
||||||
// never sent in the response.
|
|
||||||
//
|
|
||||||
// If modtime is not the zero time, ServeContent includes it in a
|
|
||||||
// Last-Modified header in the response. If the request includes an
|
|
||||||
// If-Modified-Since header, ServeContent uses modtime to decide
|
|
||||||
// whether the content needs to be sent at all.
|
|
||||||
//
|
|
||||||
// The content's Seek method must work: ServeContent uses
|
|
||||||
// a seek to the end of the content to determine its size.
|
|
||||||
//
|
|
||||||
// If the caller has set w's ETag header, ServeContent uses it to
|
|
||||||
// handle requests using If-Range and If-None-Match.
|
|
||||||
//
|
|
||||||
// Note that *os.File implements the io.ReadSeeker interface.
|
|
||||||
func ServeContent(w ResponseWriter, req *Request, name string, modtime time.Time, content io.ReadSeeker) {
|
|
||||||
sizeFunc := func() (int64, error) {
|
|
||||||
size, err := content.Seek(0, os.SEEK_END)
|
|
||||||
if err != nil {
|
|
||||||
return 0, errSeeker
|
|
||||||
}
|
|
||||||
_, err = content.Seek(0, os.SEEK_SET)
|
|
||||||
if err != nil {
|
|
||||||
return 0, errSeeker
|
|
||||||
}
|
|
||||||
return size, nil
|
|
||||||
}
|
|
||||||
serveContent(w, req, name, modtime, sizeFunc, content)
|
|
||||||
}
|
|
||||||
|
|
||||||
// errSeeker is returned by ServeContent's sizeFunc when the content
|
|
||||||
// doesn't seek properly. The underlying Seeker's error text isn't
|
|
||||||
// included in the sizeFunc reply so it's not sent over HTTP to end
|
|
||||||
// users.
|
|
||||||
var errSeeker = errors.New("seeker can't seek")
|
|
||||||
|
|
||||||
// if name is empty, filename is unknown. (used for mime type, before sniffing)
|
|
||||||
// if modtime.IsZero(), modtime is unknown.
|
|
||||||
// content must be seeked to the beginning of the file.
|
|
||||||
// The sizeFunc is called at most once. Its error, if any, is sent in the HTTP response.
|
|
||||||
func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time, sizeFunc func() (int64, error), content io.ReadSeeker) {
|
|
||||||
if checkLastModified(w, r, modtime) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rangeReq, done := checkETag(w, r)
|
|
||||||
if done {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
code := StatusOK
|
|
||||||
|
|
||||||
// If Content-Type isn't set, use the file's extension to find it, but
|
|
||||||
// if the Content-Type is unset explicitly, do not sniff the type.
|
|
||||||
ctypes, haveType := w.Header()["Content-Type"]
|
|
||||||
var ctype string
|
|
||||||
if !haveType {
|
|
||||||
ctype = mime.TypeByExtension(filepath.Ext(name))
|
|
||||||
if ctype == "" {
|
|
||||||
// read a chunk to decide between utf-8 text and binary
|
|
||||||
var buf [sniffLen]byte
|
|
||||||
n, _ := io.ReadFull(content, buf[:])
|
|
||||||
ctype = DetectContentType(buf[:n])
|
|
||||||
_, err := content.Seek(0, os.SEEK_SET) // rewind to output whole file
|
|
||||||
if err != nil {
|
|
||||||
Error(w, "seeker can't seek", StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Type", ctype)
|
|
||||||
} else if len(ctypes) > 0 {
|
|
||||||
ctype = ctypes[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
size, err := sizeFunc()
|
|
||||||
if err != nil {
|
|
||||||
Error(w, err.Error(), StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle Content-Range header.
|
|
||||||
sendSize := size
|
|
||||||
var sendContent io.Reader = content
|
|
||||||
if size >= 0 {
|
|
||||||
ranges, err := parseRange(rangeReq, size)
|
|
||||||
if err != nil {
|
|
||||||
Error(w, err.Error(), StatusRequestedRangeNotSatisfiable)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if sumRangesSize(ranges) > size {
|
|
||||||
// The total number of bytes in all the ranges
|
|
||||||
// is larger than the size of the file by
|
|
||||||
// itself, so this is probably an attack, or a
|
|
||||||
// dumb client. Ignore the range request.
|
|
||||||
ranges = nil
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case len(ranges) == 1:
|
|
||||||
// RFC 2616, Section 14.16:
|
|
||||||
// "When an HTTP message includes the content of a single
|
|
||||||
// range (for example, a response to a request for a
|
|
||||||
// single range, or to a request for a set of ranges
|
|
||||||
// that overlap without any holes), this content is
|
|
||||||
// transmitted with a Content-Range header, and a
|
|
||||||
// Content-Length header showing the number of bytes
|
|
||||||
// actually transferred.
|
|
||||||
// ...
|
|
||||||
// A response to a request for a single range MUST NOT
|
|
||||||
// be sent using the multipart/byteranges media type."
|
|
||||||
ra := ranges[0]
|
|
||||||
if _, err := content.Seek(ra.start, os.SEEK_SET); err != nil {
|
|
||||||
Error(w, err.Error(), StatusRequestedRangeNotSatisfiable)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sendSize = ra.length
|
|
||||||
code = StatusPartialContent
|
|
||||||
w.Header().Set("Content-Range", ra.contentRange(size))
|
|
||||||
case len(ranges) > 1:
|
|
||||||
for _, ra := range ranges {
|
|
||||||
if ra.start > size {
|
|
||||||
Error(w, err.Error(), StatusRequestedRangeNotSatisfiable)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendSize = rangesMIMESize(ranges, ctype, size)
|
|
||||||
code = StatusPartialContent
|
|
||||||
|
|
||||||
pr, pw := io.Pipe()
|
|
||||||
mw := multipart.NewWriter(pw)
|
|
||||||
w.Header().Set("Content-Type", "multipart/byteranges; boundary="+mw.Boundary())
|
|
||||||
sendContent = pr
|
|
||||||
defer pr.Close() // cause writing goroutine to fail and exit if CopyN doesn't finish.
|
|
||||||
go func() {
|
|
||||||
for _, ra := range ranges {
|
|
||||||
part, err := mw.CreatePart(ra.mimeHeader(ctype, size))
|
|
||||||
if err != nil {
|
|
||||||
pw.CloseWithError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, err := content.Seek(ra.start, os.SEEK_SET); err != nil {
|
|
||||||
pw.CloseWithError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, err := io.CopyN(part, content, ra.length); err != nil {
|
|
||||||
pw.CloseWithError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mw.Close()
|
|
||||||
pw.Close()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Accept-Ranges", "bytes")
|
|
||||||
if w.Header().Get("Content-Encoding") == "" {
|
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(sendSize, 10))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
w.WriteHeader(code)
|
|
||||||
|
|
||||||
if r.Method != "HEAD" {
|
|
||||||
io.CopyN(w, sendContent, sendSize)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// modtime is the modification time of the resource to be served, or IsZero().
|
|
||||||
// return value is whether this request is now complete.
|
|
||||||
func checkLastModified(w ResponseWriter, r *Request, modtime time.Time) bool {
|
|
||||||
if modtime.IsZero() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// The Date-Modified header truncates sub-second precision, so
|
|
||||||
// use mtime < t+1s instead of mtime <= t to check for unmodified.
|
|
||||||
if t, err := time.Parse(TimeFormat, r.Header.Get("If-Modified-Since")); err == nil && modtime.Before(t.Add(1*time.Second)) {
|
|
||||||
h := w.Header()
|
|
||||||
delete(h, "Content-Type")
|
|
||||||
delete(h, "Content-Length")
|
|
||||||
w.WriteHeader(StatusNotModified)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
w.Header().Set("Last-Modified", modtime.UTC().Format(TimeFormat))
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkETag implements If-None-Match and If-Range checks.
|
|
||||||
// The ETag must have been previously set in the ResponseWriter's headers.
|
|
||||||
//
|
|
||||||
// The return value is the effective request "Range" header to use and
|
|
||||||
// whether this request is now considered done.
|
|
||||||
func checkETag(w ResponseWriter, r *Request) (rangeReq string, done bool) {
|
|
||||||
etag := w.Header().get("Etag")
|
|
||||||
rangeReq = r.Header.get("Range")
|
|
||||||
|
|
||||||
// Invalidate the range request if the entity doesn't match the one
|
|
||||||
// the client was expecting.
|
|
||||||
// "If-Range: version" means "ignore the Range: header unless version matches the
|
|
||||||
// current file."
|
|
||||||
// We only support ETag versions.
|
|
||||||
// The caller must have set the ETag on the response already.
|
|
||||||
if ir := r.Header.get("If-Range"); ir != "" && ir != etag {
|
|
||||||
// TODO(bradfitz): handle If-Range requests with Last-Modified
|
|
||||||
// times instead of ETags? I'd rather not, at least for
|
|
||||||
// now. That seems like a bug/compromise in the RFC 2616, and
|
|
||||||
// I've never heard of anybody caring about that (yet).
|
|
||||||
rangeReq = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if inm := r.Header.get("If-None-Match"); inm != "" {
|
|
||||||
// Must know ETag.
|
|
||||||
if etag == "" {
|
|
||||||
return rangeReq, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(bradfitz): non-GET/HEAD requests require more work:
|
|
||||||
// sending a different status code on matches, and
|
|
||||||
// also can't use weak cache validators (those with a "W/
|
|
||||||
// prefix). But most users of ServeContent will be using
|
|
||||||
// it on GET or HEAD, so only support those for now.
|
|
||||||
if r.Method != "GET" && r.Method != "HEAD" {
|
|
||||||
return rangeReq, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(bradfitz): deal with comma-separated or multiple-valued
|
|
||||||
// list of If-None-match values. For now just handle the common
|
|
||||||
// case of a single item.
|
|
||||||
if inm == etag || inm == "*" {
|
|
||||||
h := w.Header()
|
|
||||||
delete(h, "Content-Type")
|
|
||||||
delete(h, "Content-Length")
|
|
||||||
w.WriteHeader(StatusNotModified)
|
|
||||||
return "", true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rangeReq, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// name is '/'-separated, not filepath.Separator.
|
|
||||||
func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirect bool) {
|
|
||||||
const indexPage = "/index.html"
|
|
||||||
|
|
||||||
// redirect .../index.html to .../
|
|
||||||
// can't use Redirect() because that would make the path absolute,
|
|
||||||
// which would be a problem running under StripPrefix
|
|
||||||
if strings.HasSuffix(r.URL.Path, indexPage) {
|
|
||||||
localRedirect(w, r, "./")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := fs.Open(name)
|
|
||||||
if err != nil {
|
|
||||||
// TODO expose actual error?
|
|
||||||
NotFound(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
d, err1 := f.Stat()
|
|
||||||
if err1 != nil {
|
|
||||||
// TODO expose actual error?
|
|
||||||
NotFound(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if redirect {
|
|
||||||
// redirect to canonical path: / at end of directory url
|
|
||||||
// r.URL.Path always begins with /
|
|
||||||
url := r.URL.Path
|
|
||||||
if d.IsDir() {
|
|
||||||
if url[len(url)-1] != '/' {
|
|
||||||
localRedirect(w, r, path.Base(url)+"/")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if url[len(url)-1] == '/' {
|
|
||||||
localRedirect(w, r, "../"+path.Base(url))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// use contents of index.html for directory, if present
|
|
||||||
if d.IsDir() {
|
|
||||||
index := name + indexPage
|
|
||||||
ff, err := fs.Open(index)
|
|
||||||
if err == nil {
|
|
||||||
defer ff.Close()
|
|
||||||
dd, err := ff.Stat()
|
|
||||||
if err == nil {
|
|
||||||
name = index
|
|
||||||
d = dd
|
|
||||||
f = ff
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Still a directory? (we didn't find an index.html file)
|
|
||||||
if d.IsDir() {
|
|
||||||
if checkLastModified(w, r, d.ModTime()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
dirList(w, f)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// serverContent will check modification time
|
|
||||||
sizeFunc := func() (int64, error) { return d.Size(), nil }
|
|
||||||
serveContent(w, r, d.Name(), d.ModTime(), sizeFunc, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// localRedirect gives a Moved Permanently response.
|
|
||||||
// It does not convert relative paths to absolute paths like Redirect does.
|
|
||||||
func localRedirect(w ResponseWriter, r *Request, newPath string) {
|
|
||||||
if q := r.URL.RawQuery; q != "" {
|
|
||||||
newPath += "?" + q
|
|
||||||
}
|
|
||||||
w.Header().Set("Location", newPath)
|
|
||||||
w.WriteHeader(StatusMovedPermanently)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServeFile replies to the request with the contents of the named file or directory.
|
|
||||||
func ServeFile(w ResponseWriter, r *Request, name string) {
|
|
||||||
dir, file := filepath.Split(name)
|
|
||||||
serveFile(w, r, Dir(dir), file, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
type fileHandler struct {
|
|
||||||
root FileSystem
|
|
||||||
}
|
|
||||||
|
|
||||||
// FileServer returns a handler that serves HTTP requests
|
|
||||||
// with the contents of the file system rooted at root.
|
|
||||||
//
|
|
||||||
// To use the operating system's file system implementation,
|
|
||||||
// use http.Dir:
|
|
||||||
//
|
|
||||||
// http.Handle("/", http.FileServer(http.Dir("/tmp")))
|
|
||||||
func FileServer(root FileSystem) Handler {
|
|
||||||
return &fileHandler{root}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *fileHandler) ServeHTTP(w ResponseWriter, r *Request) {
|
|
||||||
upath := r.URL.Path
|
|
||||||
if !strings.HasPrefix(upath, "/") {
|
|
||||||
upath = "/" + upath
|
|
||||||
r.URL.Path = upath
|
|
||||||
}
|
|
||||||
serveFile(w, r, f.root, path.Clean(upath), true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// httpRange specifies the byte range to be sent to the client.
|
|
||||||
type httpRange struct {
|
|
||||||
start, length int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r httpRange) contentRange(size int64) string {
|
|
||||||
return fmt.Sprintf("bytes %d-%d/%d", r.start, r.start+r.length-1, size)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r httpRange) mimeHeader(contentType string, size int64) textproto.MIMEHeader {
|
|
||||||
return textproto.MIMEHeader{
|
|
||||||
"Content-Range": {r.contentRange(size)},
|
|
||||||
"Content-Type": {contentType},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseRange parses a Range header string as per RFC 2616.
|
|
||||||
func parseRange(s string, size int64) ([]httpRange, error) {
|
|
||||||
if s == "" {
|
|
||||||
return nil, nil // header not present
|
|
||||||
}
|
|
||||||
const b = "bytes="
|
|
||||||
if !strings.HasPrefix(s, b) {
|
|
||||||
return nil, errors.New("invalid range")
|
|
||||||
}
|
|
||||||
var ranges []httpRange
|
|
||||||
for _, ra := range strings.Split(s[len(b):], ",") {
|
|
||||||
ra = strings.TrimSpace(ra)
|
|
||||||
if ra == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
i := strings.Index(ra, "-")
|
|
||||||
if i < 0 {
|
|
||||||
return nil, errors.New("invalid range")
|
|
||||||
}
|
|
||||||
start, end := strings.TrimSpace(ra[:i]), strings.TrimSpace(ra[i+1:])
|
|
||||||
var r httpRange
|
|
||||||
if start == "" {
|
|
||||||
// If no start is specified, end specifies the
|
|
||||||
// range start relative to the end of the file.
|
|
||||||
i, err := strconv.ParseInt(end, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("invalid range")
|
|
||||||
}
|
|
||||||
if i > size {
|
|
||||||
i = size
|
|
||||||
}
|
|
||||||
r.start = size - i
|
|
||||||
r.length = size - r.start
|
|
||||||
} else {
|
|
||||||
i, err := strconv.ParseInt(start, 10, 64)
|
|
||||||
if err != nil || i > size || i < 0 {
|
|
||||||
return nil, errors.New("invalid range")
|
|
||||||
}
|
|
||||||
r.start = i
|
|
||||||
if end == "" {
|
|
||||||
// If no end is specified, range extends to end of the file.
|
|
||||||
r.length = size - r.start
|
|
||||||
} else {
|
|
||||||
i, err := strconv.ParseInt(end, 10, 64)
|
|
||||||
if err != nil || r.start > i {
|
|
||||||
return nil, errors.New("invalid range")
|
|
||||||
}
|
|
||||||
if i >= size {
|
|
||||||
i = size - 1
|
|
||||||
}
|
|
||||||
r.length = i - r.start + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ranges = append(ranges, r)
|
|
||||||
}
|
|
||||||
return ranges, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// countingWriter counts how many bytes have been written to it.
|
|
||||||
type countingWriter int64
|
|
||||||
|
|
||||||
func (w *countingWriter) Write(p []byte) (n int, err error) {
|
|
||||||
*w += countingWriter(len(p))
|
|
||||||
return len(p), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// rangesMIMESize returns the number of bytes it takes to encode the
|
|
||||||
// provided ranges as a multipart response.
|
|
||||||
func rangesMIMESize(ranges []httpRange, contentType string, contentSize int64) (encSize int64) {
|
|
||||||
var w countingWriter
|
|
||||||
mw := multipart.NewWriter(&w)
|
|
||||||
for _, ra := range ranges {
|
|
||||||
mw.CreatePart(ra.mimeHeader(contentType, contentSize))
|
|
||||||
encSize += ra.length
|
|
||||||
}
|
|
||||||
mw.Close()
|
|
||||||
encSize += int64(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func sumRangesSize(ranges []httpRange) (size int64) {
|
|
||||||
for _, ra := range ranges {
|
|
||||||
size += ra.length
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,211 +0,0 @@
|
||||||
// Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/textproto"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var raceEnabled = false // set by race.go
|
|
||||||
|
|
||||||
// A Header represents the key-value pairs in an HTTP header.
|
|
||||||
type Header map[string][]string
|
|
||||||
|
|
||||||
// Add adds the key, value pair to the header.
|
|
||||||
// It appends to any existing values associated with key.
|
|
||||||
func (h Header) Add(key, value string) {
|
|
||||||
textproto.MIMEHeader(h).Add(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set sets the header entries associated with key to
|
|
||||||
// the single element value. It replaces any existing
|
|
||||||
// values associated with key.
|
|
||||||
func (h Header) Set(key, value string) {
|
|
||||||
textproto.MIMEHeader(h).Set(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets the first value associated with the given key.
|
|
||||||
// If there are no values associated with the key, Get returns "".
|
|
||||||
// To access multiple values of a key, access the map directly
|
|
||||||
// with CanonicalHeaderKey.
|
|
||||||
func (h Header) Get(key string) string {
|
|
||||||
return textproto.MIMEHeader(h).Get(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
// get is like Get, but key must already be in CanonicalHeaderKey form.
|
|
||||||
func (h Header) get(key string) string {
|
|
||||||
if v := h[key]; len(v) > 0 {
|
|
||||||
return v[0]
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Del deletes the values associated with key.
|
|
||||||
func (h Header) Del(key string) {
|
|
||||||
textproto.MIMEHeader(h).Del(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write writes a header in wire format.
|
|
||||||
func (h Header) Write(w io.Writer) error {
|
|
||||||
return h.WriteSubset(w, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h Header) clone() Header {
|
|
||||||
h2 := make(Header, len(h))
|
|
||||||
for k, vv := range h {
|
|
||||||
vv2 := make([]string, len(vv))
|
|
||||||
copy(vv2, vv)
|
|
||||||
h2[k] = vv2
|
|
||||||
}
|
|
||||||
return h2
|
|
||||||
}
|
|
||||||
|
|
||||||
var timeFormats = []string{
|
|
||||||
TimeFormat,
|
|
||||||
time.RFC850,
|
|
||||||
time.ANSIC,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseTime parses a time header (such as the Date: header),
|
|
||||||
// trying each of the three formats allowed by HTTP/1.1:
|
|
||||||
// TimeFormat, time.RFC850, and time.ANSIC.
|
|
||||||
func ParseTime(text string) (t time.Time, err error) {
|
|
||||||
for _, layout := range timeFormats {
|
|
||||||
t, err = time.Parse(layout, text)
|
|
||||||
if err == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var headerNewlineToSpace = strings.NewReplacer("\n", " ", "\r", " ")
|
|
||||||
|
|
||||||
type writeStringer interface {
|
|
||||||
WriteString(string) (int, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// stringWriter implements WriteString on a Writer.
|
|
||||||
type stringWriter struct {
|
|
||||||
w io.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w stringWriter) WriteString(s string) (n int, err error) {
|
|
||||||
return w.w.Write([]byte(s))
|
|
||||||
}
|
|
||||||
|
|
||||||
type keyValues struct {
|
|
||||||
key string
|
|
||||||
values []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// A headerSorter implements sort.Interface by sorting a []keyValues
|
|
||||||
// by key. It's used as a pointer, so it can fit in a sort.Interface
|
|
||||||
// interface value without allocation.
|
|
||||||
type headerSorter struct {
|
|
||||||
kvs []keyValues
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *headerSorter) Len() int { return len(s.kvs) }
|
|
||||||
func (s *headerSorter) Swap(i, j int) { s.kvs[i], s.kvs[j] = s.kvs[j], s.kvs[i] }
|
|
||||||
func (s *headerSorter) Less(i, j int) bool { return s.kvs[i].key < s.kvs[j].key }
|
|
||||||
|
|
||||||
var headerSorterPool = sync.Pool{
|
|
||||||
New: func() interface{} { return new(headerSorter) },
|
|
||||||
}
|
|
||||||
|
|
||||||
// sortedKeyValues returns h's keys sorted in the returned kvs
|
|
||||||
// slice. The headerSorter used to sort is also returned, for possible
|
|
||||||
// return to headerSorterCache.
|
|
||||||
func (h Header) sortedKeyValues(exclude map[string]bool) (kvs []keyValues, hs *headerSorter) {
|
|
||||||
hs = headerSorterPool.Get().(*headerSorter)
|
|
||||||
if cap(hs.kvs) < len(h) {
|
|
||||||
hs.kvs = make([]keyValues, 0, len(h))
|
|
||||||
}
|
|
||||||
kvs = hs.kvs[:0]
|
|
||||||
for k, vv := range h {
|
|
||||||
if !exclude[k] {
|
|
||||||
kvs = append(kvs, keyValues{k, vv})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hs.kvs = kvs
|
|
||||||
sort.Sort(hs)
|
|
||||||
return kvs, hs
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteSubset writes a header in wire format.
|
|
||||||
// If exclude is not nil, keys where exclude[key] == true are not written.
|
|
||||||
func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error {
|
|
||||||
ws, ok := w.(writeStringer)
|
|
||||||
if !ok {
|
|
||||||
ws = stringWriter{w}
|
|
||||||
}
|
|
||||||
kvs, sorter := h.sortedKeyValues(exclude)
|
|
||||||
for _, kv := range kvs {
|
|
||||||
for _, v := range kv.values {
|
|
||||||
v = headerNewlineToSpace.Replace(v)
|
|
||||||
v = textproto.TrimString(v)
|
|
||||||
for _, s := range []string{kv.key, ": ", v, "\r\n"} {
|
|
||||||
if _, err := ws.WriteString(s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
headerSorterPool.Put(sorter)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanonicalHeaderKey returns the canonical format of the
|
|
||||||
// header key s. The canonicalization converts the first
|
|
||||||
// letter and any letter following a hyphen to upper case;
|
|
||||||
// the rest are converted to lowercase. For example, the
|
|
||||||
// canonical key for "accept-encoding" is "Accept-Encoding".
|
|
||||||
func CanonicalHeaderKey(s string) string { return textproto.CanonicalMIMEHeaderKey(s) }
|
|
||||||
|
|
||||||
// hasToken reports whether token appears with v, ASCII
|
|
||||||
// case-insensitive, with space or comma boundaries.
|
|
||||||
// token must be all lowercase.
|
|
||||||
// v may contain mixed cased.
|
|
||||||
func hasToken(v, token string) bool {
|
|
||||||
if len(token) > len(v) || token == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if v == token {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
for sp := 0; sp <= len(v)-len(token); sp++ {
|
|
||||||
// Check that first character is good.
|
|
||||||
// The token is ASCII, so checking only a single byte
|
|
||||||
// is sufficient. We skip this potential starting
|
|
||||||
// position if both the first byte and its potential
|
|
||||||
// ASCII uppercase equivalent (b|0x20) don't match.
|
|
||||||
// False positives ('^' => '~') are caught by EqualFold.
|
|
||||||
if b := v[sp]; b != token[0] && b|0x20 != token[0] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Check that start pos is on a valid token boundary.
|
|
||||||
if sp > 0 && !isTokenBoundary(v[sp-1]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Check that end pos is on a valid token boundary.
|
|
||||||
if endPos := sp + len(token); endPos != len(v) && !isTokenBoundary(v[endPos]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if strings.EqualFold(v[sp:sp+len(token)], token) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func isTokenBoundary(b byte) bool {
|
|
||||||
return b == ' ' || b == ',' || b == '\t'
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/url"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A CookieJar manages storage and use of cookies in HTTP requests.
|
|
||||||
//
|
|
||||||
// Implementations of CookieJar must be safe for concurrent use by multiple
|
|
||||||
// goroutines.
|
|
||||||
//
|
|
||||||
// The net/http/cookiejar package provides a CookieJar implementation.
|
|
||||||
type CookieJar interface {
|
|
||||||
// SetCookies handles the receipt of the cookies in a reply for the
|
|
||||||
// given URL. It may or may not choose to save the cookies, depending
|
|
||||||
// on the jar's policy and implementation.
|
|
||||||
SetCookies(u *url.URL, cookies []*Cookie)
|
|
||||||
|
|
||||||
// Cookies returns the cookies to send in a request for the given URL.
|
|
||||||
// It is up to the implementation to honor the standard cookie use
|
|
||||||
// restrictions such as in RFC 6265.
|
|
||||||
Cookies(u *url.URL) []*Cookie
|
|
||||||
}
|
|
|
@ -1,96 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
// This file deals with lexical matters of HTTP
|
|
||||||
|
|
||||||
var isTokenTable = [127]bool{
|
|
||||||
'!': true,
|
|
||||||
'#': true,
|
|
||||||
'$': true,
|
|
||||||
'%': true,
|
|
||||||
'&': true,
|
|
||||||
'\'': true,
|
|
||||||
'*': true,
|
|
||||||
'+': true,
|
|
||||||
'-': true,
|
|
||||||
'.': true,
|
|
||||||
'0': true,
|
|
||||||
'1': true,
|
|
||||||
'2': true,
|
|
||||||
'3': true,
|
|
||||||
'4': true,
|
|
||||||
'5': true,
|
|
||||||
'6': true,
|
|
||||||
'7': true,
|
|
||||||
'8': true,
|
|
||||||
'9': true,
|
|
||||||
'A': true,
|
|
||||||
'B': true,
|
|
||||||
'C': true,
|
|
||||||
'D': true,
|
|
||||||
'E': true,
|
|
||||||
'F': true,
|
|
||||||
'G': true,
|
|
||||||
'H': true,
|
|
||||||
'I': true,
|
|
||||||
'J': true,
|
|
||||||
'K': true,
|
|
||||||
'L': true,
|
|
||||||
'M': true,
|
|
||||||
'N': true,
|
|
||||||
'O': true,
|
|
||||||
'P': true,
|
|
||||||
'Q': true,
|
|
||||||
'R': true,
|
|
||||||
'S': true,
|
|
||||||
'T': true,
|
|
||||||
'U': true,
|
|
||||||
'W': true,
|
|
||||||
'V': true,
|
|
||||||
'X': true,
|
|
||||||
'Y': true,
|
|
||||||
'Z': true,
|
|
||||||
'^': true,
|
|
||||||
'_': true,
|
|
||||||
'`': true,
|
|
||||||
'a': true,
|
|
||||||
'b': true,
|
|
||||||
'c': true,
|
|
||||||
'd': true,
|
|
||||||
'e': true,
|
|
||||||
'f': true,
|
|
||||||
'g': true,
|
|
||||||
'h': true,
|
|
||||||
'i': true,
|
|
||||||
'j': true,
|
|
||||||
'k': true,
|
|
||||||
'l': true,
|
|
||||||
'm': true,
|
|
||||||
'n': true,
|
|
||||||
'o': true,
|
|
||||||
'p': true,
|
|
||||||
'q': true,
|
|
||||||
'r': true,
|
|
||||||
's': true,
|
|
||||||
't': true,
|
|
||||||
'u': true,
|
|
||||||
'v': true,
|
|
||||||
'w': true,
|
|
||||||
'x': true,
|
|
||||||
'y': true,
|
|
||||||
'z': true,
|
|
||||||
'|': true,
|
|
||||||
'~': true,
|
|
||||||
}
|
|
||||||
|
|
||||||
func isToken(r rune) bool {
|
|
||||||
i := int(r)
|
|
||||||
return i < len(isTokenTable) && isTokenTable[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
func isNotToken(r rune) bool {
|
|
||||||
return !isToken(r)
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
// Copyright 2014 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build race
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
raceEnabled = true
|
|
||||||
}
|
|
|
@ -1,875 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// HTTP Request reading and parsing.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"crypto/tls"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"mime"
|
|
||||||
"mime/multipart"
|
|
||||||
"net/textproto"
|
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
maxValueLength = 4096
|
|
||||||
maxHeaderLines = 1024
|
|
||||||
chunkSize = 4 << 10 // 4 KB chunks
|
|
||||||
defaultMaxMemory = 32 << 20 // 32 MB
|
|
||||||
)
|
|
||||||
|
|
||||||
// ErrMissingFile is returned by FormFile when the provided file field name
|
|
||||||
// is either not present in the request or not a file field.
|
|
||||||
var ErrMissingFile = errors.New("http: no such file")
|
|
||||||
|
|
||||||
// HTTP request parsing errors.
|
|
||||||
type ProtocolError struct {
|
|
||||||
ErrorString string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err *ProtocolError) Error() string { return err.ErrorString }
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrHeaderTooLong = &ProtocolError{"header too long"}
|
|
||||||
ErrShortBody = &ProtocolError{"entity body too short"}
|
|
||||||
ErrNotSupported = &ProtocolError{"feature not supported"}
|
|
||||||
ErrUnexpectedTrailer = &ProtocolError{"trailer header without chunked transfer encoding"}
|
|
||||||
ErrMissingContentLength = &ProtocolError{"missing ContentLength in HEAD response"}
|
|
||||||
ErrNotMultipart = &ProtocolError{"request Content-Type isn't multipart/form-data"}
|
|
||||||
ErrMissingBoundary = &ProtocolError{"no multipart boundary param in Content-Type"}
|
|
||||||
)
|
|
||||||
|
|
||||||
type badStringError struct {
|
|
||||||
what string
|
|
||||||
str string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *badStringError) Error() string { return fmt.Sprintf("%s %q", e.what, e.str) }
|
|
||||||
|
|
||||||
// Headers that Request.Write handles itself and should be skipped.
|
|
||||||
var reqWriteExcludeHeader = map[string]bool{
|
|
||||||
"Host": true, // not in Header map anyway
|
|
||||||
"User-Agent": true,
|
|
||||||
"Content-Length": true,
|
|
||||||
"Transfer-Encoding": true,
|
|
||||||
"Trailer": true,
|
|
||||||
}
|
|
||||||
|
|
||||||
// A Request represents an HTTP request received by a server
|
|
||||||
// or to be sent by a client.
|
|
||||||
//
|
|
||||||
// The field semantics differ slightly between client and server
|
|
||||||
// usage. In addition to the notes on the fields below, see the
|
|
||||||
// documentation for Request.Write and RoundTripper.
|
|
||||||
type Request struct {
|
|
||||||
// Method specifies the HTTP method (GET, POST, PUT, etc.).
|
|
||||||
// For client requests an empty string means GET.
|
|
||||||
Method string
|
|
||||||
|
|
||||||
// URL specifies either the URI being requested (for server
|
|
||||||
// requests) or the URL to access (for client requests).
|
|
||||||
//
|
|
||||||
// For server requests the URL is parsed from the URI
|
|
||||||
// supplied on the Request-Line as stored in RequestURI. For
|
|
||||||
// most requests, fields other than Path and RawQuery will be
|
|
||||||
// empty. (See RFC 2616, Section 5.1.2)
|
|
||||||
//
|
|
||||||
// For client requests, the URL's Host specifies the server to
|
|
||||||
// connect to, while the Request's Host field optionally
|
|
||||||
// specifies the Host header value to send in the HTTP
|
|
||||||
// request.
|
|
||||||
URL *url.URL
|
|
||||||
|
|
||||||
// The protocol version for incoming requests.
|
|
||||||
// Client requests always use HTTP/1.1.
|
|
||||||
Proto string // "HTTP/1.0"
|
|
||||||
ProtoMajor int // 1
|
|
||||||
ProtoMinor int // 0
|
|
||||||
|
|
||||||
// A header maps request lines to their values.
|
|
||||||
// If the header says
|
|
||||||
//
|
|
||||||
// accept-encoding: gzip, deflate
|
|
||||||
// Accept-Language: en-us
|
|
||||||
// Connection: keep-alive
|
|
||||||
//
|
|
||||||
// then
|
|
||||||
//
|
|
||||||
// Header = map[string][]string{
|
|
||||||
// "Accept-Encoding": {"gzip, deflate"},
|
|
||||||
// "Accept-Language": {"en-us"},
|
|
||||||
// "Connection": {"keep-alive"},
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// HTTP defines that header names are case-insensitive.
|
|
||||||
// The request parser implements this by canonicalizing the
|
|
||||||
// name, making the first character and any characters
|
|
||||||
// following a hyphen uppercase and the rest lowercase.
|
|
||||||
//
|
|
||||||
// For client requests certain headers are automatically
|
|
||||||
// added and may override values in Header.
|
|
||||||
//
|
|
||||||
// See the documentation for the Request.Write method.
|
|
||||||
Header Header
|
|
||||||
|
|
||||||
// Body is the request's body.
|
|
||||||
//
|
|
||||||
// For client requests a nil body means the request has no
|
|
||||||
// body, such as a GET request. The HTTP Client's Transport
|
|
||||||
// is responsible for calling the Close method.
|
|
||||||
//
|
|
||||||
// For server requests the Request Body is always non-nil
|
|
||||||
// but will return EOF immediately when no body is present.
|
|
||||||
// The Server will close the request body. The ServeHTTP
|
|
||||||
// Handler does not need to.
|
|
||||||
Body io.ReadCloser
|
|
||||||
|
|
||||||
// ContentLength records the length of the associated content.
|
|
||||||
// The value -1 indicates that the length is unknown.
|
|
||||||
// Values >= 0 indicate that the given number of bytes may
|
|
||||||
// be read from Body.
|
|
||||||
// For client requests, a value of 0 means unknown if Body is not nil.
|
|
||||||
ContentLength int64
|
|
||||||
|
|
||||||
// TransferEncoding lists the transfer encodings from outermost to
|
|
||||||
// innermost. An empty list denotes the "identity" encoding.
|
|
||||||
// TransferEncoding can usually be ignored; chunked encoding is
|
|
||||||
// automatically added and removed as necessary when sending and
|
|
||||||
// receiving requests.
|
|
||||||
TransferEncoding []string
|
|
||||||
|
|
||||||
// Close indicates whether to close the connection after
|
|
||||||
// replying to this request (for servers) or after sending
|
|
||||||
// the request (for clients).
|
|
||||||
Close bool
|
|
||||||
|
|
||||||
// For server requests Host specifies the host on which the
|
|
||||||
// URL is sought. Per RFC 2616, this is either the value of
|
|
||||||
// the "Host" header or the host name given in the URL itself.
|
|
||||||
// It may be of the form "host:port".
|
|
||||||
//
|
|
||||||
// For client requests Host optionally overrides the Host
|
|
||||||
// header to send. If empty, the Request.Write method uses
|
|
||||||
// the value of URL.Host.
|
|
||||||
Host string
|
|
||||||
|
|
||||||
// Form contains the parsed form data, including both the URL
|
|
||||||
// field's query parameters and the POST or PUT form data.
|
|
||||||
// This field is only available after ParseForm is called.
|
|
||||||
// The HTTP client ignores Form and uses Body instead.
|
|
||||||
Form url.Values
|
|
||||||
|
|
||||||
// PostForm contains the parsed form data from POST or PUT
|
|
||||||
// body parameters.
|
|
||||||
// This field is only available after ParseForm is called.
|
|
||||||
// The HTTP client ignores PostForm and uses Body instead.
|
|
||||||
PostForm url.Values
|
|
||||||
|
|
||||||
// MultipartForm is the parsed multipart form, including file uploads.
|
|
||||||
// This field is only available after ParseMultipartForm is called.
|
|
||||||
// The HTTP client ignores MultipartForm and uses Body instead.
|
|
||||||
MultipartForm *multipart.Form
|
|
||||||
|
|
||||||
// Trailer specifies additional headers that are sent after the request
|
|
||||||
// body.
|
|
||||||
//
|
|
||||||
// For server requests the Trailer map initially contains only the
|
|
||||||
// trailer keys, with nil values. (The client declares which trailers it
|
|
||||||
// will later send.) While the handler is reading from Body, it must
|
|
||||||
// not reference Trailer. After reading from Body returns EOF, Trailer
|
|
||||||
// can be read again and will contain non-nil values, if they were sent
|
|
||||||
// by the client.
|
|
||||||
//
|
|
||||||
// For client requests Trailer must be initialized to a map containing
|
|
||||||
// the trailer keys to later send. The values may be nil or their final
|
|
||||||
// values. The ContentLength must be 0 or -1, to send a chunked request.
|
|
||||||
// After the HTTP request is sent the map values can be updated while
|
|
||||||
// the request body is read. Once the body returns EOF, the caller must
|
|
||||||
// not mutate Trailer.
|
|
||||||
//
|
|
||||||
// Few HTTP clients, servers, or proxies support HTTP trailers.
|
|
||||||
Trailer Header
|
|
||||||
|
|
||||||
// RemoteAddr allows HTTP servers and other software to record
|
|
||||||
// the network address that sent the request, usually for
|
|
||||||
// logging. This field is not filled in by ReadRequest and
|
|
||||||
// has no defined format. The HTTP server in this package
|
|
||||||
// sets RemoteAddr to an "IP:port" address before invoking a
|
|
||||||
// handler.
|
|
||||||
// This field is ignored by the HTTP client.
|
|
||||||
RemoteAddr string
|
|
||||||
|
|
||||||
// RequestURI is the unmodified Request-URI of the
|
|
||||||
// Request-Line (RFC 2616, Section 5.1) as sent by the client
|
|
||||||
// to a server. Usually the URL field should be used instead.
|
|
||||||
// It is an error to set this field in an HTTP client request.
|
|
||||||
RequestURI string
|
|
||||||
|
|
||||||
// TLS allows HTTP servers and other software to record
|
|
||||||
// information about the TLS connection on which the request
|
|
||||||
// was received. This field is not filled in by ReadRequest.
|
|
||||||
// The HTTP server in this package sets the field for
|
|
||||||
// TLS-enabled connections before invoking a handler;
|
|
||||||
// otherwise it leaves the field nil.
|
|
||||||
// This field is ignored by the HTTP client.
|
|
||||||
TLS *tls.ConnectionState
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProtoAtLeast reports whether the HTTP protocol used
|
|
||||||
// in the request is at least major.minor.
|
|
||||||
func (r *Request) ProtoAtLeast(major, minor int) bool {
|
|
||||||
return r.ProtoMajor > major ||
|
|
||||||
r.ProtoMajor == major && r.ProtoMinor >= minor
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserAgent returns the client's User-Agent, if sent in the request.
|
|
||||||
func (r *Request) UserAgent() string {
|
|
||||||
return r.Header.Get("User-Agent")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cookies parses and returns the HTTP cookies sent with the request.
|
|
||||||
func (r *Request) Cookies() []*Cookie {
|
|
||||||
return readCookies(r.Header, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
var ErrNoCookie = errors.New("http: named cookie not present")
|
|
||||||
|
|
||||||
// Cookie returns the named cookie provided in the request or
|
|
||||||
// ErrNoCookie if not found.
|
|
||||||
func (r *Request) Cookie(name string) (*Cookie, error) {
|
|
||||||
for _, c := range readCookies(r.Header, name) {
|
|
||||||
return c, nil
|
|
||||||
}
|
|
||||||
return nil, ErrNoCookie
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddCookie adds a cookie to the request. Per RFC 6265 section 5.4,
|
|
||||||
// AddCookie does not attach more than one Cookie header field. That
|
|
||||||
// means all cookies, if any, are written into the same line,
|
|
||||||
// separated by semicolon.
|
|
||||||
func (r *Request) AddCookie(c *Cookie) {
|
|
||||||
s := fmt.Sprintf("%s=%s", sanitizeCookieName(c.Name), sanitizeCookieValue(c.Value))
|
|
||||||
if c := r.Header.Get("Cookie"); c != "" {
|
|
||||||
r.Header.Set("Cookie", c+"; "+s)
|
|
||||||
} else {
|
|
||||||
r.Header.Set("Cookie", s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Referer returns the referring URL, if sent in the request.
|
|
||||||
//
|
|
||||||
// Referer is misspelled as in the request itself, a mistake from the
|
|
||||||
// earliest days of HTTP. This value can also be fetched from the
|
|
||||||
// Header map as Header["Referer"]; the benefit of making it available
|
|
||||||
// as a method is that the compiler can diagnose programs that use the
|
|
||||||
// alternate (correct English) spelling req.Referrer() but cannot
|
|
||||||
// diagnose programs that use Header["Referrer"].
|
|
||||||
func (r *Request) Referer() string {
|
|
||||||
return r.Header.Get("Referer")
|
|
||||||
}
|
|
||||||
|
|
||||||
// multipartByReader is a sentinel value.
|
|
||||||
// Its presence in Request.MultipartForm indicates that parsing of the request
|
|
||||||
// body has been handed off to a MultipartReader instead of ParseMultipartFrom.
|
|
||||||
var multipartByReader = &multipart.Form{
|
|
||||||
Value: make(map[string][]string),
|
|
||||||
File: make(map[string][]*multipart.FileHeader),
|
|
||||||
}
|
|
||||||
|
|
||||||
// MultipartReader returns a MIME multipart reader if this is a
|
|
||||||
// multipart/form-data POST request, else returns nil and an error.
|
|
||||||
// Use this function instead of ParseMultipartForm to
|
|
||||||
// process the request body as a stream.
|
|
||||||
func (r *Request) MultipartReader() (*multipart.Reader, error) {
|
|
||||||
if r.MultipartForm == multipartByReader {
|
|
||||||
return nil, errors.New("http: MultipartReader called twice")
|
|
||||||
}
|
|
||||||
if r.MultipartForm != nil {
|
|
||||||
return nil, errors.New("http: multipart handled by ParseMultipartForm")
|
|
||||||
}
|
|
||||||
r.MultipartForm = multipartByReader
|
|
||||||
return r.multipartReader()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Request) multipartReader() (*multipart.Reader, error) {
|
|
||||||
v := r.Header.Get("Content-Type")
|
|
||||||
if v == "" {
|
|
||||||
return nil, ErrNotMultipart
|
|
||||||
}
|
|
||||||
d, params, err := mime.ParseMediaType(v)
|
|
||||||
if err != nil || d != "multipart/form-data" {
|
|
||||||
return nil, ErrNotMultipart
|
|
||||||
}
|
|
||||||
boundary, ok := params["boundary"]
|
|
||||||
if !ok {
|
|
||||||
return nil, ErrMissingBoundary
|
|
||||||
}
|
|
||||||
return multipart.NewReader(r.Body, boundary), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return value if nonempty, def otherwise.
|
|
||||||
func valueOrDefault(value, def string) string {
|
|
||||||
if value != "" {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: This is not intended to reflect the actual Go version being used.
|
|
||||||
// It was changed from "Go http package" to "Go 1.1 package http" at the
|
|
||||||
// time of the Go 1.1 release because the former User-Agent had ended up
|
|
||||||
// on a blacklist for some intrusion detection systems.
|
|
||||||
// See https://codereview.appspot.com/7532043.
|
|
||||||
const defaultUserAgent = "Go 1.1 package http"
|
|
||||||
|
|
||||||
// Write writes an HTTP/1.1 request -- header and body -- in wire format.
|
|
||||||
// This method consults the following fields of the request:
|
|
||||||
// Host
|
|
||||||
// URL
|
|
||||||
// Method (defaults to "GET")
|
|
||||||
// Header
|
|
||||||
// ContentLength
|
|
||||||
// TransferEncoding
|
|
||||||
// Body
|
|
||||||
//
|
|
||||||
// If Body is present, Content-Length is <= 0 and TransferEncoding
|
|
||||||
// hasn't been set to "identity", Write adds "Transfer-Encoding:
|
|
||||||
// chunked" to the header. Body is closed after it is sent.
|
|
||||||
func (r *Request) Write(w io.Writer) error {
|
|
||||||
return r.write(w, false, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteProxy is like Write but writes the request in the form
|
|
||||||
// expected by an HTTP proxy. In particular, WriteProxy writes the
|
|
||||||
// initial Request-URI line of the request with an absolute URI, per
|
|
||||||
// section 5.1.2 of RFC 2616, including the scheme and host.
|
|
||||||
// In either case, WriteProxy also writes a Host header, using
|
|
||||||
// either r.Host or r.URL.Host.
|
|
||||||
func (r *Request) WriteProxy(w io.Writer) error {
|
|
||||||
return r.write(w, true, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// extraHeaders may be nil
|
|
||||||
func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header) error {
|
|
||||||
host := req.Host
|
|
||||||
if host == "" {
|
|
||||||
if req.URL == nil {
|
|
||||||
return errors.New("http: Request.Write on Request with no Host or URL set")
|
|
||||||
}
|
|
||||||
host = req.URL.Host
|
|
||||||
}
|
|
||||||
|
|
||||||
ruri := req.URL.RequestURI()
|
|
||||||
if usingProxy && req.URL.Scheme != "" && req.URL.Opaque == "" {
|
|
||||||
ruri = req.URL.Scheme + "://" + host + ruri
|
|
||||||
} else if req.Method == "CONNECT" && req.URL.Path == "" {
|
|
||||||
// CONNECT requests normally give just the host and port, not a full URL.
|
|
||||||
ruri = host
|
|
||||||
}
|
|
||||||
// TODO(bradfitz): escape at least newlines in ruri?
|
|
||||||
|
|
||||||
// Wrap the writer in a bufio Writer if it's not already buffered.
|
|
||||||
// Don't always call NewWriter, as that forces a bytes.Buffer
|
|
||||||
// and other small bufio Writers to have a minimum 4k buffer
|
|
||||||
// size.
|
|
||||||
var bw *bufio.Writer
|
|
||||||
if _, ok := w.(io.ByteWriter); !ok {
|
|
||||||
bw = bufio.NewWriter(w)
|
|
||||||
w = bw
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), ruri)
|
|
||||||
|
|
||||||
// Header lines
|
|
||||||
fmt.Fprintf(w, "Host: %s\r\n", host)
|
|
||||||
|
|
||||||
// Use the defaultUserAgent unless the Header contains one, which
|
|
||||||
// may be blank to not send the header.
|
|
||||||
userAgent := defaultUserAgent
|
|
||||||
if req.Header != nil {
|
|
||||||
if ua := req.Header["User-Agent"]; len(ua) > 0 {
|
|
||||||
userAgent = ua[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if userAgent != "" {
|
|
||||||
fmt.Fprintf(w, "User-Agent: %s\r\n", userAgent)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process Body,ContentLength,Close,Trailer
|
|
||||||
tw, err := newTransferWriter(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = tw.WriteHeader(w)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = req.Header.WriteSubset(w, reqWriteExcludeHeader)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if extraHeaders != nil {
|
|
||||||
err = extraHeaders.Write(w)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
io.WriteString(w, "\r\n")
|
|
||||||
|
|
||||||
// Write body and trailer
|
|
||||||
err = tw.WriteBody(w)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if bw != nil {
|
|
||||||
return bw.Flush()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseHTTPVersion parses a HTTP version string.
|
|
||||||
// "HTTP/1.0" returns (1, 0, true).
|
|
||||||
func ParseHTTPVersion(vers string) (major, minor int, ok bool) {
|
|
||||||
const Big = 1000000 // arbitrary upper bound
|
|
||||||
switch vers {
|
|
||||||
case "HTTP/1.1":
|
|
||||||
return 1, 1, true
|
|
||||||
case "HTTP/1.0":
|
|
||||||
return 1, 0, true
|
|
||||||
}
|
|
||||||
if !strings.HasPrefix(vers, "HTTP/") {
|
|
||||||
return 0, 0, false
|
|
||||||
}
|
|
||||||
dot := strings.Index(vers, ".")
|
|
||||||
if dot < 0 {
|
|
||||||
return 0, 0, false
|
|
||||||
}
|
|
||||||
major, err := strconv.Atoi(vers[5:dot])
|
|
||||||
if err != nil || major < 0 || major > Big {
|
|
||||||
return 0, 0, false
|
|
||||||
}
|
|
||||||
minor, err = strconv.Atoi(vers[dot+1:])
|
|
||||||
if err != nil || minor < 0 || minor > Big {
|
|
||||||
return 0, 0, false
|
|
||||||
}
|
|
||||||
return major, minor, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRequest returns a new Request given a method, URL, and optional body.
|
|
||||||
//
|
|
||||||
// If the provided body is also an io.Closer, the returned
|
|
||||||
// Request.Body is set to body and will be closed by the Client
|
|
||||||
// methods Do, Post, and PostForm, and Transport.RoundTrip.
|
|
||||||
func NewRequest(method, urlStr string, body io.Reader) (*Request, error) {
|
|
||||||
u, err := url.Parse(urlStr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rc, ok := body.(io.ReadCloser)
|
|
||||||
if !ok && body != nil {
|
|
||||||
rc = ioutil.NopCloser(body)
|
|
||||||
}
|
|
||||||
req := &Request{
|
|
||||||
Method: method,
|
|
||||||
URL: u,
|
|
||||||
Proto: "HTTP/1.1",
|
|
||||||
ProtoMajor: 1,
|
|
||||||
ProtoMinor: 1,
|
|
||||||
Header: make(Header),
|
|
||||||
Body: rc,
|
|
||||||
Host: u.Host,
|
|
||||||
}
|
|
||||||
if body != nil {
|
|
||||||
switch v := body.(type) {
|
|
||||||
case *bytes.Buffer:
|
|
||||||
req.ContentLength = int64(v.Len())
|
|
||||||
case *bytes.Reader:
|
|
||||||
req.ContentLength = int64(v.Len())
|
|
||||||
case *strings.Reader:
|
|
||||||
req.ContentLength = int64(v.Len())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBasicAuth sets the request's Authorization header to use HTTP
|
|
||||||
// Basic Authentication with the provided username and password.
|
|
||||||
//
|
|
||||||
// With HTTP Basic Authentication the provided username and password
|
|
||||||
// are not encrypted.
|
|
||||||
func (r *Request) SetBasicAuth(username, password string) {
|
|
||||||
r.Header.Set("Authorization", "Basic "+basicAuth(username, password))
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseRequestLine parses "GET /foo HTTP/1.1" into its three parts.
|
|
||||||
func parseRequestLine(line string) (method, requestURI, proto string, ok bool) {
|
|
||||||
s1 := strings.Index(line, " ")
|
|
||||||
s2 := strings.Index(line[s1+1:], " ")
|
|
||||||
if s1 < 0 || s2 < 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s2 += s1 + 1
|
|
||||||
return line[:s1], line[s1+1 : s2], line[s2+1:], true
|
|
||||||
}
|
|
||||||
|
|
||||||
var textprotoReaderPool sync.Pool
|
|
||||||
|
|
||||||
func newTextprotoReader(br *bufio.Reader) *textproto.Reader {
|
|
||||||
if v := textprotoReaderPool.Get(); v != nil {
|
|
||||||
tr := v.(*textproto.Reader)
|
|
||||||
tr.R = br
|
|
||||||
return tr
|
|
||||||
}
|
|
||||||
return textproto.NewReader(br)
|
|
||||||
}
|
|
||||||
|
|
||||||
func putTextprotoReader(r *textproto.Reader) {
|
|
||||||
r.R = nil
|
|
||||||
textprotoReaderPool.Put(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadRequest reads and parses a request from b.
|
|
||||||
func ReadRequest(b *bufio.Reader) (req *Request, err error) {
|
|
||||||
|
|
||||||
tp := newTextprotoReader(b)
|
|
||||||
req = new(Request)
|
|
||||||
|
|
||||||
// First line: GET /index.html HTTP/1.0
|
|
||||||
var s string
|
|
||||||
if s, err = tp.ReadLine(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
putTextprotoReader(tp)
|
|
||||||
if err == io.EOF {
|
|
||||||
err = io.ErrUnexpectedEOF
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
var ok bool
|
|
||||||
req.Method, req.RequestURI, req.Proto, ok = parseRequestLine(s)
|
|
||||||
if !ok {
|
|
||||||
return nil, &badStringError{"malformed HTTP request", s}
|
|
||||||
}
|
|
||||||
rawurl := req.RequestURI
|
|
||||||
if req.ProtoMajor, req.ProtoMinor, ok = ParseHTTPVersion(req.Proto); !ok {
|
|
||||||
return nil, &badStringError{"malformed HTTP version", req.Proto}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CONNECT requests are used two different ways, and neither uses a full URL:
|
|
||||||
// The standard use is to tunnel HTTPS through an HTTP proxy.
|
|
||||||
// It looks like "CONNECT www.google.com:443 HTTP/1.1", and the parameter is
|
|
||||||
// just the authority section of a URL. This information should go in req.URL.Host.
|
|
||||||
//
|
|
||||||
// The net/rpc package also uses CONNECT, but there the parameter is a path
|
|
||||||
// that starts with a slash. It can be parsed with the regular URL parser,
|
|
||||||
// and the path will end up in req.URL.Path, where it needs to be in order for
|
|
||||||
// RPC to work.
|
|
||||||
justAuthority := req.Method == "CONNECT" && !strings.HasPrefix(rawurl, "/")
|
|
||||||
if justAuthority {
|
|
||||||
rawurl = "http://" + rawurl
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.URL, err = url.ParseRequestURI(rawurl); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if justAuthority {
|
|
||||||
// Strip the bogus "http://" back off.
|
|
||||||
req.URL.Scheme = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subsequent lines: Key: value.
|
|
||||||
mimeHeader, err := tp.ReadMIMEHeader()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
req.Header = Header(mimeHeader)
|
|
||||||
|
|
||||||
// RFC2616: Must treat
|
|
||||||
// GET /index.html HTTP/1.1
|
|
||||||
// Host: www.google.com
|
|
||||||
// and
|
|
||||||
// GET http://www.google.com/index.html HTTP/1.1
|
|
||||||
// Host: doesntmatter
|
|
||||||
// the same. In the second case, any Host line is ignored.
|
|
||||||
req.Host = req.URL.Host
|
|
||||||
if req.Host == "" {
|
|
||||||
req.Host = req.Header.get("Host")
|
|
||||||
}
|
|
||||||
delete(req.Header, "Host")
|
|
||||||
|
|
||||||
fixPragmaCacheControl(req.Header)
|
|
||||||
|
|
||||||
err = readTransfer(req, b)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MaxBytesReader is similar to io.LimitReader but is intended for
|
|
||||||
// limiting the size of incoming request bodies. In contrast to
|
|
||||||
// io.LimitReader, MaxBytesReader's result is a ReadCloser, returns a
|
|
||||||
// non-EOF error for a Read beyond the limit, and Closes the
|
|
||||||
// underlying reader when its Close method is called.
|
|
||||||
//
|
|
||||||
// MaxBytesReader prevents clients from accidentally or maliciously
|
|
||||||
// sending a large request and wasting server resources.
|
|
||||||
func MaxBytesReader(w ResponseWriter, r io.ReadCloser, n int64) io.ReadCloser {
|
|
||||||
return &maxBytesReader{w: w, r: r, n: n}
|
|
||||||
}
|
|
||||||
|
|
||||||
type maxBytesReader struct {
|
|
||||||
w ResponseWriter
|
|
||||||
r io.ReadCloser // underlying reader
|
|
||||||
n int64 // max bytes remaining
|
|
||||||
stopped bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *maxBytesReader) Read(p []byte) (n int, err error) {
|
|
||||||
if l.n <= 0 {
|
|
||||||
if !l.stopped {
|
|
||||||
l.stopped = true
|
|
||||||
if res, ok := l.w.(*response); ok {
|
|
||||||
res.requestTooLarge()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0, errors.New("http: request body too large")
|
|
||||||
}
|
|
||||||
if int64(len(p)) > l.n {
|
|
||||||
p = p[:l.n]
|
|
||||||
}
|
|
||||||
n, err = l.r.Read(p)
|
|
||||||
l.n -= int64(n)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *maxBytesReader) Close() error {
|
|
||||||
return l.r.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyValues(dst, src url.Values) {
|
|
||||||
for k, vs := range src {
|
|
||||||
for _, value := range vs {
|
|
||||||
dst.Add(k, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func parsePostForm(r *Request) (vs url.Values, err error) {
|
|
||||||
if r.Body == nil {
|
|
||||||
err = errors.New("missing form body")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ct := r.Header.Get("Content-Type")
|
|
||||||
// RFC 2616, section 7.2.1 - empty type
|
|
||||||
// SHOULD be treated as application/octet-stream
|
|
||||||
if ct == "" {
|
|
||||||
ct = "application/octet-stream"
|
|
||||||
}
|
|
||||||
ct, _, err = mime.ParseMediaType(ct)
|
|
||||||
switch {
|
|
||||||
case ct == "application/x-www-form-urlencoded":
|
|
||||||
var reader io.Reader = r.Body
|
|
||||||
maxFormSize := int64(1<<63 - 1)
|
|
||||||
if _, ok := r.Body.(*maxBytesReader); !ok {
|
|
||||||
maxFormSize = int64(10 << 20) // 10 MB is a lot of text.
|
|
||||||
reader = io.LimitReader(r.Body, maxFormSize+1)
|
|
||||||
}
|
|
||||||
b, e := ioutil.ReadAll(reader)
|
|
||||||
if e != nil {
|
|
||||||
if err == nil {
|
|
||||||
err = e
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if int64(len(b)) > maxFormSize {
|
|
||||||
err = errors.New("http: POST too large")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
vs, e = url.ParseQuery(string(b))
|
|
||||||
if err == nil {
|
|
||||||
err = e
|
|
||||||
}
|
|
||||||
case ct == "multipart/form-data":
|
|
||||||
// handled by ParseMultipartForm (which is calling us, or should be)
|
|
||||||
// TODO(bradfitz): there are too many possible
|
|
||||||
// orders to call too many functions here.
|
|
||||||
// Clean this up and write more tests.
|
|
||||||
// request_test.go contains the start of this,
|
|
||||||
// in TestParseMultipartFormOrder and others.
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseForm parses the raw query from the URL and updates r.Form.
|
|
||||||
//
|
|
||||||
// For POST or PUT requests, it also parses the request body as a form and
|
|
||||||
// put the results into both r.PostForm and r.Form.
|
|
||||||
// POST and PUT body parameters take precedence over URL query string values
|
|
||||||
// in r.Form.
|
|
||||||
//
|
|
||||||
// If the request Body's size has not already been limited by MaxBytesReader,
|
|
||||||
// the size is capped at 10MB.
|
|
||||||
//
|
|
||||||
// ParseMultipartForm calls ParseForm automatically.
|
|
||||||
// It is idempotent.
|
|
||||||
func (r *Request) ParseForm() error {
|
|
||||||
var err error
|
|
||||||
if r.PostForm == nil {
|
|
||||||
if r.Method == "POST" || r.Method == "PUT" || r.Method == "PATCH" {
|
|
||||||
r.PostForm, err = parsePostForm(r)
|
|
||||||
}
|
|
||||||
if r.PostForm == nil {
|
|
||||||
r.PostForm = make(url.Values)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.Form == nil {
|
|
||||||
if len(r.PostForm) > 0 {
|
|
||||||
r.Form = make(url.Values)
|
|
||||||
copyValues(r.Form, r.PostForm)
|
|
||||||
}
|
|
||||||
var newValues url.Values
|
|
||||||
if r.URL != nil {
|
|
||||||
var e error
|
|
||||||
newValues, e = url.ParseQuery(r.URL.RawQuery)
|
|
||||||
if err == nil {
|
|
||||||
err = e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if newValues == nil {
|
|
||||||
newValues = make(url.Values)
|
|
||||||
}
|
|
||||||
if r.Form == nil {
|
|
||||||
r.Form = newValues
|
|
||||||
} else {
|
|
||||||
copyValues(r.Form, newValues)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseMultipartForm parses a request body as multipart/form-data.
|
|
||||||
// The whole request body is parsed and up to a total of maxMemory bytes of
|
|
||||||
// its file parts are stored in memory, with the remainder stored on
|
|
||||||
// disk in temporary files.
|
|
||||||
// ParseMultipartForm calls ParseForm if necessary.
|
|
||||||
// After one call to ParseMultipartForm, subsequent calls have no effect.
|
|
||||||
func (r *Request) ParseMultipartForm(maxMemory int64) error {
|
|
||||||
if r.MultipartForm == multipartByReader {
|
|
||||||
return errors.New("http: multipart handled by MultipartReader")
|
|
||||||
}
|
|
||||||
if r.Form == nil {
|
|
||||||
err := r.ParseForm()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.MultipartForm != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
mr, err := r.multipartReader()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := mr.ReadForm(maxMemory)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for k, v := range f.Value {
|
|
||||||
r.Form[k] = append(r.Form[k], v...)
|
|
||||||
}
|
|
||||||
r.MultipartForm = f
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FormValue returns the first value for the named component of the query.
|
|
||||||
// POST and PUT body parameters take precedence over URL query string values.
|
|
||||||
// FormValue calls ParseMultipartForm and ParseForm if necessary.
|
|
||||||
// To access multiple values of the same key use ParseForm.
|
|
||||||
func (r *Request) FormValue(key string) string {
|
|
||||||
if r.Form == nil {
|
|
||||||
r.ParseMultipartForm(defaultMaxMemory)
|
|
||||||
}
|
|
||||||
if vs := r.Form[key]; len(vs) > 0 {
|
|
||||||
return vs[0]
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// PostFormValue returns the first value for the named component of the POST
|
|
||||||
// or PUT request body. URL query parameters are ignored.
|
|
||||||
// PostFormValue calls ParseMultipartForm and ParseForm if necessary.
|
|
||||||
func (r *Request) PostFormValue(key string) string {
|
|
||||||
if r.PostForm == nil {
|
|
||||||
r.ParseMultipartForm(defaultMaxMemory)
|
|
||||||
}
|
|
||||||
if vs := r.PostForm[key]; len(vs) > 0 {
|
|
||||||
return vs[0]
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// FormFile returns the first file for the provided form key.
|
|
||||||
// FormFile calls ParseMultipartForm and ParseForm if necessary.
|
|
||||||
func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, error) {
|
|
||||||
if r.MultipartForm == multipartByReader {
|
|
||||||
return nil, nil, errors.New("http: multipart handled by MultipartReader")
|
|
||||||
}
|
|
||||||
if r.MultipartForm == nil {
|
|
||||||
err := r.ParseMultipartForm(defaultMaxMemory)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.MultipartForm != nil && r.MultipartForm.File != nil {
|
|
||||||
if fhs := r.MultipartForm.File[key]; len(fhs) > 0 {
|
|
||||||
f, err := fhs[0].Open()
|
|
||||||
return f, fhs[0], err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, nil, ErrMissingFile
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Request) expectsContinue() bool {
|
|
||||||
return hasToken(r.Header.get("Expect"), "100-continue")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Request) wantsHttp10KeepAlive() bool {
|
|
||||||
if r.ProtoMajor != 1 || r.ProtoMinor != 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return hasToken(r.Header.get("Connection"), "keep-alive")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Request) wantsClose() bool {
|
|
||||||
return hasToken(r.Header.get("Connection"), "close")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Request) closeBody() {
|
|
||||||
if r.Body != nil {
|
|
||||||
r.Body.Close()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,291 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// HTTP Response reading and parsing.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"github.com/Azure/azure-sdk-for-go/core/tls"
|
|
||||||
"io"
|
|
||||||
"net/textproto"
|
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var respExcludeHeader = map[string]bool{
|
|
||||||
"Content-Length": true,
|
|
||||||
"Transfer-Encoding": true,
|
|
||||||
"Trailer": true,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response represents the response from an HTTP request.
|
|
||||||
//
|
|
||||||
type Response struct {
|
|
||||||
Status string // e.g. "200 OK"
|
|
||||||
StatusCode int // e.g. 200
|
|
||||||
Proto string // e.g. "HTTP/1.0"
|
|
||||||
ProtoMajor int // e.g. 1
|
|
||||||
ProtoMinor int // e.g. 0
|
|
||||||
|
|
||||||
// Header maps header keys to values. If the response had multiple
|
|
||||||
// headers with the same key, they may be concatenated, with comma
|
|
||||||
// delimiters. (Section 4.2 of RFC 2616 requires that multiple headers
|
|
||||||
// be semantically equivalent to a comma-delimited sequence.) Values
|
|
||||||
// duplicated by other fields in this struct (e.g., ContentLength) are
|
|
||||||
// omitted from Header.
|
|
||||||
//
|
|
||||||
// Keys in the map are canonicalized (see CanonicalHeaderKey).
|
|
||||||
Header Header
|
|
||||||
|
|
||||||
// Body represents the response body.
|
|
||||||
//
|
|
||||||
// The http Client and Transport guarantee that Body is always
|
|
||||||
// non-nil, even on responses without a body or responses with
|
|
||||||
// a zero-length body. It is the caller's responsibility to
|
|
||||||
// close Body.
|
|
||||||
//
|
|
||||||
// The Body is automatically dechunked if the server replied
|
|
||||||
// with a "chunked" Transfer-Encoding.
|
|
||||||
Body io.ReadCloser
|
|
||||||
|
|
||||||
// ContentLength records the length of the associated content. The
|
|
||||||
// value -1 indicates that the length is unknown. Unless Request.Method
|
|
||||||
// is "HEAD", values >= 0 indicate that the given number of bytes may
|
|
||||||
// be read from Body.
|
|
||||||
ContentLength int64
|
|
||||||
|
|
||||||
// Contains transfer encodings from outer-most to inner-most. Value is
|
|
||||||
// nil, means that "identity" encoding is used.
|
|
||||||
TransferEncoding []string
|
|
||||||
|
|
||||||
// Close records whether the header directed that the connection be
|
|
||||||
// closed after reading Body. The value is advice for clients: neither
|
|
||||||
// ReadResponse nor Response.Write ever closes a connection.
|
|
||||||
Close bool
|
|
||||||
|
|
||||||
// Trailer maps trailer keys to values, in the same
|
|
||||||
// format as the header.
|
|
||||||
Trailer Header
|
|
||||||
|
|
||||||
// The Request that was sent to obtain this Response.
|
|
||||||
// Request's Body is nil (having already been consumed).
|
|
||||||
// This is only populated for Client requests.
|
|
||||||
Request *Request
|
|
||||||
|
|
||||||
// TLS contains information about the TLS connection on which the
|
|
||||||
// response was received. It is nil for unencrypted responses.
|
|
||||||
// The pointer is shared between responses and should not be
|
|
||||||
// modified.
|
|
||||||
TLS *tls.ConnectionState
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cookies parses and returns the cookies set in the Set-Cookie headers.
|
|
||||||
func (r *Response) Cookies() []*Cookie {
|
|
||||||
return readSetCookies(r.Header)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ErrNoLocation = errors.New("http: no Location header in response")
|
|
||||||
|
|
||||||
// Location returns the URL of the response's "Location" header,
|
|
||||||
// if present. Relative redirects are resolved relative to
|
|
||||||
// the Response's Request. ErrNoLocation is returned if no
|
|
||||||
// Location header is present.
|
|
||||||
func (r *Response) Location() (*url.URL, error) {
|
|
||||||
lv := r.Header.Get("Location")
|
|
||||||
if lv == "" {
|
|
||||||
return nil, ErrNoLocation
|
|
||||||
}
|
|
||||||
if r.Request != nil && r.Request.URL != nil {
|
|
||||||
return r.Request.URL.Parse(lv)
|
|
||||||
}
|
|
||||||
return url.Parse(lv)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadResponse reads and returns an HTTP response from r.
|
|
||||||
// The req parameter optionally specifies the Request that corresponds
|
|
||||||
// to this Response. If nil, a GET request is assumed.
|
|
||||||
// Clients must call resp.Body.Close when finished reading resp.Body.
|
|
||||||
// After that call, clients can inspect resp.Trailer to find key/value
|
|
||||||
// pairs included in the response trailer.
|
|
||||||
func ReadResponse(r *bufio.Reader, req *Request) (*Response, error) {
|
|
||||||
tp := textproto.NewReader(r)
|
|
||||||
resp := &Response{
|
|
||||||
Request: req,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the first line of the response.
|
|
||||||
line, err := tp.ReadLine()
|
|
||||||
if err != nil {
|
|
||||||
if err == io.EOF {
|
|
||||||
err = io.ErrUnexpectedEOF
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
f := strings.SplitN(line, " ", 3)
|
|
||||||
if len(f) < 2 {
|
|
||||||
return nil, &badStringError{"malformed HTTP response", line}
|
|
||||||
}
|
|
||||||
reasonPhrase := ""
|
|
||||||
if len(f) > 2 {
|
|
||||||
reasonPhrase = f[2]
|
|
||||||
}
|
|
||||||
resp.Status = f[1] + " " + reasonPhrase
|
|
||||||
resp.StatusCode, err = strconv.Atoi(f[1])
|
|
||||||
if err != nil {
|
|
||||||
return nil, &badStringError{"malformed HTTP status code", f[1]}
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Proto = f[0]
|
|
||||||
var ok bool
|
|
||||||
if resp.ProtoMajor, resp.ProtoMinor, ok = ParseHTTPVersion(resp.Proto); !ok {
|
|
||||||
return nil, &badStringError{"malformed HTTP version", resp.Proto}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the response headers.
|
|
||||||
mimeHeader, err := tp.ReadMIMEHeader()
|
|
||||||
if err != nil {
|
|
||||||
if err == io.EOF {
|
|
||||||
err = io.ErrUnexpectedEOF
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
resp.Header = Header(mimeHeader)
|
|
||||||
|
|
||||||
fixPragmaCacheControl(resp.Header)
|
|
||||||
|
|
||||||
err = readTransfer(resp, r)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RFC2616: Should treat
|
|
||||||
// Pragma: no-cache
|
|
||||||
// like
|
|
||||||
// Cache-Control: no-cache
|
|
||||||
func fixPragmaCacheControl(header Header) {
|
|
||||||
if hp, ok := header["Pragma"]; ok && len(hp) > 0 && hp[0] == "no-cache" {
|
|
||||||
if _, presentcc := header["Cache-Control"]; !presentcc {
|
|
||||||
header["Cache-Control"] = []string{"no-cache"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProtoAtLeast reports whether the HTTP protocol used
|
|
||||||
// in the response is at least major.minor.
|
|
||||||
func (r *Response) ProtoAtLeast(major, minor int) bool {
|
|
||||||
return r.ProtoMajor > major ||
|
|
||||||
r.ProtoMajor == major && r.ProtoMinor >= minor
|
|
||||||
}
|
|
||||||
|
|
||||||
// Writes the response (header, body and trailer) in wire format. This method
|
|
||||||
// consults the following fields of the response:
|
|
||||||
//
|
|
||||||
// StatusCode
|
|
||||||
// ProtoMajor
|
|
||||||
// ProtoMinor
|
|
||||||
// Request.Method
|
|
||||||
// TransferEncoding
|
|
||||||
// Trailer
|
|
||||||
// Body
|
|
||||||
// ContentLength
|
|
||||||
// Header, values for non-canonical keys will have unpredictable behavior
|
|
||||||
//
|
|
||||||
// Body is closed after it is sent.
|
|
||||||
func (r *Response) Write(w io.Writer) error {
|
|
||||||
// Status line
|
|
||||||
text := r.Status
|
|
||||||
if text == "" {
|
|
||||||
var ok bool
|
|
||||||
text, ok = statusText[r.StatusCode]
|
|
||||||
if !ok {
|
|
||||||
text = "status code " + strconv.Itoa(r.StatusCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protoMajor, protoMinor := strconv.Itoa(r.ProtoMajor), strconv.Itoa(r.ProtoMinor)
|
|
||||||
statusCode := strconv.Itoa(r.StatusCode) + " "
|
|
||||||
text = strings.TrimPrefix(text, statusCode)
|
|
||||||
if _, err := io.WriteString(w, "HTTP/"+protoMajor+"."+protoMinor+" "+statusCode+text+"\r\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone it, so we can modify r1 as needed.
|
|
||||||
r1 := new(Response)
|
|
||||||
*r1 = *r
|
|
||||||
if r1.ContentLength == 0 && r1.Body != nil {
|
|
||||||
// Is it actually 0 length? Or just unknown?
|
|
||||||
var buf [1]byte
|
|
||||||
n, err := r1.Body.Read(buf[:])
|
|
||||||
if err != nil && err != io.EOF {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if n == 0 {
|
|
||||||
// Reset it to a known zero reader, in case underlying one
|
|
||||||
// is unhappy being read repeatedly.
|
|
||||||
r1.Body = eofReader
|
|
||||||
} else {
|
|
||||||
r1.ContentLength = -1
|
|
||||||
r1.Body = struct {
|
|
||||||
io.Reader
|
|
||||||
io.Closer
|
|
||||||
}{
|
|
||||||
io.MultiReader(bytes.NewReader(buf[:1]), r.Body),
|
|
||||||
r.Body,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If we're sending a non-chunked HTTP/1.1 response without a
|
|
||||||
// content-length, the only way to do that is the old HTTP/1.0
|
|
||||||
// way, by noting the EOF with a connection close, so we need
|
|
||||||
// to set Close.
|
|
||||||
if r1.ContentLength == -1 && !r1.Close && r1.ProtoAtLeast(1, 1) && !chunked(r1.TransferEncoding) {
|
|
||||||
r1.Close = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process Body,ContentLength,Close,Trailer
|
|
||||||
tw, err := newTransferWriter(r1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = tw.WriteHeader(w)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rest of header
|
|
||||||
err = r.Header.WriteSubset(w, respExcludeHeader)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// contentLengthAlreadySent may have been already sent for
|
|
||||||
// POST/PUT requests, even if zero length. See Issue 8180.
|
|
||||||
contentLengthAlreadySent := tw.shouldSendContentLength()
|
|
||||||
if r1.ContentLength == 0 && !chunked(r1.TransferEncoding) && !contentLengthAlreadySent {
|
|
||||||
if _, err := io.WriteString(w, "Content-Length: 0\r\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// End-of-header
|
|
||||||
if _, err := io.WriteString(w, "\r\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write body and trailer
|
|
||||||
err = tw.WriteBody(w)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success
|
|
||||||
return nil
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,214 +0,0 @@
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
|
||||||
)
|
|
||||||
|
|
||||||
// The algorithm uses at most sniffLen bytes to make its decision.
|
|
||||||
const sniffLen = 512
|
|
||||||
|
|
||||||
// DetectContentType implements the algorithm described
|
|
||||||
// at http://mimesniff.spec.whatwg.org/ to determine the
|
|
||||||
// Content-Type of the given data. It considers at most the
|
|
||||||
// first 512 bytes of data. DetectContentType always returns
|
|
||||||
// a valid MIME type: if it cannot determine a more specific one, it
|
|
||||||
// returns "application/octet-stream".
|
|
||||||
func DetectContentType(data []byte) string {
|
|
||||||
if len(data) > sniffLen {
|
|
||||||
data = data[:sniffLen]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Index of the first non-whitespace byte in data.
|
|
||||||
firstNonWS := 0
|
|
||||||
for ; firstNonWS < len(data) && isWS(data[firstNonWS]); firstNonWS++ {
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, sig := range sniffSignatures {
|
|
||||||
if ct := sig.match(data, firstNonWS); ct != "" {
|
|
||||||
return ct
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "application/octet-stream" // fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
func isWS(b byte) bool {
|
|
||||||
return bytes.IndexByte([]byte("\t\n\x0C\r "), b) != -1
|
|
||||||
}
|
|
||||||
|
|
||||||
type sniffSig interface {
|
|
||||||
// match returns the MIME type of the data, or "" if unknown.
|
|
||||||
match(data []byte, firstNonWS int) string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Data matching the table in section 6.
|
|
||||||
var sniffSignatures = []sniffSig{
|
|
||||||
htmlSig("<!DOCTYPE HTML"),
|
|
||||||
htmlSig("<HTML"),
|
|
||||||
htmlSig("<HEAD"),
|
|
||||||
htmlSig("<SCRIPT"),
|
|
||||||
htmlSig("<IFRAME"),
|
|
||||||
htmlSig("<H1"),
|
|
||||||
htmlSig("<DIV"),
|
|
||||||
htmlSig("<FONT"),
|
|
||||||
htmlSig("<TABLE"),
|
|
||||||
htmlSig("<A"),
|
|
||||||
htmlSig("<STYLE"),
|
|
||||||
htmlSig("<TITLE"),
|
|
||||||
htmlSig("<B"),
|
|
||||||
htmlSig("<BODY"),
|
|
||||||
htmlSig("<BR"),
|
|
||||||
htmlSig("<P"),
|
|
||||||
htmlSig("<!--"),
|
|
||||||
|
|
||||||
&maskedSig{mask: []byte("\xFF\xFF\xFF\xFF\xFF"), pat: []byte("<?xml"), skipWS: true, ct: "text/xml; charset=utf-8"},
|
|
||||||
|
|
||||||
&exactSig{[]byte("%PDF-"), "application/pdf"},
|
|
||||||
&exactSig{[]byte("%!PS-Adobe-"), "application/postscript"},
|
|
||||||
|
|
||||||
// UTF BOMs.
|
|
||||||
&maskedSig{mask: []byte("\xFF\xFF\x00\x00"), pat: []byte("\xFE\xFF\x00\x00"), ct: "text/plain; charset=utf-16be"},
|
|
||||||
&maskedSig{mask: []byte("\xFF\xFF\x00\x00"), pat: []byte("\xFF\xFE\x00\x00"), ct: "text/plain; charset=utf-16le"},
|
|
||||||
&maskedSig{mask: []byte("\xFF\xFF\xFF\x00"), pat: []byte("\xEF\xBB\xBF\x00"), ct: "text/plain; charset=utf-8"},
|
|
||||||
|
|
||||||
&exactSig{[]byte("GIF87a"), "image/gif"},
|
|
||||||
&exactSig{[]byte("GIF89a"), "image/gif"},
|
|
||||||
&exactSig{[]byte("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"), "image/png"},
|
|
||||||
&exactSig{[]byte("\xFF\xD8\xFF"), "image/jpeg"},
|
|
||||||
&exactSig{[]byte("BM"), "image/bmp"},
|
|
||||||
&maskedSig{
|
|
||||||
mask: []byte("\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF"),
|
|
||||||
pat: []byte("RIFF\x00\x00\x00\x00WEBPVP"),
|
|
||||||
ct: "image/webp",
|
|
||||||
},
|
|
||||||
&exactSig{[]byte("\x00\x00\x01\x00"), "image/vnd.microsoft.icon"},
|
|
||||||
&exactSig{[]byte("\x4F\x67\x67\x53\x00"), "application/ogg"},
|
|
||||||
&maskedSig{
|
|
||||||
mask: []byte("\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF"),
|
|
||||||
pat: []byte("RIFF\x00\x00\x00\x00WAVE"),
|
|
||||||
ct: "audio/wave",
|
|
||||||
},
|
|
||||||
&exactSig{[]byte("\x1A\x45\xDF\xA3"), "video/webm"},
|
|
||||||
&exactSig{[]byte("\x52\x61\x72\x20\x1A\x07\x00"), "application/x-rar-compressed"},
|
|
||||||
&exactSig{[]byte("\x50\x4B\x03\x04"), "application/zip"},
|
|
||||||
&exactSig{[]byte("\x1F\x8B\x08"), "application/x-gzip"},
|
|
||||||
|
|
||||||
// TODO(dsymonds): Re-enable this when the spec is sorted w.r.t. MP4.
|
|
||||||
//mp4Sig(0),
|
|
||||||
|
|
||||||
textSig(0), // should be last
|
|
||||||
}
|
|
||||||
|
|
||||||
type exactSig struct {
|
|
||||||
sig []byte
|
|
||||||
ct string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *exactSig) match(data []byte, firstNonWS int) string {
|
|
||||||
if bytes.HasPrefix(data, e.sig) {
|
|
||||||
return e.ct
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type maskedSig struct {
|
|
||||||
mask, pat []byte
|
|
||||||
skipWS bool
|
|
||||||
ct string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *maskedSig) match(data []byte, firstNonWS int) string {
|
|
||||||
if m.skipWS {
|
|
||||||
data = data[firstNonWS:]
|
|
||||||
}
|
|
||||||
if len(data) < len(m.mask) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
for i, mask := range m.mask {
|
|
||||||
db := data[i] & mask
|
|
||||||
if db != m.pat[i] {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m.ct
|
|
||||||
}
|
|
||||||
|
|
||||||
type htmlSig []byte
|
|
||||||
|
|
||||||
func (h htmlSig) match(data []byte, firstNonWS int) string {
|
|
||||||
data = data[firstNonWS:]
|
|
||||||
if len(data) < len(h)+1 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
for i, b := range h {
|
|
||||||
db := data[i]
|
|
||||||
if 'A' <= b && b <= 'Z' {
|
|
||||||
db &= 0xDF
|
|
||||||
}
|
|
||||||
if b != db {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Next byte must be space or right angle bracket.
|
|
||||||
if db := data[len(h)]; db != ' ' && db != '>' {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return "text/html; charset=utf-8"
|
|
||||||
}
|
|
||||||
|
|
||||||
type mp4Sig int
|
|
||||||
|
|
||||||
func (mp4Sig) match(data []byte, firstNonWS int) string {
|
|
||||||
// c.f. section 6.1.
|
|
||||||
if len(data) < 8 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
boxSize := int(binary.BigEndian.Uint32(data[:4]))
|
|
||||||
if boxSize%4 != 0 || len(data) < boxSize {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if !bytes.Equal(data[4:8], []byte("ftyp")) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
for st := 8; st < boxSize; st += 4 {
|
|
||||||
if st == 12 {
|
|
||||||
// minor version number
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
seg := string(data[st : st+3])
|
|
||||||
switch seg {
|
|
||||||
case "mp4", "iso", "M4V", "M4P", "M4B":
|
|
||||||
return "video/mp4"
|
|
||||||
/* The remainder are not in the spec.
|
|
||||||
case "M4A":
|
|
||||||
return "audio/mp4"
|
|
||||||
case "3gp":
|
|
||||||
return "video/3gpp"
|
|
||||||
case "jp2":
|
|
||||||
return "image/jp2" // JPEG 2000
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type textSig int
|
|
||||||
|
|
||||||
func (textSig) match(data []byte, firstNonWS int) string {
|
|
||||||
// c.f. section 5, step 4.
|
|
||||||
for _, b := range data[firstNonWS:] {
|
|
||||||
switch {
|
|
||||||
case 0x00 <= b && b <= 0x08,
|
|
||||||
b == 0x0B,
|
|
||||||
0x0E <= b && b <= 0x1A,
|
|
||||||
0x1C <= b && b <= 0x1F:
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "text/plain; charset=utf-8"
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
// HTTP status codes, defined in RFC 2616.
|
|
||||||
const (
|
|
||||||
StatusContinue = 100
|
|
||||||
StatusSwitchingProtocols = 101
|
|
||||||
|
|
||||||
StatusOK = 200
|
|
||||||
StatusCreated = 201
|
|
||||||
StatusAccepted = 202
|
|
||||||
StatusNonAuthoritativeInfo = 203
|
|
||||||
StatusNoContent = 204
|
|
||||||
StatusResetContent = 205
|
|
||||||
StatusPartialContent = 206
|
|
||||||
|
|
||||||
StatusMultipleChoices = 300
|
|
||||||
StatusMovedPermanently = 301
|
|
||||||
StatusFound = 302
|
|
||||||
StatusSeeOther = 303
|
|
||||||
StatusNotModified = 304
|
|
||||||
StatusUseProxy = 305
|
|
||||||
StatusTemporaryRedirect = 307
|
|
||||||
|
|
||||||
StatusBadRequest = 400
|
|
||||||
StatusUnauthorized = 401
|
|
||||||
StatusPaymentRequired = 402
|
|
||||||
StatusForbidden = 403
|
|
||||||
StatusNotFound = 404
|
|
||||||
StatusMethodNotAllowed = 405
|
|
||||||
StatusNotAcceptable = 406
|
|
||||||
StatusProxyAuthRequired = 407
|
|
||||||
StatusRequestTimeout = 408
|
|
||||||
StatusConflict = 409
|
|
||||||
StatusGone = 410
|
|
||||||
StatusLengthRequired = 411
|
|
||||||
StatusPreconditionFailed = 412
|
|
||||||
StatusRequestEntityTooLarge = 413
|
|
||||||
StatusRequestURITooLong = 414
|
|
||||||
StatusUnsupportedMediaType = 415
|
|
||||||
StatusRequestedRangeNotSatisfiable = 416
|
|
||||||
StatusExpectationFailed = 417
|
|
||||||
StatusTeapot = 418
|
|
||||||
|
|
||||||
StatusInternalServerError = 500
|
|
||||||
StatusNotImplemented = 501
|
|
||||||
StatusBadGateway = 502
|
|
||||||
StatusServiceUnavailable = 503
|
|
||||||
StatusGatewayTimeout = 504
|
|
||||||
StatusHTTPVersionNotSupported = 505
|
|
||||||
|
|
||||||
// New HTTP status codes from RFC 6585. Not exported yet in Go 1.1.
|
|
||||||
// See discussion at https://codereview.appspot.com/7678043/
|
|
||||||
statusPreconditionRequired = 428
|
|
||||||
statusTooManyRequests = 429
|
|
||||||
statusRequestHeaderFieldsTooLarge = 431
|
|
||||||
statusNetworkAuthenticationRequired = 511
|
|
||||||
)
|
|
||||||
|
|
||||||
var statusText = map[int]string{
|
|
||||||
StatusContinue: "Continue",
|
|
||||||
StatusSwitchingProtocols: "Switching Protocols",
|
|
||||||
|
|
||||||
StatusOK: "OK",
|
|
||||||
StatusCreated: "Created",
|
|
||||||
StatusAccepted: "Accepted",
|
|
||||||
StatusNonAuthoritativeInfo: "Non-Authoritative Information",
|
|
||||||
StatusNoContent: "No Content",
|
|
||||||
StatusResetContent: "Reset Content",
|
|
||||||
StatusPartialContent: "Partial Content",
|
|
||||||
|
|
||||||
StatusMultipleChoices: "Multiple Choices",
|
|
||||||
StatusMovedPermanently: "Moved Permanently",
|
|
||||||
StatusFound: "Found",
|
|
||||||
StatusSeeOther: "See Other",
|
|
||||||
StatusNotModified: "Not Modified",
|
|
||||||
StatusUseProxy: "Use Proxy",
|
|
||||||
StatusTemporaryRedirect: "Temporary Redirect",
|
|
||||||
|
|
||||||
StatusBadRequest: "Bad Request",
|
|
||||||
StatusUnauthorized: "Unauthorized",
|
|
||||||
StatusPaymentRequired: "Payment Required",
|
|
||||||
StatusForbidden: "Forbidden",
|
|
||||||
StatusNotFound: "Not Found",
|
|
||||||
StatusMethodNotAllowed: "Method Not Allowed",
|
|
||||||
StatusNotAcceptable: "Not Acceptable",
|
|
||||||
StatusProxyAuthRequired: "Proxy Authentication Required",
|
|
||||||
StatusRequestTimeout: "Request Timeout",
|
|
||||||
StatusConflict: "Conflict",
|
|
||||||
StatusGone: "Gone",
|
|
||||||
StatusLengthRequired: "Length Required",
|
|
||||||
StatusPreconditionFailed: "Precondition Failed",
|
|
||||||
StatusRequestEntityTooLarge: "Request Entity Too Large",
|
|
||||||
StatusRequestURITooLong: "Request URI Too Long",
|
|
||||||
StatusUnsupportedMediaType: "Unsupported Media Type",
|
|
||||||
StatusRequestedRangeNotSatisfiable: "Requested Range Not Satisfiable",
|
|
||||||
StatusExpectationFailed: "Expectation Failed",
|
|
||||||
StatusTeapot: "I'm a teapot",
|
|
||||||
|
|
||||||
StatusInternalServerError: "Internal Server Error",
|
|
||||||
StatusNotImplemented: "Not Implemented",
|
|
||||||
StatusBadGateway: "Bad Gateway",
|
|
||||||
StatusServiceUnavailable: "Service Unavailable",
|
|
||||||
StatusGatewayTimeout: "Gateway Timeout",
|
|
||||||
StatusHTTPVersionNotSupported: "HTTP Version Not Supported",
|
|
||||||
|
|
||||||
statusPreconditionRequired: "Precondition Required",
|
|
||||||
statusTooManyRequests: "Too Many Requests",
|
|
||||||
statusRequestHeaderFieldsTooLarge: "Request Header Fields Too Large",
|
|
||||||
statusNetworkAuthenticationRequired: "Network Authentication Required",
|
|
||||||
}
|
|
||||||
|
|
||||||
// StatusText returns a text for the HTTP status code. It returns the empty
|
|
||||||
// string if the code is unknown.
|
|
||||||
func StatusText(code int) string {
|
|
||||||
return statusText[code]
|
|
||||||
}
|
|
|
@ -1,730 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/textproto"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
type errorReader struct {
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *errorReader) Read(p []byte) (n int, err error) {
|
|
||||||
return 0, r.err
|
|
||||||
}
|
|
||||||
|
|
||||||
// transferWriter inspects the fields of a user-supplied Request or Response,
|
|
||||||
// sanitizes them without changing the user object and provides methods for
|
|
||||||
// writing the respective header, body and trailer in wire format.
|
|
||||||
type transferWriter struct {
|
|
||||||
Method string
|
|
||||||
Body io.Reader
|
|
||||||
BodyCloser io.Closer
|
|
||||||
ResponseToHEAD bool
|
|
||||||
ContentLength int64 // -1 means unknown, 0 means exactly none
|
|
||||||
Close bool
|
|
||||||
TransferEncoding []string
|
|
||||||
Trailer Header
|
|
||||||
}
|
|
||||||
|
|
||||||
func newTransferWriter(r interface{}) (t *transferWriter, err error) {
|
|
||||||
t = &transferWriter{}
|
|
||||||
|
|
||||||
// Extract relevant fields
|
|
||||||
atLeastHTTP11 := false
|
|
||||||
switch rr := r.(type) {
|
|
||||||
case *Request:
|
|
||||||
if rr.ContentLength != 0 && rr.Body == nil {
|
|
||||||
return nil, fmt.Errorf("http: Request.ContentLength=%d with nil Body", rr.ContentLength)
|
|
||||||
}
|
|
||||||
t.Method = rr.Method
|
|
||||||
t.Body = rr.Body
|
|
||||||
t.BodyCloser = rr.Body
|
|
||||||
t.ContentLength = rr.ContentLength
|
|
||||||
t.Close = rr.Close
|
|
||||||
t.TransferEncoding = rr.TransferEncoding
|
|
||||||
t.Trailer = rr.Trailer
|
|
||||||
atLeastHTTP11 = rr.ProtoAtLeast(1, 1)
|
|
||||||
if t.Body != nil && len(t.TransferEncoding) == 0 && atLeastHTTP11 {
|
|
||||||
if t.ContentLength == 0 {
|
|
||||||
// Test to see if it's actually zero or just unset.
|
|
||||||
var buf [1]byte
|
|
||||||
n, rerr := io.ReadFull(t.Body, buf[:])
|
|
||||||
if rerr != nil && rerr != io.EOF {
|
|
||||||
t.ContentLength = -1
|
|
||||||
t.Body = &errorReader{rerr}
|
|
||||||
} else if n == 1 {
|
|
||||||
// Oh, guess there is data in this Body Reader after all.
|
|
||||||
// The ContentLength field just wasn't set.
|
|
||||||
// Stich the Body back together again, re-attaching our
|
|
||||||
// consumed byte.
|
|
||||||
t.ContentLength = -1
|
|
||||||
t.Body = io.MultiReader(bytes.NewReader(buf[:]), t.Body)
|
|
||||||
} else {
|
|
||||||
// Body is actually empty.
|
|
||||||
t.Body = nil
|
|
||||||
t.BodyCloser = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if t.ContentLength < 0 {
|
|
||||||
t.TransferEncoding = []string{"chunked"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case *Response:
|
|
||||||
if rr.Request != nil {
|
|
||||||
t.Method = rr.Request.Method
|
|
||||||
}
|
|
||||||
t.Body = rr.Body
|
|
||||||
t.BodyCloser = rr.Body
|
|
||||||
t.ContentLength = rr.ContentLength
|
|
||||||
t.Close = rr.Close
|
|
||||||
t.TransferEncoding = rr.TransferEncoding
|
|
||||||
t.Trailer = rr.Trailer
|
|
||||||
atLeastHTTP11 = rr.ProtoAtLeast(1, 1)
|
|
||||||
t.ResponseToHEAD = noBodyExpected(t.Method)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanitize Body,ContentLength,TransferEncoding
|
|
||||||
if t.ResponseToHEAD {
|
|
||||||
t.Body = nil
|
|
||||||
if chunked(t.TransferEncoding) {
|
|
||||||
t.ContentLength = -1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !atLeastHTTP11 || t.Body == nil {
|
|
||||||
t.TransferEncoding = nil
|
|
||||||
}
|
|
||||||
if chunked(t.TransferEncoding) {
|
|
||||||
t.ContentLength = -1
|
|
||||||
} else if t.Body == nil { // no chunking, no body
|
|
||||||
t.ContentLength = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanitize Trailer
|
|
||||||
if !chunked(t.TransferEncoding) {
|
|
||||||
t.Trailer = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return t, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func noBodyExpected(requestMethod string) bool {
|
|
||||||
return requestMethod == "HEAD"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *transferWriter) shouldSendContentLength() bool {
|
|
||||||
if chunked(t.TransferEncoding) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if t.ContentLength > 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// Many servers expect a Content-Length for these methods
|
|
||||||
if t.Method == "POST" || t.Method == "PUT" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if t.ContentLength == 0 && isIdentity(t.TransferEncoding) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *transferWriter) WriteHeader(w io.Writer) error {
|
|
||||||
if t.Close {
|
|
||||||
if _, err := io.WriteString(w, "Connection: close\r\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write Content-Length and/or Transfer-Encoding whose values are a
|
|
||||||
// function of the sanitized field triple (Body, ContentLength,
|
|
||||||
// TransferEncoding)
|
|
||||||
if t.shouldSendContentLength() {
|
|
||||||
if _, err := io.WriteString(w, "Content-Length: "); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.WriteString(w, strconv.FormatInt(t.ContentLength, 10)+"\r\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if chunked(t.TransferEncoding) {
|
|
||||||
if _, err := io.WriteString(w, "Transfer-Encoding: chunked\r\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write Trailer header
|
|
||||||
if t.Trailer != nil {
|
|
||||||
keys := make([]string, 0, len(t.Trailer))
|
|
||||||
for k := range t.Trailer {
|
|
||||||
k = CanonicalHeaderKey(k)
|
|
||||||
switch k {
|
|
||||||
case "Transfer-Encoding", "Trailer", "Content-Length":
|
|
||||||
return &badStringError{"invalid Trailer key", k}
|
|
||||||
}
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
if len(keys) > 0 {
|
|
||||||
sort.Strings(keys)
|
|
||||||
// TODO: could do better allocation-wise here, but trailers are rare,
|
|
||||||
// so being lazy for now.
|
|
||||||
if _, err := io.WriteString(w, "Trailer: "+strings.Join(keys, ",")+"\r\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *transferWriter) WriteBody(w io.Writer) error {
|
|
||||||
var err error
|
|
||||||
var ncopy int64
|
|
||||||
|
|
||||||
// Write body
|
|
||||||
if t.Body != nil {
|
|
||||||
if chunked(t.TransferEncoding) {
|
|
||||||
cw := newChunkedWriter(w)
|
|
||||||
_, err = io.Copy(cw, t.Body)
|
|
||||||
if err == nil {
|
|
||||||
err = cw.Close()
|
|
||||||
}
|
|
||||||
} else if t.ContentLength == -1 {
|
|
||||||
ncopy, err = io.Copy(w, t.Body)
|
|
||||||
} else {
|
|
||||||
ncopy, err = io.Copy(w, io.LimitReader(t.Body, t.ContentLength))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var nextra int64
|
|
||||||
nextra, err = io.Copy(ioutil.Discard, t.Body)
|
|
||||||
ncopy += nextra
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err = t.BodyCloser.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !t.ResponseToHEAD && t.ContentLength != -1 && t.ContentLength != ncopy {
|
|
||||||
return fmt.Errorf("http: Request.ContentLength=%d with Body length %d",
|
|
||||||
t.ContentLength, ncopy)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(petar): Place trailer writer code here.
|
|
||||||
if chunked(t.TransferEncoding) {
|
|
||||||
// Write Trailer header
|
|
||||||
if t.Trailer != nil {
|
|
||||||
if err := t.Trailer.Write(w); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Last chunk, empty trailer
|
|
||||||
_, err = io.WriteString(w, "\r\n")
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
type transferReader struct {
|
|
||||||
// Input
|
|
||||||
Header Header
|
|
||||||
StatusCode int
|
|
||||||
RequestMethod string
|
|
||||||
ProtoMajor int
|
|
||||||
ProtoMinor int
|
|
||||||
// Output
|
|
||||||
Body io.ReadCloser
|
|
||||||
ContentLength int64
|
|
||||||
TransferEncoding []string
|
|
||||||
Close bool
|
|
||||||
Trailer Header
|
|
||||||
}
|
|
||||||
|
|
||||||
// bodyAllowedForStatus reports whether a given response status code
|
|
||||||
// permits a body. See RFC2616, section 4.4.
|
|
||||||
func bodyAllowedForStatus(status int) bool {
|
|
||||||
switch {
|
|
||||||
case status >= 100 && status <= 199:
|
|
||||||
return false
|
|
||||||
case status == 204:
|
|
||||||
return false
|
|
||||||
case status == 304:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
suppressedHeaders304 = []string{"Content-Type", "Content-Length", "Transfer-Encoding"}
|
|
||||||
suppressedHeadersNoBody = []string{"Content-Length", "Transfer-Encoding"}
|
|
||||||
)
|
|
||||||
|
|
||||||
func suppressedHeaders(status int) []string {
|
|
||||||
switch {
|
|
||||||
case status == 304:
|
|
||||||
// RFC 2616 section 10.3.5: "the response MUST NOT include other entity-headers"
|
|
||||||
return suppressedHeaders304
|
|
||||||
case !bodyAllowedForStatus(status):
|
|
||||||
return suppressedHeadersNoBody
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// msg is *Request or *Response.
|
|
||||||
func readTransfer(msg interface{}, r *bufio.Reader) (err error) {
|
|
||||||
t := &transferReader{RequestMethod: "GET"}
|
|
||||||
|
|
||||||
// Unify input
|
|
||||||
isResponse := false
|
|
||||||
switch rr := msg.(type) {
|
|
||||||
case *Response:
|
|
||||||
t.Header = rr.Header
|
|
||||||
t.StatusCode = rr.StatusCode
|
|
||||||
t.ProtoMajor = rr.ProtoMajor
|
|
||||||
t.ProtoMinor = rr.ProtoMinor
|
|
||||||
t.Close = shouldClose(t.ProtoMajor, t.ProtoMinor, t.Header)
|
|
||||||
isResponse = true
|
|
||||||
if rr.Request != nil {
|
|
||||||
t.RequestMethod = rr.Request.Method
|
|
||||||
}
|
|
||||||
case *Request:
|
|
||||||
t.Header = rr.Header
|
|
||||||
t.ProtoMajor = rr.ProtoMajor
|
|
||||||
t.ProtoMinor = rr.ProtoMinor
|
|
||||||
// Transfer semantics for Requests are exactly like those for
|
|
||||||
// Responses with status code 200, responding to a GET method
|
|
||||||
t.StatusCode = 200
|
|
||||||
default:
|
|
||||||
panic("unexpected type")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default to HTTP/1.1
|
|
||||||
if t.ProtoMajor == 0 && t.ProtoMinor == 0 {
|
|
||||||
t.ProtoMajor, t.ProtoMinor = 1, 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transfer encoding, content length
|
|
||||||
t.TransferEncoding, err = fixTransferEncoding(t.RequestMethod, t.Header)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
realLength, err := fixLength(isResponse, t.StatusCode, t.RequestMethod, t.Header, t.TransferEncoding)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if isResponse && t.RequestMethod == "HEAD" {
|
|
||||||
if n, err := parseContentLength(t.Header.get("Content-Length")); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
t.ContentLength = n
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.ContentLength = realLength
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trailer
|
|
||||||
t.Trailer, err = fixTrailer(t.Header, t.TransferEncoding)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is no Content-Length or chunked Transfer-Encoding on a *Response
|
|
||||||
// and the status is not 1xx, 204 or 304, then the body is unbounded.
|
|
||||||
// See RFC2616, section 4.4.
|
|
||||||
switch msg.(type) {
|
|
||||||
case *Response:
|
|
||||||
if realLength == -1 &&
|
|
||||||
!chunked(t.TransferEncoding) &&
|
|
||||||
bodyAllowedForStatus(t.StatusCode) {
|
|
||||||
// Unbounded body.
|
|
||||||
t.Close = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare body reader. ContentLength < 0 means chunked encoding
|
|
||||||
// or close connection when finished, since multipart is not supported yet
|
|
||||||
switch {
|
|
||||||
case chunked(t.TransferEncoding):
|
|
||||||
if noBodyExpected(t.RequestMethod) {
|
|
||||||
t.Body = eofReader
|
|
||||||
} else {
|
|
||||||
t.Body = &body{src: newChunkedReader(r), hdr: msg, r: r, closing: t.Close}
|
|
||||||
}
|
|
||||||
case realLength == 0:
|
|
||||||
t.Body = eofReader
|
|
||||||
case realLength > 0:
|
|
||||||
t.Body = &body{src: io.LimitReader(r, realLength), closing: t.Close}
|
|
||||||
default:
|
|
||||||
// realLength < 0, i.e. "Content-Length" not mentioned in header
|
|
||||||
if t.Close {
|
|
||||||
// Close semantics (i.e. HTTP/1.0)
|
|
||||||
t.Body = &body{src: r, closing: t.Close}
|
|
||||||
} else {
|
|
||||||
// Persistent connection (i.e. HTTP/1.1)
|
|
||||||
t.Body = eofReader
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unify output
|
|
||||||
switch rr := msg.(type) {
|
|
||||||
case *Request:
|
|
||||||
rr.Body = t.Body
|
|
||||||
rr.ContentLength = t.ContentLength
|
|
||||||
rr.TransferEncoding = t.TransferEncoding
|
|
||||||
rr.Close = t.Close
|
|
||||||
rr.Trailer = t.Trailer
|
|
||||||
case *Response:
|
|
||||||
rr.Body = t.Body
|
|
||||||
rr.ContentLength = t.ContentLength
|
|
||||||
rr.TransferEncoding = t.TransferEncoding
|
|
||||||
rr.Close = t.Close
|
|
||||||
rr.Trailer = t.Trailer
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks whether chunked is part of the encodings stack
|
|
||||||
func chunked(te []string) bool { return len(te) > 0 && te[0] == "chunked" }
|
|
||||||
|
|
||||||
// Checks whether the encoding is explicitly "identity".
|
|
||||||
func isIdentity(te []string) bool { return len(te) == 1 && te[0] == "identity" }
|
|
||||||
|
|
||||||
// Sanitize transfer encoding
|
|
||||||
func fixTransferEncoding(requestMethod string, header Header) ([]string, error) {
|
|
||||||
raw, present := header["Transfer-Encoding"]
|
|
||||||
if !present {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(header, "Transfer-Encoding")
|
|
||||||
|
|
||||||
encodings := strings.Split(raw[0], ",")
|
|
||||||
te := make([]string, 0, len(encodings))
|
|
||||||
// TODO: Even though we only support "identity" and "chunked"
|
|
||||||
// encodings, the loop below is designed with foresight. One
|
|
||||||
// invariant that must be maintained is that, if present,
|
|
||||||
// chunked encoding must always come first.
|
|
||||||
for _, encoding := range encodings {
|
|
||||||
encoding = strings.ToLower(strings.TrimSpace(encoding))
|
|
||||||
// "identity" encoding is not recorded
|
|
||||||
if encoding == "identity" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if encoding != "chunked" {
|
|
||||||
return nil, &badStringError{"unsupported transfer encoding", encoding}
|
|
||||||
}
|
|
||||||
te = te[0 : len(te)+1]
|
|
||||||
te[len(te)-1] = encoding
|
|
||||||
}
|
|
||||||
if len(te) > 1 {
|
|
||||||
return nil, &badStringError{"too many transfer encodings", strings.Join(te, ",")}
|
|
||||||
}
|
|
||||||
if len(te) > 0 {
|
|
||||||
// Chunked encoding trumps Content-Length. See RFC 2616
|
|
||||||
// Section 4.4. Currently len(te) > 0 implies chunked
|
|
||||||
// encoding.
|
|
||||||
delete(header, "Content-Length")
|
|
||||||
return te, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine the expected body length, using RFC 2616 Section 4.4. This
|
|
||||||
// function is not a method, because ultimately it should be shared by
|
|
||||||
// ReadResponse and ReadRequest.
|
|
||||||
func fixLength(isResponse bool, status int, requestMethod string, header Header, te []string) (int64, error) {
|
|
||||||
|
|
||||||
// Logic based on response type or status
|
|
||||||
if noBodyExpected(requestMethod) {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
if status/100 == 1 {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
switch status {
|
|
||||||
case 204, 304:
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logic based on Transfer-Encoding
|
|
||||||
if chunked(te) {
|
|
||||||
return -1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logic based on Content-Length
|
|
||||||
cl := strings.TrimSpace(header.get("Content-Length"))
|
|
||||||
if cl != "" {
|
|
||||||
n, err := parseContentLength(cl)
|
|
||||||
if err != nil {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
return n, nil
|
|
||||||
} else {
|
|
||||||
header.Del("Content-Length")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isResponse && requestMethod == "GET" {
|
|
||||||
// RFC 2616 doesn't explicitly permit nor forbid an
|
|
||||||
// entity-body on a GET request so we permit one if
|
|
||||||
// declared, but we default to 0 here (not -1 below)
|
|
||||||
// if there's no mention of a body.
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Body-EOF logic based on other methods (like closing, or chunked coding)
|
|
||||||
return -1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine whether to hang up after sending a request and body, or
|
|
||||||
// receiving a response and body
|
|
||||||
// 'header' is the request headers
|
|
||||||
func shouldClose(major, minor int, header Header) bool {
|
|
||||||
if major < 1 {
|
|
||||||
return true
|
|
||||||
} else if major == 1 && minor == 0 {
|
|
||||||
if !strings.Contains(strings.ToLower(header.get("Connection")), "keep-alive") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
// TODO: Should split on commas, toss surrounding white space,
|
|
||||||
// and check each field.
|
|
||||||
if strings.ToLower(header.get("Connection")) == "close" {
|
|
||||||
header.Del("Connection")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the trailer header
|
|
||||||
func fixTrailer(header Header, te []string) (Header, error) {
|
|
||||||
raw := header.get("Trailer")
|
|
||||||
if raw == "" {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
header.Del("Trailer")
|
|
||||||
trailer := make(Header)
|
|
||||||
keys := strings.Split(raw, ",")
|
|
||||||
for _, key := range keys {
|
|
||||||
key = CanonicalHeaderKey(strings.TrimSpace(key))
|
|
||||||
switch key {
|
|
||||||
case "Transfer-Encoding", "Trailer", "Content-Length":
|
|
||||||
return nil, &badStringError{"bad trailer key", key}
|
|
||||||
}
|
|
||||||
trailer[key] = nil
|
|
||||||
}
|
|
||||||
if len(trailer) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
if !chunked(te) {
|
|
||||||
// Trailer and no chunking
|
|
||||||
return nil, ErrUnexpectedTrailer
|
|
||||||
}
|
|
||||||
return trailer, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// body turns a Reader into a ReadCloser.
|
|
||||||
// Close ensures that the body has been fully read
|
|
||||||
// and then reads the trailer if necessary.
|
|
||||||
type body struct {
|
|
||||||
src io.Reader
|
|
||||||
hdr interface{} // non-nil (Response or Request) value means read trailer
|
|
||||||
r *bufio.Reader // underlying wire-format reader for the trailer
|
|
||||||
closing bool // is the connection to be closed after reading body?
|
|
||||||
|
|
||||||
mu sync.Mutex // guards closed, and calls to Read and Close
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrBodyReadAfterClose is returned when reading a Request or Response
|
|
||||||
// Body after the body has been closed. This typically happens when the body is
|
|
||||||
// read after an HTTP Handler calls WriteHeader or Write on its
|
|
||||||
// ResponseWriter.
|
|
||||||
var ErrBodyReadAfterClose = errors.New("http: invalid Read on closed Body")
|
|
||||||
|
|
||||||
func (b *body) Read(p []byte) (n int, err error) {
|
|
||||||
b.mu.Lock()
|
|
||||||
defer b.mu.Unlock()
|
|
||||||
if b.closed {
|
|
||||||
return 0, ErrBodyReadAfterClose
|
|
||||||
}
|
|
||||||
return b.readLocked(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Must hold b.mu.
|
|
||||||
func (b *body) readLocked(p []byte) (n int, err error) {
|
|
||||||
n, err = b.src.Read(p)
|
|
||||||
|
|
||||||
if err == io.EOF {
|
|
||||||
// Chunked case. Read the trailer.
|
|
||||||
if b.hdr != nil {
|
|
||||||
if e := b.readTrailer(); e != nil {
|
|
||||||
err = e
|
|
||||||
}
|
|
||||||
b.hdr = nil
|
|
||||||
} else {
|
|
||||||
// If the server declared the Content-Length, our body is a LimitedReader
|
|
||||||
// and we need to check whether this EOF arrived early.
|
|
||||||
if lr, ok := b.src.(*io.LimitedReader); ok && lr.N > 0 {
|
|
||||||
err = io.ErrUnexpectedEOF
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we can return an EOF here along with the read data, do
|
|
||||||
// so. This is optional per the io.Reader contract, but doing
|
|
||||||
// so helps the HTTP transport code recycle its connection
|
|
||||||
// earlier (since it will see this EOF itself), even if the
|
|
||||||
// client doesn't do future reads or Close.
|
|
||||||
if err == nil && n > 0 {
|
|
||||||
if lr, ok := b.src.(*io.LimitedReader); ok && lr.N == 0 {
|
|
||||||
err = io.EOF
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return n, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
singleCRLF = []byte("\r\n")
|
|
||||||
doubleCRLF = []byte("\r\n\r\n")
|
|
||||||
)
|
|
||||||
|
|
||||||
func seeUpcomingDoubleCRLF(r *bufio.Reader) bool {
|
|
||||||
for peekSize := 4; ; peekSize++ {
|
|
||||||
// This loop stops when Peek returns an error,
|
|
||||||
// which it does when r's buffer has been filled.
|
|
||||||
buf, err := r.Peek(peekSize)
|
|
||||||
if bytes.HasSuffix(buf, doubleCRLF) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var errTrailerEOF = errors.New("http: unexpected EOF reading trailer")
|
|
||||||
|
|
||||||
func (b *body) readTrailer() error {
|
|
||||||
// The common case, since nobody uses trailers.
|
|
||||||
buf, err := b.r.Peek(2)
|
|
||||||
if bytes.Equal(buf, singleCRLF) {
|
|
||||||
b.r.ReadByte()
|
|
||||||
b.r.ReadByte()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if len(buf) < 2 {
|
|
||||||
return errTrailerEOF
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure there's a header terminator coming up, to prevent
|
|
||||||
// a DoS with an unbounded size Trailer. It's not easy to
|
|
||||||
// slip in a LimitReader here, as textproto.NewReader requires
|
|
||||||
// a concrete *bufio.Reader. Also, we can't get all the way
|
|
||||||
// back up to our conn's LimitedReader that *might* be backing
|
|
||||||
// this bufio.Reader. Instead, a hack: we iteratively Peek up
|
|
||||||
// to the bufio.Reader's max size, looking for a double CRLF.
|
|
||||||
// This limits the trailer to the underlying buffer size, typically 4kB.
|
|
||||||
if !seeUpcomingDoubleCRLF(b.r) {
|
|
||||||
return errors.New("http: suspiciously long trailer after chunked body")
|
|
||||||
}
|
|
||||||
|
|
||||||
hdr, err := textproto.NewReader(b.r).ReadMIMEHeader()
|
|
||||||
if err != nil {
|
|
||||||
if err == io.EOF {
|
|
||||||
return errTrailerEOF
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch rr := b.hdr.(type) {
|
|
||||||
case *Request:
|
|
||||||
mergeSetHeader(&rr.Trailer, Header(hdr))
|
|
||||||
case *Response:
|
|
||||||
mergeSetHeader(&rr.Trailer, Header(hdr))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func mergeSetHeader(dst *Header, src Header) {
|
|
||||||
if *dst == nil {
|
|
||||||
*dst = src
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for k, vv := range src {
|
|
||||||
(*dst)[k] = vv
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *body) Close() error {
|
|
||||||
b.mu.Lock()
|
|
||||||
defer b.mu.Unlock()
|
|
||||||
if b.closed {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var err error
|
|
||||||
switch {
|
|
||||||
case b.hdr == nil && b.closing:
|
|
||||||
// no trailer and closing the connection next.
|
|
||||||
// no point in reading to EOF.
|
|
||||||
default:
|
|
||||||
// Fully consume the body, which will also lead to us reading
|
|
||||||
// the trailer headers after the body, if present.
|
|
||||||
_, err = io.Copy(ioutil.Discard, bodyLocked{b})
|
|
||||||
}
|
|
||||||
b.closed = true
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// bodyLocked is a io.Reader reading from a *body when its mutex is
|
|
||||||
// already held.
|
|
||||||
type bodyLocked struct {
|
|
||||||
b *body
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bl bodyLocked) Read(p []byte) (n int, err error) {
|
|
||||||
if bl.b.closed {
|
|
||||||
return 0, ErrBodyReadAfterClose
|
|
||||||
}
|
|
||||||
return bl.b.readLocked(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseContentLength trims whitespace from s and returns -1 if no value
|
|
||||||
// is set, or the value if it's >= 0.
|
|
||||||
func parseContentLength(cl string) (int64, error) {
|
|
||||||
cl = strings.TrimSpace(cl)
|
|
||||||
if cl == "" {
|
|
||||||
return -1, nil
|
|
||||||
}
|
|
||||||
n, err := strconv.ParseInt(cl, 10, 64)
|
|
||||||
if err != nil || n < 0 {
|
|
||||||
return 0, &badStringError{"bad Content-Length", cl}
|
|
||||||
}
|
|
||||||
return n, nil
|
|
||||||
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,141 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"expvar"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strconv"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// hello world, the web server
|
|
||||||
var helloRequests = expvar.NewInt("hello-requests")
|
|
||||||
|
|
||||||
func HelloServer(w http.ResponseWriter, req *http.Request) {
|
|
||||||
helloRequests.Add(1)
|
|
||||||
io.WriteString(w, "hello, world!\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simple counter server. POSTing to it will set the value.
|
|
||||||
type Counter struct {
|
|
||||||
mu sync.Mutex // protects n
|
|
||||||
n int
|
|
||||||
}
|
|
||||||
|
|
||||||
// This makes Counter satisfy the expvar.Var interface, so we can export
|
|
||||||
// it directly.
|
|
||||||
func (ctr *Counter) String() string {
|
|
||||||
ctr.mu.Lock()
|
|
||||||
defer ctr.mu.Unlock()
|
|
||||||
return fmt.Sprintf("%d", ctr.n)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ctr *Counter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
||||||
ctr.mu.Lock()
|
|
||||||
defer ctr.mu.Unlock()
|
|
||||||
switch req.Method {
|
|
||||||
case "GET":
|
|
||||||
ctr.n++
|
|
||||||
case "POST":
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
io.Copy(buf, req.Body)
|
|
||||||
body := buf.String()
|
|
||||||
if n, err := strconv.Atoi(body); err != nil {
|
|
||||||
fmt.Fprintf(w, "bad POST: %v\nbody: [%v]\n", err, body)
|
|
||||||
} else {
|
|
||||||
ctr.n = n
|
|
||||||
fmt.Fprint(w, "counter reset\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprintf(w, "counter = %d\n", ctr.n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// simple flag server
|
|
||||||
var booleanflag = flag.Bool("boolean", true, "another flag for testing")
|
|
||||||
|
|
||||||
func FlagServer(w http.ResponseWriter, req *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
||||||
fmt.Fprint(w, "Flags:\n")
|
|
||||||
flag.VisitAll(func(f *flag.Flag) {
|
|
||||||
if f.Value.String() != f.DefValue {
|
|
||||||
fmt.Fprintf(w, "%s = %s [default = %s]\n", f.Name, f.Value.String(), f.DefValue)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(w, "%s = %s\n", f.Name, f.Value.String())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// simple argument server
|
|
||||||
func ArgServer(w http.ResponseWriter, req *http.Request) {
|
|
||||||
for _, s := range os.Args {
|
|
||||||
fmt.Fprint(w, s, " ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// a channel (just for the fun of it)
|
|
||||||
type Chan chan int
|
|
||||||
|
|
||||||
func ChanCreate() Chan {
|
|
||||||
c := make(Chan)
|
|
||||||
go func(c Chan) {
|
|
||||||
for x := 0; ; x++ {
|
|
||||||
c <- x
|
|
||||||
}
|
|
||||||
}(c)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ch Chan) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
||||||
io.WriteString(w, fmt.Sprintf("channel send #%d\n", <-ch))
|
|
||||||
}
|
|
||||||
|
|
||||||
// exec a program, redirecting output
|
|
||||||
func DateServer(rw http.ResponseWriter, req *http.Request) {
|
|
||||||
rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
||||||
|
|
||||||
date, err := exec.Command("/bin/date").Output()
|
|
||||||
if err != nil {
|
|
||||||
http.Error(rw, err.Error(), 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rw.Write(date)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Logger(w http.ResponseWriter, req *http.Request) {
|
|
||||||
log.Print(req.URL)
|
|
||||||
http.Error(w, "oops", 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
var webroot = flag.String("root", os.Getenv("HOME"), "web root directory")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
// The counter is published as a variable directly.
|
|
||||||
ctr := new(Counter)
|
|
||||||
expvar.Publish("counter", ctr)
|
|
||||||
http.Handle("/counter", ctr)
|
|
||||||
http.Handle("/", http.HandlerFunc(Logger))
|
|
||||||
http.Handle("/go/", http.StripPrefix("/go/", http.FileServer(http.Dir(*webroot))))
|
|
||||||
http.Handle("/chan", ChanCreate())
|
|
||||||
http.HandleFunc("/flags", FlagServer)
|
|
||||||
http.HandleFunc("/args", ArgServer)
|
|
||||||
http.HandleFunc("/go/hello", HelloServer)
|
|
||||||
http.HandleFunc("/date", DateServer)
|
|
||||||
err := http.ListenAndServe(":12345", nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Panicln("ListenAndServe:", err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import "strconv"
|
|
||||||
|
|
||||||
type alert uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
// alert level
|
|
||||||
alertLevelWarning = 1
|
|
||||||
alertLevelError = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
alertCloseNotify alert = 0
|
|
||||||
alertUnexpectedMessage alert = 10
|
|
||||||
alertBadRecordMAC alert = 20
|
|
||||||
alertDecryptionFailed alert = 21
|
|
||||||
alertRecordOverflow alert = 22
|
|
||||||
alertDecompressionFailure alert = 30
|
|
||||||
alertHandshakeFailure alert = 40
|
|
||||||
alertBadCertificate alert = 42
|
|
||||||
alertUnsupportedCertificate alert = 43
|
|
||||||
alertCertificateRevoked alert = 44
|
|
||||||
alertCertificateExpired alert = 45
|
|
||||||
alertCertificateUnknown alert = 46
|
|
||||||
alertIllegalParameter alert = 47
|
|
||||||
alertUnknownCA alert = 48
|
|
||||||
alertAccessDenied alert = 49
|
|
||||||
alertDecodeError alert = 50
|
|
||||||
alertDecryptError alert = 51
|
|
||||||
alertProtocolVersion alert = 70
|
|
||||||
alertInsufficientSecurity alert = 71
|
|
||||||
alertInternalError alert = 80
|
|
||||||
alertUserCanceled alert = 90
|
|
||||||
alertNoRenegotiation alert = 100
|
|
||||||
)
|
|
||||||
|
|
||||||
var alertText = map[alert]string{
|
|
||||||
alertCloseNotify: "close notify",
|
|
||||||
alertUnexpectedMessage: "unexpected message",
|
|
||||||
alertBadRecordMAC: "bad record MAC",
|
|
||||||
alertDecryptionFailed: "decryption failed",
|
|
||||||
alertRecordOverflow: "record overflow",
|
|
||||||
alertDecompressionFailure: "decompression failure",
|
|
||||||
alertHandshakeFailure: "handshake failure",
|
|
||||||
alertBadCertificate: "bad certificate",
|
|
||||||
alertUnsupportedCertificate: "unsupported certificate",
|
|
||||||
alertCertificateRevoked: "revoked certificate",
|
|
||||||
alertCertificateExpired: "expired certificate",
|
|
||||||
alertCertificateUnknown: "unknown certificate",
|
|
||||||
alertIllegalParameter: "illegal parameter",
|
|
||||||
alertUnknownCA: "unknown certificate authority",
|
|
||||||
alertAccessDenied: "access denied",
|
|
||||||
alertDecodeError: "error decoding message",
|
|
||||||
alertDecryptError: "error decrypting message",
|
|
||||||
alertProtocolVersion: "protocol version not supported",
|
|
||||||
alertInsufficientSecurity: "insufficient security level",
|
|
||||||
alertInternalError: "internal error",
|
|
||||||
alertUserCanceled: "user canceled",
|
|
||||||
alertNoRenegotiation: "no renegotiation",
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e alert) String() string {
|
|
||||||
s, ok := alertText[e]
|
|
||||||
if ok {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return "alert(" + strconv.Itoa(int(e)) + ")"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e alert) Error() string {
|
|
||||||
return e.String()
|
|
||||||
}
|
|
|
@ -1,270 +0,0 @@
|
||||||
// Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/aes"
|
|
||||||
"crypto/cipher"
|
|
||||||
"crypto/des"
|
|
||||||
"crypto/hmac"
|
|
||||||
"crypto/rc4"
|
|
||||||
"crypto/sha1"
|
|
||||||
"crypto/x509"
|
|
||||||
"hash"
|
|
||||||
)
|
|
||||||
|
|
||||||
// a keyAgreement implements the client and server side of a TLS key agreement
|
|
||||||
// protocol by generating and processing key exchange messages.
|
|
||||||
type keyAgreement interface {
|
|
||||||
// On the server side, the first two methods are called in order.
|
|
||||||
|
|
||||||
// In the case that the key agreement protocol doesn't use a
|
|
||||||
// ServerKeyExchange message, generateServerKeyExchange can return nil,
|
|
||||||
// nil.
|
|
||||||
generateServerKeyExchange(*Config, *Certificate, *clientHelloMsg, *serverHelloMsg) (*serverKeyExchangeMsg, error)
|
|
||||||
processClientKeyExchange(*Config, *Certificate, *clientKeyExchangeMsg, uint16) ([]byte, error)
|
|
||||||
|
|
||||||
// On the client side, the next two methods are called in order.
|
|
||||||
|
|
||||||
// This method may not be called if the server doesn't send a
|
|
||||||
// ServerKeyExchange message.
|
|
||||||
processServerKeyExchange(*Config, *clientHelloMsg, *serverHelloMsg, *x509.Certificate, *serverKeyExchangeMsg) error
|
|
||||||
generateClientKeyExchange(*Config, *clientHelloMsg, *x509.Certificate) ([]byte, *clientKeyExchangeMsg, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
// suiteECDH indicates that the cipher suite involves elliptic curve
|
|
||||||
// Diffie-Hellman. This means that it should only be selected when the
|
|
||||||
// client indicates that it supports ECC with a curve and point format
|
|
||||||
// that we're happy with.
|
|
||||||
suiteECDHE = 1 << iota
|
|
||||||
// suiteECDSA indicates that the cipher suite involves an ECDSA
|
|
||||||
// signature and therefore may only be selected when the server's
|
|
||||||
// certificate is ECDSA. If this is not set then the cipher suite is
|
|
||||||
// RSA based.
|
|
||||||
suiteECDSA
|
|
||||||
// suiteTLS12 indicates that the cipher suite should only be advertised
|
|
||||||
// and accepted when using TLS 1.2.
|
|
||||||
suiteTLS12
|
|
||||||
)
|
|
||||||
|
|
||||||
// A cipherSuite is a specific combination of key agreement, cipher and MAC
|
|
||||||
// function. All cipher suites currently assume RSA key agreement.
|
|
||||||
type cipherSuite struct {
|
|
||||||
id uint16
|
|
||||||
// the lengths, in bytes, of the key material needed for each component.
|
|
||||||
keyLen int
|
|
||||||
macLen int
|
|
||||||
ivLen int
|
|
||||||
ka func(version uint16) keyAgreement
|
|
||||||
// flags is a bitmask of the suite* values, above.
|
|
||||||
flags int
|
|
||||||
cipher func(key, iv []byte, isRead bool) interface{}
|
|
||||||
mac func(version uint16, macKey []byte) macFunction
|
|
||||||
aead func(key, fixedNonce []byte) cipher.AEAD
|
|
||||||
}
|
|
||||||
|
|
||||||
var cipherSuites = []*cipherSuite{
|
|
||||||
// Ciphersuite order is chosen so that ECDHE comes before plain RSA
|
|
||||||
// and RC4 comes before AES (because of the Lucky13 attack).
|
|
||||||
{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 16, 0, 4, ecdheRSAKA, suiteECDHE | suiteTLS12, nil, nil, aeadAESGCM},
|
|
||||||
{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 16, 0, 4, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteTLS12, nil, nil, aeadAESGCM},
|
|
||||||
{TLS_ECDHE_RSA_WITH_RC4_128_SHA, 16, 20, 0, ecdheRSAKA, suiteECDHE, cipherRC4, macSHA1, nil},
|
|
||||||
{TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, 16, 20, 0, ecdheECDSAKA, suiteECDHE | suiteECDSA, cipherRC4, macSHA1, nil},
|
|
||||||
{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, 16, 20, 16, ecdheRSAKA, suiteECDHE, cipherAES, macSHA1, nil},
|
|
||||||
{TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, 16, 20, 16, ecdheECDSAKA, suiteECDHE | suiteECDSA, cipherAES, macSHA1, nil},
|
|
||||||
{TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, 32, 20, 16, ecdheRSAKA, suiteECDHE, cipherAES, macSHA1, nil},
|
|
||||||
{TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, 32, 20, 16, ecdheECDSAKA, suiteECDHE | suiteECDSA, cipherAES, macSHA1, nil},
|
|
||||||
{TLS_RSA_WITH_RC4_128_SHA, 16, 20, 0, rsaKA, 0, cipherRC4, macSHA1, nil},
|
|
||||||
{TLS_RSA_WITH_AES_128_CBC_SHA, 16, 20, 16, rsaKA, 0, cipherAES, macSHA1, nil},
|
|
||||||
{TLS_RSA_WITH_AES_256_CBC_SHA, 32, 20, 16, rsaKA, 0, cipherAES, macSHA1, nil},
|
|
||||||
{TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, 24, 20, 8, ecdheRSAKA, suiteECDHE, cipher3DES, macSHA1, nil},
|
|
||||||
{TLS_RSA_WITH_3DES_EDE_CBC_SHA, 24, 20, 8, rsaKA, 0, cipher3DES, macSHA1, nil},
|
|
||||||
}
|
|
||||||
|
|
||||||
func cipherRC4(key, iv []byte, isRead bool) interface{} {
|
|
||||||
cipher, _ := rc4.NewCipher(key)
|
|
||||||
return cipher
|
|
||||||
}
|
|
||||||
|
|
||||||
func cipher3DES(key, iv []byte, isRead bool) interface{} {
|
|
||||||
block, _ := des.NewTripleDESCipher(key)
|
|
||||||
if isRead {
|
|
||||||
return cipher.NewCBCDecrypter(block, iv)
|
|
||||||
}
|
|
||||||
return cipher.NewCBCEncrypter(block, iv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func cipherAES(key, iv []byte, isRead bool) interface{} {
|
|
||||||
block, _ := aes.NewCipher(key)
|
|
||||||
if isRead {
|
|
||||||
return cipher.NewCBCDecrypter(block, iv)
|
|
||||||
}
|
|
||||||
return cipher.NewCBCEncrypter(block, iv)
|
|
||||||
}
|
|
||||||
|
|
||||||
// macSHA1 returns a macFunction for the given protocol version.
|
|
||||||
func macSHA1(version uint16, key []byte) macFunction {
|
|
||||||
if version == VersionSSL30 {
|
|
||||||
mac := ssl30MAC{
|
|
||||||
h: sha1.New(),
|
|
||||||
key: make([]byte, len(key)),
|
|
||||||
}
|
|
||||||
copy(mac.key, key)
|
|
||||||
return mac
|
|
||||||
}
|
|
||||||
return tls10MAC{hmac.New(sha1.New, key)}
|
|
||||||
}
|
|
||||||
|
|
||||||
type macFunction interface {
|
|
||||||
Size() int
|
|
||||||
MAC(digestBuf, seq, header, data []byte) []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// fixedNonceAEAD wraps an AEAD and prefixes a fixed portion of the nonce to
|
|
||||||
// each call.
|
|
||||||
type fixedNonceAEAD struct {
|
|
||||||
// sealNonce and openNonce are buffers where the larger nonce will be
|
|
||||||
// constructed. Since a seal and open operation may be running
|
|
||||||
// concurrently, there is a separate buffer for each.
|
|
||||||
sealNonce, openNonce []byte
|
|
||||||
aead cipher.AEAD
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *fixedNonceAEAD) NonceSize() int { return 8 }
|
|
||||||
func (f *fixedNonceAEAD) Overhead() int { return f.aead.Overhead() }
|
|
||||||
|
|
||||||
func (f *fixedNonceAEAD) Seal(out, nonce, plaintext, additionalData []byte) []byte {
|
|
||||||
copy(f.sealNonce[len(f.sealNonce)-8:], nonce)
|
|
||||||
return f.aead.Seal(out, f.sealNonce, plaintext, additionalData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *fixedNonceAEAD) Open(out, nonce, plaintext, additionalData []byte) ([]byte, error) {
|
|
||||||
copy(f.openNonce[len(f.openNonce)-8:], nonce)
|
|
||||||
return f.aead.Open(out, f.openNonce, plaintext, additionalData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func aeadAESGCM(key, fixedNonce []byte) cipher.AEAD {
|
|
||||||
aes, err := aes.NewCipher(key)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
aead, err := cipher.NewGCM(aes)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nonce1, nonce2 := make([]byte, 12), make([]byte, 12)
|
|
||||||
copy(nonce1, fixedNonce)
|
|
||||||
copy(nonce2, fixedNonce)
|
|
||||||
|
|
||||||
return &fixedNonceAEAD{nonce1, nonce2, aead}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ssl30MAC implements the SSLv3 MAC function, as defined in
|
|
||||||
// www.mozilla.org/projects/security/pki/nss/ssl/draft302.txt section 5.2.3.1
|
|
||||||
type ssl30MAC struct {
|
|
||||||
h hash.Hash
|
|
||||||
key []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s ssl30MAC) Size() int {
|
|
||||||
return s.h.Size()
|
|
||||||
}
|
|
||||||
|
|
||||||
var ssl30Pad1 = [48]byte{0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36}
|
|
||||||
|
|
||||||
var ssl30Pad2 = [48]byte{0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c}
|
|
||||||
|
|
||||||
func (s ssl30MAC) MAC(digestBuf, seq, header, data []byte) []byte {
|
|
||||||
padLength := 48
|
|
||||||
if s.h.Size() == 20 {
|
|
||||||
padLength = 40
|
|
||||||
}
|
|
||||||
|
|
||||||
s.h.Reset()
|
|
||||||
s.h.Write(s.key)
|
|
||||||
s.h.Write(ssl30Pad1[:padLength])
|
|
||||||
s.h.Write(seq)
|
|
||||||
s.h.Write(header[:1])
|
|
||||||
s.h.Write(header[3:5])
|
|
||||||
s.h.Write(data)
|
|
||||||
digestBuf = s.h.Sum(digestBuf[:0])
|
|
||||||
|
|
||||||
s.h.Reset()
|
|
||||||
s.h.Write(s.key)
|
|
||||||
s.h.Write(ssl30Pad2[:padLength])
|
|
||||||
s.h.Write(digestBuf)
|
|
||||||
return s.h.Sum(digestBuf[:0])
|
|
||||||
}
|
|
||||||
|
|
||||||
// tls10MAC implements the TLS 1.0 MAC function. RFC 2246, section 6.2.3.
|
|
||||||
type tls10MAC struct {
|
|
||||||
h hash.Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s tls10MAC) Size() int {
|
|
||||||
return s.h.Size()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s tls10MAC) MAC(digestBuf, seq, header, data []byte) []byte {
|
|
||||||
s.h.Reset()
|
|
||||||
s.h.Write(seq)
|
|
||||||
s.h.Write(header)
|
|
||||||
s.h.Write(data)
|
|
||||||
return s.h.Sum(digestBuf[:0])
|
|
||||||
}
|
|
||||||
|
|
||||||
func rsaKA(version uint16) keyAgreement {
|
|
||||||
return rsaKeyAgreement{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ecdheECDSAKA(version uint16) keyAgreement {
|
|
||||||
return &ecdheKeyAgreement{
|
|
||||||
sigType: signatureECDSA,
|
|
||||||
version: version,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ecdheRSAKA(version uint16) keyAgreement {
|
|
||||||
return &ecdheKeyAgreement{
|
|
||||||
sigType: signatureRSA,
|
|
||||||
version: version,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// mutualCipherSuite returns a cipherSuite given a list of supported
|
|
||||||
// ciphersuites and the id requested by the peer.
|
|
||||||
func mutualCipherSuite(have []uint16, want uint16) *cipherSuite {
|
|
||||||
for _, id := range have {
|
|
||||||
if id == want {
|
|
||||||
for _, suite := range cipherSuites {
|
|
||||||
if suite.id == want {
|
|
||||||
return suite
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// A list of the possible cipher suite ids. Taken from
|
|
||||||
// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml
|
|
||||||
const (
|
|
||||||
TLS_RSA_WITH_RC4_128_SHA uint16 = 0x0005
|
|
||||||
TLS_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0x000a
|
|
||||||
TLS_RSA_WITH_AES_128_CBC_SHA uint16 = 0x002f
|
|
||||||
TLS_RSA_WITH_AES_256_CBC_SHA uint16 = 0x0035
|
|
||||||
TLS_ECDHE_ECDSA_WITH_RC4_128_SHA uint16 = 0xc007
|
|
||||||
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA uint16 = 0xc009
|
|
||||||
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA uint16 = 0xc00a
|
|
||||||
TLS_ECDHE_RSA_WITH_RC4_128_SHA uint16 = 0xc011
|
|
||||||
TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0xc012
|
|
||||||
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA uint16 = 0xc013
|
|
||||||
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA uint16 = 0xc014
|
|
||||||
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02f
|
|
||||||
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02b
|
|
||||||
)
|
|
|
@ -1,438 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto"
|
|
||||||
"crypto/rand"
|
|
||||||
"crypto/x509"
|
|
||||||
"io"
|
|
||||||
"math/big"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
VersionSSL30 = 0x0300
|
|
||||||
VersionTLS10 = 0x0301
|
|
||||||
VersionTLS11 = 0x0302
|
|
||||||
VersionTLS12 = 0x0303
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
maxPlaintext = 16384 // maximum plaintext payload length
|
|
||||||
maxCiphertext = 16384 + 2048 // maximum ciphertext payload length
|
|
||||||
recordHeaderLen = 5 // record header length
|
|
||||||
maxHandshake = 65536 // maximum handshake we support (protocol max is 16 MB)
|
|
||||||
|
|
||||||
minVersion = VersionSSL30
|
|
||||||
maxVersion = VersionTLS12
|
|
||||||
)
|
|
||||||
|
|
||||||
// TLS record types.
|
|
||||||
type recordType uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
recordTypeChangeCipherSpec recordType = 20
|
|
||||||
recordTypeAlert recordType = 21
|
|
||||||
recordTypeHandshake recordType = 22
|
|
||||||
recordTypeApplicationData recordType = 23
|
|
||||||
)
|
|
||||||
|
|
||||||
// TLS handshake message types.
|
|
||||||
const (
|
|
||||||
typeHelloRequest uint8 = 0
|
|
||||||
typeClientHello uint8 = 1
|
|
||||||
typeServerHello uint8 = 2
|
|
||||||
typeNewSessionTicket uint8 = 4
|
|
||||||
typeCertificate uint8 = 11
|
|
||||||
typeServerKeyExchange uint8 = 12
|
|
||||||
typeCertificateRequest uint8 = 13
|
|
||||||
typeServerHelloDone uint8 = 14
|
|
||||||
typeCertificateVerify uint8 = 15
|
|
||||||
typeClientKeyExchange uint8 = 16
|
|
||||||
typeFinished uint8 = 20
|
|
||||||
typeCertificateStatus uint8 = 22
|
|
||||||
typeNextProtocol uint8 = 67 // Not IANA assigned
|
|
||||||
)
|
|
||||||
|
|
||||||
// TLS compression types.
|
|
||||||
const (
|
|
||||||
compressionNone uint8 = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
// TLS extension numbers
|
|
||||||
var (
|
|
||||||
extensionServerName uint16 = 0
|
|
||||||
extensionStatusRequest uint16 = 5
|
|
||||||
extensionSupportedCurves uint16 = 10
|
|
||||||
extensionSupportedPoints uint16 = 11
|
|
||||||
extensionSignatureAlgorithms uint16 = 13
|
|
||||||
extensionSessionTicket uint16 = 35
|
|
||||||
extensionNextProtoNeg uint16 = 13172 // not IANA assigned
|
|
||||||
)
|
|
||||||
|
|
||||||
// TLS Elliptic Curves
|
|
||||||
// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8
|
|
||||||
var (
|
|
||||||
curveP256 uint16 = 23
|
|
||||||
curveP384 uint16 = 24
|
|
||||||
curveP521 uint16 = 25
|
|
||||||
)
|
|
||||||
|
|
||||||
// TLS Elliptic Curve Point Formats
|
|
||||||
// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-9
|
|
||||||
var (
|
|
||||||
pointFormatUncompressed uint8 = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
// TLS CertificateStatusType (RFC 3546)
|
|
||||||
const (
|
|
||||||
statusTypeOCSP uint8 = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
// Certificate types (for certificateRequestMsg)
|
|
||||||
const (
|
|
||||||
certTypeRSASign = 1 // A certificate containing an RSA key
|
|
||||||
certTypeDSSSign = 2 // A certificate containing a DSA key
|
|
||||||
certTypeRSAFixedDH = 3 // A certificate containing a static DH key
|
|
||||||
certTypeDSSFixedDH = 4 // A certificate containing a static DH key
|
|
||||||
|
|
||||||
// See RFC4492 sections 3 and 5.5.
|
|
||||||
certTypeECDSASign = 64 // A certificate containing an ECDSA-capable public key, signed with ECDSA.
|
|
||||||
certTypeRSAFixedECDH = 65 // A certificate containing an ECDH-capable public key, signed with RSA.
|
|
||||||
certTypeECDSAFixedECDH = 66 // A certificate containing an ECDH-capable public key, signed with ECDSA.
|
|
||||||
|
|
||||||
// Rest of these are reserved by the TLS spec
|
|
||||||
)
|
|
||||||
|
|
||||||
// Hash functions for TLS 1.2 (See RFC 5246, section A.4.1)
|
|
||||||
const (
|
|
||||||
hashSHA1 uint8 = 2
|
|
||||||
hashSHA256 uint8 = 4
|
|
||||||
)
|
|
||||||
|
|
||||||
// Signature algorithms for TLS 1.2 (See RFC 5246, section A.4.1)
|
|
||||||
const (
|
|
||||||
signatureRSA uint8 = 1
|
|
||||||
signatureECDSA uint8 = 3
|
|
||||||
)
|
|
||||||
|
|
||||||
// signatureAndHash mirrors the TLS 1.2, SignatureAndHashAlgorithm struct. See
|
|
||||||
// RFC 5246, section A.4.1.
|
|
||||||
type signatureAndHash struct {
|
|
||||||
hash, signature uint8
|
|
||||||
}
|
|
||||||
|
|
||||||
// supportedSKXSignatureAlgorithms contains the signature and hash algorithms
|
|
||||||
// that the code advertises as supported in a TLS 1.2 ClientHello.
|
|
||||||
var supportedSKXSignatureAlgorithms = []signatureAndHash{
|
|
||||||
{hashSHA256, signatureRSA},
|
|
||||||
{hashSHA256, signatureECDSA},
|
|
||||||
{hashSHA1, signatureRSA},
|
|
||||||
{hashSHA1, signatureECDSA},
|
|
||||||
}
|
|
||||||
|
|
||||||
// supportedClientCertSignatureAlgorithms contains the signature and hash
|
|
||||||
// algorithms that the code advertises as supported in a TLS 1.2
|
|
||||||
// CertificateRequest.
|
|
||||||
var supportedClientCertSignatureAlgorithms = []signatureAndHash{
|
|
||||||
{hashSHA256, signatureRSA},
|
|
||||||
{hashSHA256, signatureECDSA},
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConnectionState records basic TLS details about the connection.
|
|
||||||
type ConnectionState struct {
|
|
||||||
HandshakeComplete bool // TLS handshake is complete
|
|
||||||
DidResume bool // connection resumes a previous TLS connection
|
|
||||||
CipherSuite uint16 // cipher suite in use (TLS_RSA_WITH_RC4_128_SHA, ...)
|
|
||||||
NegotiatedProtocol string // negotiated next protocol (from Config.NextProtos)
|
|
||||||
NegotiatedProtocolIsMutual bool // negotiated protocol was advertised by server
|
|
||||||
ServerName string // server name requested by client, if any (server side only)
|
|
||||||
PeerCertificates []*x509.Certificate // certificate chain presented by remote peer
|
|
||||||
VerifiedChains [][]*x509.Certificate // verified chains built from PeerCertificates
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientAuthType declares the policy the server will follow for
|
|
||||||
// TLS Client Authentication.
|
|
||||||
type ClientAuthType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
NoClientCert ClientAuthType = iota
|
|
||||||
RequestClientCert
|
|
||||||
RequireAnyClientCert
|
|
||||||
VerifyClientCertIfGiven
|
|
||||||
RequireAndVerifyClientCert
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Config structure is used to configure a TLS client or server. After one
|
|
||||||
// has been passed to a TLS function it must not be modified.
|
|
||||||
type Config struct {
|
|
||||||
// Rand provides the source of entropy for nonces and RSA blinding.
|
|
||||||
// If Rand is nil, TLS uses the cryptographic random reader in package
|
|
||||||
// crypto/rand.
|
|
||||||
Rand io.Reader
|
|
||||||
|
|
||||||
// Time returns the current time as the number of seconds since the epoch.
|
|
||||||
// If Time is nil, TLS uses time.Now.
|
|
||||||
Time func() time.Time
|
|
||||||
|
|
||||||
// Certificates contains one or more certificate chains
|
|
||||||
// to present to the other side of the connection.
|
|
||||||
// Server configurations must include at least one certificate.
|
|
||||||
Certificates []Certificate
|
|
||||||
|
|
||||||
// NameToCertificate maps from a certificate name to an element of
|
|
||||||
// Certificates. Note that a certificate name can be of the form
|
|
||||||
// '*.example.com' and so doesn't have to be a domain name as such.
|
|
||||||
// See Config.BuildNameToCertificate
|
|
||||||
// The nil value causes the first element of Certificates to be used
|
|
||||||
// for all connections.
|
|
||||||
NameToCertificate map[string]*Certificate
|
|
||||||
|
|
||||||
// RootCAs defines the set of root certificate authorities
|
|
||||||
// that clients use when verifying server certificates.
|
|
||||||
// If RootCAs is nil, TLS uses the host's root CA set.
|
|
||||||
RootCAs *x509.CertPool
|
|
||||||
|
|
||||||
// NextProtos is a list of supported, application level protocols.
|
|
||||||
NextProtos []string
|
|
||||||
|
|
||||||
// ServerName is included in the client's handshake to support virtual
|
|
||||||
// hosting.
|
|
||||||
ServerName string
|
|
||||||
|
|
||||||
// ClientAuth determines the server's policy for
|
|
||||||
// TLS Client Authentication. The default is NoClientCert.
|
|
||||||
ClientAuth ClientAuthType
|
|
||||||
|
|
||||||
// ClientCAs defines the set of root certificate authorities
|
|
||||||
// that servers use if required to verify a client certificate
|
|
||||||
// by the policy in ClientAuth.
|
|
||||||
ClientCAs *x509.CertPool
|
|
||||||
|
|
||||||
// InsecureSkipVerify controls whether a client verifies the
|
|
||||||
// server's certificate chain and host name.
|
|
||||||
// If InsecureSkipVerify is true, TLS accepts any certificate
|
|
||||||
// presented by the server and any host name in that certificate.
|
|
||||||
// In this mode, TLS is susceptible to man-in-the-middle attacks.
|
|
||||||
// This should be used only for testing.
|
|
||||||
InsecureSkipVerify bool
|
|
||||||
|
|
||||||
// CipherSuites is a list of supported cipher suites. If CipherSuites
|
|
||||||
// is nil, TLS uses a list of suites supported by the implementation.
|
|
||||||
CipherSuites []uint16
|
|
||||||
|
|
||||||
// PreferServerCipherSuites controls whether the server selects the
|
|
||||||
// client's most preferred ciphersuite, or the server's most preferred
|
|
||||||
// ciphersuite. If true then the server's preference, as expressed in
|
|
||||||
// the order of elements in CipherSuites, is used.
|
|
||||||
PreferServerCipherSuites bool
|
|
||||||
|
|
||||||
// SessionTicketsDisabled may be set to true to disable session ticket
|
|
||||||
// (resumption) support.
|
|
||||||
SessionTicketsDisabled bool
|
|
||||||
|
|
||||||
// SessionTicketKey is used by TLS servers to provide session
|
|
||||||
// resumption. See RFC 5077. If zero, it will be filled with
|
|
||||||
// random data before the first server handshake.
|
|
||||||
//
|
|
||||||
// If multiple servers are terminating connections for the same host
|
|
||||||
// they should all have the same SessionTicketKey. If the
|
|
||||||
// SessionTicketKey leaks, previously recorded and future TLS
|
|
||||||
// connections using that key are compromised.
|
|
||||||
SessionTicketKey [32]byte
|
|
||||||
|
|
||||||
// MinVersion contains the minimum SSL/TLS version that is acceptable.
|
|
||||||
// If zero, then SSLv3 is taken as the minimum.
|
|
||||||
MinVersion uint16
|
|
||||||
|
|
||||||
// MaxVersion contains the maximum SSL/TLS version that is acceptable.
|
|
||||||
// If zero, then the maximum version supported by this package is used,
|
|
||||||
// which is currently TLS 1.2.
|
|
||||||
MaxVersion uint16
|
|
||||||
|
|
||||||
serverInitOnce sync.Once // guards calling (*Config).serverInit
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) serverInit() {
|
|
||||||
if c.SessionTicketsDisabled {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the key has already been set then we have nothing to do.
|
|
||||||
for _, b := range c.SessionTicketKey {
|
|
||||||
if b != 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil {
|
|
||||||
c.SessionTicketsDisabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) rand() io.Reader {
|
|
||||||
r := c.Rand
|
|
||||||
if r == nil {
|
|
||||||
return rand.Reader
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) time() time.Time {
|
|
||||||
t := c.Time
|
|
||||||
if t == nil {
|
|
||||||
t = time.Now
|
|
||||||
}
|
|
||||||
return t()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) cipherSuites() []uint16 {
|
|
||||||
s := c.CipherSuites
|
|
||||||
if s == nil {
|
|
||||||
s = defaultCipherSuites()
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) minVersion() uint16 {
|
|
||||||
if c == nil || c.MinVersion == 0 {
|
|
||||||
return minVersion
|
|
||||||
}
|
|
||||||
return c.MinVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) maxVersion() uint16 {
|
|
||||||
if c == nil || c.MaxVersion == 0 {
|
|
||||||
return maxVersion
|
|
||||||
}
|
|
||||||
return c.MaxVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
// mutualVersion returns the protocol version to use given the advertised
|
|
||||||
// version of the peer.
|
|
||||||
func (c *Config) mutualVersion(vers uint16) (uint16, bool) {
|
|
||||||
minVersion := c.minVersion()
|
|
||||||
maxVersion := c.maxVersion()
|
|
||||||
|
|
||||||
if vers < minVersion {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
if vers > maxVersion {
|
|
||||||
vers = maxVersion
|
|
||||||
}
|
|
||||||
return vers, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// getCertificateForName returns the best certificate for the given name,
|
|
||||||
// defaulting to the first element of c.Certificates if there are no good
|
|
||||||
// options.
|
|
||||||
func (c *Config) getCertificateForName(name string) *Certificate {
|
|
||||||
if len(c.Certificates) == 1 || c.NameToCertificate == nil {
|
|
||||||
// There's only one choice, so no point doing any work.
|
|
||||||
return &c.Certificates[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
name = strings.ToLower(name)
|
|
||||||
for len(name) > 0 && name[len(name)-1] == '.' {
|
|
||||||
name = name[:len(name)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
if cert, ok := c.NameToCertificate[name]; ok {
|
|
||||||
return cert
|
|
||||||
}
|
|
||||||
|
|
||||||
// try replacing labels in the name with wildcards until we get a
|
|
||||||
// match.
|
|
||||||
labels := strings.Split(name, ".")
|
|
||||||
for i := range labels {
|
|
||||||
labels[i] = "*"
|
|
||||||
candidate := strings.Join(labels, ".")
|
|
||||||
if cert, ok := c.NameToCertificate[candidate]; ok {
|
|
||||||
return cert
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If nothing matches, return the first certificate.
|
|
||||||
return &c.Certificates[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// BuildNameToCertificate parses c.Certificates and builds c.NameToCertificate
|
|
||||||
// from the CommonName and SubjectAlternateName fields of each of the leaf
|
|
||||||
// certificates.
|
|
||||||
func (c *Config) BuildNameToCertificate() {
|
|
||||||
c.NameToCertificate = make(map[string]*Certificate)
|
|
||||||
for i := range c.Certificates {
|
|
||||||
cert := &c.Certificates[i]
|
|
||||||
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(x509Cert.Subject.CommonName) > 0 {
|
|
||||||
c.NameToCertificate[x509Cert.Subject.CommonName] = cert
|
|
||||||
}
|
|
||||||
for _, san := range x509Cert.DNSNames {
|
|
||||||
c.NameToCertificate[san] = cert
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A Certificate is a chain of one or more certificates, leaf first.
|
|
||||||
type Certificate struct {
|
|
||||||
Certificate [][]byte
|
|
||||||
PrivateKey crypto.PrivateKey // supported types: *rsa.PrivateKey, *ecdsa.PrivateKey
|
|
||||||
// OCSPStaple contains an optional OCSP response which will be served
|
|
||||||
// to clients that request it.
|
|
||||||
OCSPStaple []byte
|
|
||||||
// Leaf is the parsed form of the leaf certificate, which may be
|
|
||||||
// initialized using x509.ParseCertificate to reduce per-handshake
|
|
||||||
// processing for TLS clients doing client authentication. If nil, the
|
|
||||||
// leaf certificate will be parsed as needed.
|
|
||||||
Leaf *x509.Certificate
|
|
||||||
}
|
|
||||||
|
|
||||||
// A TLS record.
|
|
||||||
type record struct {
|
|
||||||
contentType recordType
|
|
||||||
major, minor uint8
|
|
||||||
payload []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
type handshakeMessage interface {
|
|
||||||
marshal() []byte
|
|
||||||
unmarshal([]byte) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(jsing): Make these available to both crypto/x509 and crypto/tls.
|
|
||||||
type dsaSignature struct {
|
|
||||||
R, S *big.Int
|
|
||||||
}
|
|
||||||
|
|
||||||
type ecdsaSignature dsaSignature
|
|
||||||
|
|
||||||
var emptyConfig Config
|
|
||||||
|
|
||||||
func defaultConfig() *Config {
|
|
||||||
return &emptyConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
once sync.Once
|
|
||||||
varDefaultCipherSuites []uint16
|
|
||||||
)
|
|
||||||
|
|
||||||
func defaultCipherSuites() []uint16 {
|
|
||||||
once.Do(initDefaultCipherSuites)
|
|
||||||
return varDefaultCipherSuites
|
|
||||||
}
|
|
||||||
|
|
||||||
func initDefaultCipherSuites() {
|
|
||||||
varDefaultCipherSuites = make([]uint16, len(cipherSuites))
|
|
||||||
for i, suite := range cipherSuites {
|
|
||||||
varDefaultCipherSuites[i] = suite.id
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,118 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
// Generate a self-signed X.509 certificate for a TLS server. Outputs to
|
|
||||||
// 'cert.pem' and 'key.pem' and will overwrite existing files.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/rand"
|
|
||||||
"crypto/rsa"
|
|
||||||
"crypto/x509"
|
|
||||||
"crypto/x509/pkix"
|
|
||||||
"encoding/pem"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"math/big"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
host = flag.String("host", "", "Comma-separated hostnames and IPs to generate a certificate for")
|
|
||||||
validFrom = flag.String("start-date", "", "Creation date formatted as Jan 1 15:04:05 2011")
|
|
||||||
validFor = flag.Duration("duration", 365*24*time.Hour, "Duration that certificate is valid for")
|
|
||||||
isCA = flag.Bool("ca", false, "whether this cert should be its own Certificate Authority")
|
|
||||||
rsaBits = flag.Int("rsa-bits", 2048, "Size of RSA key to generate")
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if len(*host) == 0 {
|
|
||||||
log.Fatalf("Missing required --host parameter")
|
|
||||||
}
|
|
||||||
|
|
||||||
priv, err := rsa.GenerateKey(rand.Reader, *rsaBits)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("failed to generate private key: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var notBefore time.Time
|
|
||||||
if len(*validFrom) == 0 {
|
|
||||||
notBefore = time.Now()
|
|
||||||
} else {
|
|
||||||
notBefore, err = time.Parse("Jan 2 15:04:05 2006", *validFrom)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Failed to parse creation date: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notAfter := notBefore.Add(*validFor)
|
|
||||||
|
|
||||||
// end of ASN.1 time
|
|
||||||
endOfTime := time.Date(2049, 12, 31, 23, 59, 59, 0, time.UTC)
|
|
||||||
if notAfter.After(endOfTime) {
|
|
||||||
notAfter = endOfTime
|
|
||||||
}
|
|
||||||
|
|
||||||
template := x509.Certificate{
|
|
||||||
SerialNumber: new(big.Int).SetInt64(0),
|
|
||||||
Subject: pkix.Name{
|
|
||||||
Organization: []string{"Acme Co"},
|
|
||||||
},
|
|
||||||
NotBefore: notBefore,
|
|
||||||
NotAfter: notAfter,
|
|
||||||
|
|
||||||
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
|
|
||||||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
|
|
||||||
BasicConstraintsValid: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
hosts := strings.Split(*host, ",")
|
|
||||||
for _, h := range hosts {
|
|
||||||
if ip := net.ParseIP(h); ip != nil {
|
|
||||||
template.IPAddresses = append(template.IPAddresses, ip)
|
|
||||||
} else {
|
|
||||||
template.DNSNames = append(template.DNSNames, h)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if *isCA {
|
|
||||||
template.IsCA = true
|
|
||||||
template.KeyUsage |= x509.KeyUsageCertSign
|
|
||||||
}
|
|
||||||
|
|
||||||
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to create certificate: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
certOut, err := os.Create("cert.pem")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("failed to open cert.pem for writing: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
|
|
||||||
certOut.Close()
|
|
||||||
log.Print("written cert.pem\n")
|
|
||||||
|
|
||||||
keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
||||||
if err != nil {
|
|
||||||
log.Print("failed to open key.pem for writing:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
|
|
||||||
keyOut.Close()
|
|
||||||
log.Print("written key.pem\n")
|
|
||||||
}
|
|
|
@ -1,411 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"crypto/ecdsa"
|
|
||||||
"crypto/rsa"
|
|
||||||
"crypto/subtle"
|
|
||||||
"crypto/x509"
|
|
||||||
"encoding/asn1"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *Conn) clientHandshake() error {
|
|
||||||
if c.config == nil {
|
|
||||||
c.config = defaultConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
hello := &clientHelloMsg{
|
|
||||||
vers: c.config.maxVersion(),
|
|
||||||
compressionMethods: []uint8{compressionNone},
|
|
||||||
random: make([]byte, 32),
|
|
||||||
ocspStapling: true,
|
|
||||||
serverName: c.config.ServerName,
|
|
||||||
supportedCurves: []uint16{curveP256, curveP384, curveP521},
|
|
||||||
supportedPoints: []uint8{pointFormatUncompressed},
|
|
||||||
nextProtoNeg: len(c.config.NextProtos) > 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
possibleCipherSuites := c.config.cipherSuites()
|
|
||||||
hello.cipherSuites = make([]uint16, 0, len(possibleCipherSuites))
|
|
||||||
|
|
||||||
NextCipherSuite:
|
|
||||||
for _, suiteId := range possibleCipherSuites {
|
|
||||||
for _, suite := range cipherSuites {
|
|
||||||
if suite.id != suiteId {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Don't advertise TLS 1.2-only cipher suites unless
|
|
||||||
// we're attempting TLS 1.2.
|
|
||||||
if hello.vers < VersionTLS12 && suite.flags&suiteTLS12 != 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
hello.cipherSuites = append(hello.cipherSuites, suiteId)
|
|
||||||
continue NextCipherSuite
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t := uint32(c.config.time().Unix())
|
|
||||||
hello.random[0] = byte(t >> 24)
|
|
||||||
hello.random[1] = byte(t >> 16)
|
|
||||||
hello.random[2] = byte(t >> 8)
|
|
||||||
hello.random[3] = byte(t)
|
|
||||||
_, err := io.ReadFull(c.config.rand(), hello.random[4:])
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertInternalError)
|
|
||||||
return errors.New("short read from Rand")
|
|
||||||
}
|
|
||||||
|
|
||||||
if hello.vers >= VersionTLS12 {
|
|
||||||
hello.signatureAndHashes = supportedSKXSignatureAlgorithms
|
|
||||||
}
|
|
||||||
|
|
||||||
c.writeRecord(recordTypeHandshake, hello.marshal())
|
|
||||||
|
|
||||||
msg, err := c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
serverHello, ok := msg.(*serverHelloMsg)
|
|
||||||
if !ok {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
vers, ok := c.config.mutualVersion(serverHello.vers)
|
|
||||||
if !ok || vers < VersionTLS10 {
|
|
||||||
// TLS 1.0 is the minimum version supported as a client.
|
|
||||||
return c.sendAlert(alertProtocolVersion)
|
|
||||||
}
|
|
||||||
c.vers = vers
|
|
||||||
c.haveVers = true
|
|
||||||
|
|
||||||
finishedHash := newFinishedHash(c.vers)
|
|
||||||
finishedHash.Write(hello.marshal())
|
|
||||||
finishedHash.Write(serverHello.marshal())
|
|
||||||
|
|
||||||
if serverHello.compressionMethod != compressionNone {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hello.nextProtoNeg && serverHello.nextProtoNeg {
|
|
||||||
c.sendAlert(alertHandshakeFailure)
|
|
||||||
return errors.New("server advertised unrequested NPN")
|
|
||||||
}
|
|
||||||
|
|
||||||
suite := mutualCipherSuite(c.config.cipherSuites(), serverHello.cipherSuite)
|
|
||||||
if suite == nil {
|
|
||||||
return c.sendAlert(alertHandshakeFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err = c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
certMsg, ok := msg.(*certificateMsg)
|
|
||||||
if !ok || len(certMsg.certificates) == 0 {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
finishedHash.Write(certMsg.marshal())
|
|
||||||
|
|
||||||
certs := make([]*x509.Certificate, len(certMsg.certificates))
|
|
||||||
for i, asn1Data := range certMsg.certificates {
|
|
||||||
cert, err := x509.ParseCertificate(asn1Data)
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertBadCertificate)
|
|
||||||
return errors.New("failed to parse certificate from server: " + err.Error())
|
|
||||||
}
|
|
||||||
certs[i] = cert
|
|
||||||
}
|
|
||||||
|
|
||||||
if !c.config.InsecureSkipVerify {
|
|
||||||
opts := x509.VerifyOptions{
|
|
||||||
Roots: c.config.RootCAs,
|
|
||||||
CurrentTime: c.config.time(),
|
|
||||||
DNSName: c.config.ServerName,
|
|
||||||
Intermediates: x509.NewCertPool(),
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, cert := range certs {
|
|
||||||
if i == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
opts.Intermediates.AddCert(cert)
|
|
||||||
}
|
|
||||||
c.verifiedChains, err = certs[0].Verify(opts)
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertBadCertificate)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch certs[0].PublicKey.(type) {
|
|
||||||
case *rsa.PublicKey, *ecdsa.PublicKey:
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
return c.sendAlert(alertUnsupportedCertificate)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.peerCertificates = certs
|
|
||||||
|
|
||||||
if serverHello.ocspStapling {
|
|
||||||
msg, err = c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
cs, ok := msg.(*certificateStatusMsg)
|
|
||||||
if !ok {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
finishedHash.Write(cs.marshal())
|
|
||||||
|
|
||||||
if cs.statusType == statusTypeOCSP {
|
|
||||||
c.ocspResponse = cs.response
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err = c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
keyAgreement := suite.ka(c.vers)
|
|
||||||
|
|
||||||
skx, ok := msg.(*serverKeyExchangeMsg)
|
|
||||||
if ok {
|
|
||||||
finishedHash.Write(skx.marshal())
|
|
||||||
err = keyAgreement.processServerKeyExchange(c.config, hello, serverHello, certs[0], skx)
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertUnexpectedMessage)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err = c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var chainToSend *Certificate
|
|
||||||
var certRequested bool
|
|
||||||
certReq, ok := msg.(*certificateRequestMsg)
|
|
||||||
if ok {
|
|
||||||
certRequested = true
|
|
||||||
|
|
||||||
// RFC 4346 on the certificateAuthorities field:
|
|
||||||
// A list of the distinguished names of acceptable certificate
|
|
||||||
// authorities. These distinguished names may specify a desired
|
|
||||||
// distinguished name for a root CA or for a subordinate CA;
|
|
||||||
// thus, this message can be used to describe both known roots
|
|
||||||
// and a desired authorization space. If the
|
|
||||||
// certificate_authorities list is empty then the client MAY
|
|
||||||
// send any certificate of the appropriate
|
|
||||||
// ClientCertificateType, unless there is some external
|
|
||||||
// arrangement to the contrary.
|
|
||||||
|
|
||||||
finishedHash.Write(certReq.marshal())
|
|
||||||
|
|
||||||
var rsaAvail, ecdsaAvail bool
|
|
||||||
for _, certType := range certReq.certificateTypes {
|
|
||||||
switch certType {
|
|
||||||
case certTypeRSASign:
|
|
||||||
rsaAvail = true
|
|
||||||
case certTypeECDSASign:
|
|
||||||
ecdsaAvail = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to search our list of client certs for one
|
|
||||||
// where SignatureAlgorithm is RSA and the Issuer is in
|
|
||||||
// certReq.certificateAuthorities
|
|
||||||
findCert:
|
|
||||||
for i, chain := range c.config.Certificates {
|
|
||||||
if !rsaAvail && !ecdsaAvail {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for j, cert := range chain.Certificate {
|
|
||||||
x509Cert := chain.Leaf
|
|
||||||
// parse the certificate if this isn't the leaf
|
|
||||||
// node, or if chain.Leaf was nil
|
|
||||||
if j != 0 || x509Cert == nil {
|
|
||||||
if x509Cert, err = x509.ParseCertificate(cert); err != nil {
|
|
||||||
c.sendAlert(alertInternalError)
|
|
||||||
return errors.New("tls: failed to parse client certificate #" + strconv.Itoa(i) + ": " + err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case rsaAvail && x509Cert.PublicKeyAlgorithm == x509.RSA:
|
|
||||||
case ecdsaAvail && x509Cert.PublicKeyAlgorithm == x509.ECDSA:
|
|
||||||
default:
|
|
||||||
continue findCert
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(certReq.certificateAuthorities) == 0 {
|
|
||||||
// they gave us an empty list, so just take the
|
|
||||||
// first RSA cert from c.config.Certificates
|
|
||||||
chainToSend = &chain
|
|
||||||
break findCert
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ca := range certReq.certificateAuthorities {
|
|
||||||
if bytes.Equal(x509Cert.RawIssuer, ca) {
|
|
||||||
chainToSend = &chain
|
|
||||||
break findCert
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err = c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shd, ok := msg.(*serverHelloDoneMsg)
|
|
||||||
if !ok {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
finishedHash.Write(shd.marshal())
|
|
||||||
|
|
||||||
// If the server requested a certificate then we have to send a
|
|
||||||
// Certificate message, even if it's empty because we don't have a
|
|
||||||
// certificate to send.
|
|
||||||
if certRequested {
|
|
||||||
certMsg = new(certificateMsg)
|
|
||||||
if chainToSend != nil {
|
|
||||||
certMsg.certificates = chainToSend.Certificate
|
|
||||||
}
|
|
||||||
finishedHash.Write(certMsg.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, certMsg.marshal())
|
|
||||||
}
|
|
||||||
|
|
||||||
preMasterSecret, ckx, err := keyAgreement.generateClientKeyExchange(c.config, hello, certs[0])
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertInternalError)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if ckx != nil {
|
|
||||||
finishedHash.Write(ckx.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, ckx.marshal())
|
|
||||||
}
|
|
||||||
|
|
||||||
if chainToSend != nil {
|
|
||||||
var signed []byte
|
|
||||||
certVerify := &certificateVerifyMsg{
|
|
||||||
hasSignatureAndHash: c.vers >= VersionTLS12,
|
|
||||||
}
|
|
||||||
|
|
||||||
switch key := c.config.Certificates[0].PrivateKey.(type) {
|
|
||||||
case *ecdsa.PrivateKey:
|
|
||||||
digest, _, hashId := finishedHash.hashForClientCertificate(signatureECDSA)
|
|
||||||
r, s, err := ecdsa.Sign(c.config.rand(), key, digest)
|
|
||||||
if err == nil {
|
|
||||||
signed, err = asn1.Marshal(ecdsaSignature{r, s})
|
|
||||||
}
|
|
||||||
certVerify.signatureAndHash.signature = signatureECDSA
|
|
||||||
certVerify.signatureAndHash.hash = hashId
|
|
||||||
case *rsa.PrivateKey:
|
|
||||||
digest, hashFunc, hashId := finishedHash.hashForClientCertificate(signatureRSA)
|
|
||||||
signed, err = rsa.SignPKCS1v15(c.config.rand(), key, hashFunc, digest)
|
|
||||||
certVerify.signatureAndHash.signature = signatureRSA
|
|
||||||
certVerify.signatureAndHash.hash = hashId
|
|
||||||
default:
|
|
||||||
err = errors.New("unknown private key type")
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return c.sendAlert(alertInternalError)
|
|
||||||
}
|
|
||||||
certVerify.signature = signed
|
|
||||||
|
|
||||||
finishedHash.Write(certVerify.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, certVerify.marshal())
|
|
||||||
}
|
|
||||||
|
|
||||||
masterSecret := masterFromPreMasterSecret(c.vers, preMasterSecret, hello.random, serverHello.random)
|
|
||||||
clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
|
|
||||||
keysFromMasterSecret(c.vers, masterSecret, hello.random, serverHello.random, suite.macLen, suite.keyLen, suite.ivLen)
|
|
||||||
|
|
||||||
var clientCipher interface{}
|
|
||||||
var clientHash macFunction
|
|
||||||
if suite.cipher != nil {
|
|
||||||
clientCipher = suite.cipher(clientKey, clientIV, false /* not for reading */)
|
|
||||||
clientHash = suite.mac(c.vers, clientMAC)
|
|
||||||
} else {
|
|
||||||
clientCipher = suite.aead(clientKey, clientIV)
|
|
||||||
}
|
|
||||||
c.out.prepareCipherSpec(c.vers, clientCipher, clientHash)
|
|
||||||
c.writeRecord(recordTypeChangeCipherSpec, []byte{1})
|
|
||||||
|
|
||||||
if serverHello.nextProtoNeg {
|
|
||||||
nextProto := new(nextProtoMsg)
|
|
||||||
proto, fallback := mutualProtocol(c.config.NextProtos, serverHello.nextProtos)
|
|
||||||
nextProto.proto = proto
|
|
||||||
c.clientProtocol = proto
|
|
||||||
c.clientProtocolFallback = fallback
|
|
||||||
|
|
||||||
finishedHash.Write(nextProto.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, nextProto.marshal())
|
|
||||||
}
|
|
||||||
|
|
||||||
finished := new(finishedMsg)
|
|
||||||
finished.verifyData = finishedHash.clientSum(masterSecret)
|
|
||||||
finishedHash.Write(finished.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, finished.marshal())
|
|
||||||
|
|
||||||
var serverCipher interface{}
|
|
||||||
var serverHash macFunction
|
|
||||||
if suite.cipher != nil {
|
|
||||||
serverCipher = suite.cipher(serverKey, serverIV, true /* for reading */)
|
|
||||||
serverHash = suite.mac(c.vers, serverMAC)
|
|
||||||
} else {
|
|
||||||
serverCipher = suite.aead(serverKey, serverIV)
|
|
||||||
}
|
|
||||||
c.in.prepareCipherSpec(c.vers, serverCipher, serverHash)
|
|
||||||
c.readRecord(recordTypeChangeCipherSpec)
|
|
||||||
if err := c.error(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err = c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
serverFinished, ok := msg.(*finishedMsg)
|
|
||||||
if !ok {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
verify := finishedHash.serverSum(masterSecret)
|
|
||||||
if len(verify) != len(serverFinished.verifyData) ||
|
|
||||||
subtle.ConstantTimeCompare(verify, serverFinished.verifyData) != 1 {
|
|
||||||
return c.sendAlert(alertHandshakeFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.handshakeComplete = true
|
|
||||||
c.cipherSuite = suite.id
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// mutualProtocol finds the mutual Next Protocol Negotiation protocol given the
|
|
||||||
// set of client and server supported protocols. The set of client supported
|
|
||||||
// protocols must not be empty. It returns the resulting protocol and flag
|
|
||||||
// indicating if the fallback case was reached.
|
|
||||||
func mutualProtocol(clientProtos, serverProtos []string) (string, bool) {
|
|
||||||
for _, s := range serverProtos {
|
|
||||||
for _, c := range clientProtos {
|
|
||||||
if s == c {
|
|
||||||
return s, false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return clientProtos[0], true
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,638 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto"
|
|
||||||
"crypto/ecdsa"
|
|
||||||
"crypto/rsa"
|
|
||||||
"crypto/subtle"
|
|
||||||
"crypto/x509"
|
|
||||||
"encoding/asn1"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// serverHandshakeState contains details of a server handshake in progress.
|
|
||||||
// It's discarded once the handshake has completed.
|
|
||||||
type serverHandshakeState struct {
|
|
||||||
c *Conn
|
|
||||||
clientHello *clientHelloMsg
|
|
||||||
hello *serverHelloMsg
|
|
||||||
suite *cipherSuite
|
|
||||||
ellipticOk bool
|
|
||||||
ecdsaOk bool
|
|
||||||
sessionState *sessionState
|
|
||||||
finishedHash finishedHash
|
|
||||||
masterSecret []byte
|
|
||||||
certsFromClient [][]byte
|
|
||||||
cert *Certificate
|
|
||||||
}
|
|
||||||
|
|
||||||
// serverHandshake performs a TLS handshake as a server.
|
|
||||||
func (c *Conn) serverHandshake() error {
|
|
||||||
config := c.config
|
|
||||||
|
|
||||||
// If this is the first server handshake, we generate a random key to
|
|
||||||
// encrypt the tickets with.
|
|
||||||
config.serverInitOnce.Do(config.serverInit)
|
|
||||||
|
|
||||||
hs := serverHandshakeState{
|
|
||||||
c: c,
|
|
||||||
}
|
|
||||||
isResume, err := hs.readClientHello()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// For an overview of TLS handshaking, see https://tools.ietf.org/html/rfc5246#section-7.3
|
|
||||||
if isResume {
|
|
||||||
// The client has included a session ticket and so we do an abbreviated handshake.
|
|
||||||
if err := hs.doResumeHandshake(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := hs.establishKeys(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := hs.sendFinished(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := hs.readFinished(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.didResume = true
|
|
||||||
} else {
|
|
||||||
// The client didn't include a session ticket, or it wasn't
|
|
||||||
// valid so we do a full handshake.
|
|
||||||
if err := hs.doFullHandshake(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := hs.establishKeys(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := hs.readFinished(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := hs.sendSessionTicket(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := hs.sendFinished(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.handshakeComplete = true
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// readClientHello reads a ClientHello message from the client and decides
|
|
||||||
// whether we will perform session resumption.
|
|
||||||
func (hs *serverHandshakeState) readClientHello() (isResume bool, err error) {
|
|
||||||
config := hs.c.config
|
|
||||||
c := hs.c
|
|
||||||
|
|
||||||
msg, err := c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
var ok bool
|
|
||||||
hs.clientHello, ok = msg.(*clientHelloMsg)
|
|
||||||
if !ok {
|
|
||||||
return false, c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
c.vers, ok = config.mutualVersion(hs.clientHello.vers)
|
|
||||||
if !ok {
|
|
||||||
return false, c.sendAlert(alertProtocolVersion)
|
|
||||||
}
|
|
||||||
c.haveVers = true
|
|
||||||
|
|
||||||
hs.finishedHash = newFinishedHash(c.vers)
|
|
||||||
hs.finishedHash.Write(hs.clientHello.marshal())
|
|
||||||
|
|
||||||
hs.hello = new(serverHelloMsg)
|
|
||||||
|
|
||||||
supportedCurve := false
|
|
||||||
Curves:
|
|
||||||
for _, curve := range hs.clientHello.supportedCurves {
|
|
||||||
switch curve {
|
|
||||||
case curveP256, curveP384, curveP521:
|
|
||||||
supportedCurve = true
|
|
||||||
break Curves
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
supportedPointFormat := false
|
|
||||||
for _, pointFormat := range hs.clientHello.supportedPoints {
|
|
||||||
if pointFormat == pointFormatUncompressed {
|
|
||||||
supportedPointFormat = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hs.ellipticOk = supportedCurve && supportedPointFormat
|
|
||||||
|
|
||||||
foundCompression := false
|
|
||||||
// We only support null compression, so check that the client offered it.
|
|
||||||
for _, compression := range hs.clientHello.compressionMethods {
|
|
||||||
if compression == compressionNone {
|
|
||||||
foundCompression = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !foundCompression {
|
|
||||||
return false, c.sendAlert(alertHandshakeFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
hs.hello.vers = c.vers
|
|
||||||
t := uint32(config.time().Unix())
|
|
||||||
hs.hello.random = make([]byte, 32)
|
|
||||||
hs.hello.random[0] = byte(t >> 24)
|
|
||||||
hs.hello.random[1] = byte(t >> 16)
|
|
||||||
hs.hello.random[2] = byte(t >> 8)
|
|
||||||
hs.hello.random[3] = byte(t)
|
|
||||||
_, err = io.ReadFull(config.rand(), hs.hello.random[4:])
|
|
||||||
if err != nil {
|
|
||||||
return false, c.sendAlert(alertInternalError)
|
|
||||||
}
|
|
||||||
hs.hello.compressionMethod = compressionNone
|
|
||||||
if len(hs.clientHello.serverName) > 0 {
|
|
||||||
c.serverName = hs.clientHello.serverName
|
|
||||||
}
|
|
||||||
// Although sending an empty NPN extension is reasonable, Firefox has
|
|
||||||
// had a bug around this. Best to send nothing at all if
|
|
||||||
// config.NextProtos is empty. See
|
|
||||||
// https://code.google.com/p/go/issues/detail?id=5445.
|
|
||||||
if hs.clientHello.nextProtoNeg && len(config.NextProtos) > 0 {
|
|
||||||
hs.hello.nextProtoNeg = true
|
|
||||||
hs.hello.nextProtos = config.NextProtos
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(config.Certificates) == 0 {
|
|
||||||
return false, c.sendAlert(alertInternalError)
|
|
||||||
}
|
|
||||||
hs.cert = &config.Certificates[0]
|
|
||||||
if len(hs.clientHello.serverName) > 0 {
|
|
||||||
hs.cert = config.getCertificateForName(hs.clientHello.serverName)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, hs.ecdsaOk = hs.cert.PrivateKey.(*ecdsa.PrivateKey)
|
|
||||||
|
|
||||||
if hs.checkForResumption() {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var preferenceList, supportedList []uint16
|
|
||||||
if c.config.PreferServerCipherSuites {
|
|
||||||
preferenceList = c.config.cipherSuites()
|
|
||||||
supportedList = hs.clientHello.cipherSuites
|
|
||||||
} else {
|
|
||||||
preferenceList = hs.clientHello.cipherSuites
|
|
||||||
supportedList = c.config.cipherSuites()
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, id := range preferenceList {
|
|
||||||
if hs.suite = c.tryCipherSuite(id, supportedList, c.vers, hs.ellipticOk, hs.ecdsaOk); hs.suite != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if hs.suite == nil {
|
|
||||||
return false, c.sendAlert(alertHandshakeFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkForResumption returns true if we should perform resumption on this connection.
|
|
||||||
func (hs *serverHandshakeState) checkForResumption() bool {
|
|
||||||
c := hs.c
|
|
||||||
|
|
||||||
var ok bool
|
|
||||||
if hs.sessionState, ok = c.decryptTicket(hs.clientHello.sessionTicket); !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if hs.sessionState.vers > hs.clientHello.vers {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if vers, ok := c.config.mutualVersion(hs.sessionState.vers); !ok || vers != hs.sessionState.vers {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
cipherSuiteOk := false
|
|
||||||
// Check that the client is still offering the ciphersuite in the session.
|
|
||||||
for _, id := range hs.clientHello.cipherSuites {
|
|
||||||
if id == hs.sessionState.cipherSuite {
|
|
||||||
cipherSuiteOk = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !cipherSuiteOk {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that we also support the ciphersuite from the session.
|
|
||||||
hs.suite = c.tryCipherSuite(hs.sessionState.cipherSuite, c.config.cipherSuites(), hs.sessionState.vers, hs.ellipticOk, hs.ecdsaOk)
|
|
||||||
if hs.suite == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionHasClientCerts := len(hs.sessionState.certificates) != 0
|
|
||||||
needClientCerts := c.config.ClientAuth == RequireAnyClientCert || c.config.ClientAuth == RequireAndVerifyClientCert
|
|
||||||
if needClientCerts && !sessionHasClientCerts {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if sessionHasClientCerts && c.config.ClientAuth == NoClientCert {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hs *serverHandshakeState) doResumeHandshake() error {
|
|
||||||
c := hs.c
|
|
||||||
|
|
||||||
hs.hello.cipherSuite = hs.suite.id
|
|
||||||
// We echo the client's session ID in the ServerHello to let it know
|
|
||||||
// that we're doing a resumption.
|
|
||||||
hs.hello.sessionId = hs.clientHello.sessionId
|
|
||||||
hs.finishedHash.Write(hs.hello.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, hs.hello.marshal())
|
|
||||||
|
|
||||||
if len(hs.sessionState.certificates) > 0 {
|
|
||||||
if _, err := hs.processCertsFromClient(hs.sessionState.certificates); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hs.masterSecret = hs.sessionState.masterSecret
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hs *serverHandshakeState) doFullHandshake() error {
|
|
||||||
config := hs.c.config
|
|
||||||
c := hs.c
|
|
||||||
|
|
||||||
if hs.clientHello.ocspStapling && len(hs.cert.OCSPStaple) > 0 {
|
|
||||||
hs.hello.ocspStapling = true
|
|
||||||
}
|
|
||||||
|
|
||||||
hs.hello.ticketSupported = hs.clientHello.ticketSupported && !config.SessionTicketsDisabled
|
|
||||||
hs.hello.cipherSuite = hs.suite.id
|
|
||||||
hs.finishedHash.Write(hs.hello.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, hs.hello.marshal())
|
|
||||||
|
|
||||||
certMsg := new(certificateMsg)
|
|
||||||
certMsg.certificates = hs.cert.Certificate
|
|
||||||
hs.finishedHash.Write(certMsg.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, certMsg.marshal())
|
|
||||||
|
|
||||||
if hs.hello.ocspStapling {
|
|
||||||
certStatus := new(certificateStatusMsg)
|
|
||||||
certStatus.statusType = statusTypeOCSP
|
|
||||||
certStatus.response = hs.cert.OCSPStaple
|
|
||||||
hs.finishedHash.Write(certStatus.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, certStatus.marshal())
|
|
||||||
}
|
|
||||||
|
|
||||||
keyAgreement := hs.suite.ka(c.vers)
|
|
||||||
skx, err := keyAgreement.generateServerKeyExchange(config, hs.cert, hs.clientHello, hs.hello)
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertHandshakeFailure)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if skx != nil {
|
|
||||||
hs.finishedHash.Write(skx.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, skx.marshal())
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.ClientAuth >= RequestClientCert {
|
|
||||||
// Request a client certificate
|
|
||||||
certReq := new(certificateRequestMsg)
|
|
||||||
certReq.certificateTypes = []byte{
|
|
||||||
byte(certTypeRSASign),
|
|
||||||
byte(certTypeECDSASign),
|
|
||||||
}
|
|
||||||
if c.vers >= VersionTLS12 {
|
|
||||||
certReq.hasSignatureAndHash = true
|
|
||||||
certReq.signatureAndHashes = supportedClientCertSignatureAlgorithms
|
|
||||||
}
|
|
||||||
|
|
||||||
// An empty list of certificateAuthorities signals to
|
|
||||||
// the client that it may send any certificate in response
|
|
||||||
// to our request. When we know the CAs we trust, then
|
|
||||||
// we can send them down, so that the client can choose
|
|
||||||
// an appropriate certificate to give to us.
|
|
||||||
if config.ClientCAs != nil {
|
|
||||||
certReq.certificateAuthorities = config.ClientCAs.Subjects()
|
|
||||||
}
|
|
||||||
hs.finishedHash.Write(certReq.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, certReq.marshal())
|
|
||||||
}
|
|
||||||
|
|
||||||
helloDone := new(serverHelloDoneMsg)
|
|
||||||
hs.finishedHash.Write(helloDone.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, helloDone.marshal())
|
|
||||||
|
|
||||||
var pub crypto.PublicKey // public key for client auth, if any
|
|
||||||
|
|
||||||
msg, err := c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var ok bool
|
|
||||||
// If we requested a client certificate, then the client must send a
|
|
||||||
// certificate message, even if it's empty.
|
|
||||||
if config.ClientAuth >= RequestClientCert {
|
|
||||||
if certMsg, ok = msg.(*certificateMsg); !ok {
|
|
||||||
return c.sendAlert(alertHandshakeFailure)
|
|
||||||
}
|
|
||||||
hs.finishedHash.Write(certMsg.marshal())
|
|
||||||
|
|
||||||
if len(certMsg.certificates) == 0 {
|
|
||||||
// The client didn't actually send a certificate
|
|
||||||
switch config.ClientAuth {
|
|
||||||
case RequireAnyClientCert, RequireAndVerifyClientCert:
|
|
||||||
c.sendAlert(alertBadCertificate)
|
|
||||||
return errors.New("tls: client didn't provide a certificate")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub, err = hs.processCertsFromClient(certMsg.certificates)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err = c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get client key exchange
|
|
||||||
ckx, ok := msg.(*clientKeyExchangeMsg)
|
|
||||||
if !ok {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
hs.finishedHash.Write(ckx.marshal())
|
|
||||||
|
|
||||||
// If we received a client cert in response to our certificate request message,
|
|
||||||
// the client will send us a certificateVerifyMsg immediately after the
|
|
||||||
// clientKeyExchangeMsg. This message is a digest of all preceding
|
|
||||||
// handshake-layer messages that is signed using the private key corresponding
|
|
||||||
// to the client's certificate. This allows us to verify that the client is in
|
|
||||||
// possession of the private key of the certificate.
|
|
||||||
if len(c.peerCertificates) > 0 {
|
|
||||||
msg, err = c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
certVerify, ok := msg.(*certificateVerifyMsg)
|
|
||||||
if !ok {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch key := pub.(type) {
|
|
||||||
case *ecdsa.PublicKey:
|
|
||||||
ecdsaSig := new(ecdsaSignature)
|
|
||||||
if _, err = asn1.Unmarshal(certVerify.signature, ecdsaSig); err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if ecdsaSig.R.Sign() <= 0 || ecdsaSig.S.Sign() <= 0 {
|
|
||||||
err = errors.New("ECDSA signature contained zero or negative values")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
digest, _, _ := hs.finishedHash.hashForClientCertificate(signatureECDSA)
|
|
||||||
if !ecdsa.Verify(key, digest, ecdsaSig.R, ecdsaSig.S) {
|
|
||||||
err = errors.New("ECDSA verification failure")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case *rsa.PublicKey:
|
|
||||||
digest, hashFunc, _ := hs.finishedHash.hashForClientCertificate(signatureRSA)
|
|
||||||
err = rsa.VerifyPKCS1v15(key, hashFunc, digest, certVerify.signature)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertBadCertificate)
|
|
||||||
return errors.New("could not validate signature of connection nonces: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
hs.finishedHash.Write(certVerify.marshal())
|
|
||||||
}
|
|
||||||
|
|
||||||
preMasterSecret, err := keyAgreement.processClientKeyExchange(config, hs.cert, ckx, c.vers)
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertHandshakeFailure)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
hs.masterSecret = masterFromPreMasterSecret(c.vers, preMasterSecret, hs.clientHello.random, hs.hello.random)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hs *serverHandshakeState) establishKeys() error {
|
|
||||||
c := hs.c
|
|
||||||
|
|
||||||
clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
|
|
||||||
keysFromMasterSecret(c.vers, hs.masterSecret, hs.clientHello.random, hs.hello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen)
|
|
||||||
|
|
||||||
var clientCipher, serverCipher interface{}
|
|
||||||
var clientHash, serverHash macFunction
|
|
||||||
|
|
||||||
if hs.suite.aead == nil {
|
|
||||||
clientCipher = hs.suite.cipher(clientKey, clientIV, true /* for reading */)
|
|
||||||
clientHash = hs.suite.mac(c.vers, clientMAC)
|
|
||||||
serverCipher = hs.suite.cipher(serverKey, serverIV, false /* not for reading */)
|
|
||||||
serverHash = hs.suite.mac(c.vers, serverMAC)
|
|
||||||
} else {
|
|
||||||
clientCipher = hs.suite.aead(clientKey, clientIV)
|
|
||||||
serverCipher = hs.suite.aead(serverKey, serverIV)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.in.prepareCipherSpec(c.vers, clientCipher, clientHash)
|
|
||||||
c.out.prepareCipherSpec(c.vers, serverCipher, serverHash)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hs *serverHandshakeState) readFinished() error {
|
|
||||||
c := hs.c
|
|
||||||
|
|
||||||
c.readRecord(recordTypeChangeCipherSpec)
|
|
||||||
if err := c.error(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if hs.hello.nextProtoNeg {
|
|
||||||
msg, err := c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nextProto, ok := msg.(*nextProtoMsg)
|
|
||||||
if !ok {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
hs.finishedHash.Write(nextProto.marshal())
|
|
||||||
c.clientProtocol = nextProto.proto
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := c.readHandshake()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
clientFinished, ok := msg.(*finishedMsg)
|
|
||||||
if !ok {
|
|
||||||
return c.sendAlert(alertUnexpectedMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
verify := hs.finishedHash.clientSum(hs.masterSecret)
|
|
||||||
if len(verify) != len(clientFinished.verifyData) ||
|
|
||||||
subtle.ConstantTimeCompare(verify, clientFinished.verifyData) != 1 {
|
|
||||||
return c.sendAlert(alertHandshakeFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
hs.finishedHash.Write(clientFinished.marshal())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hs *serverHandshakeState) sendSessionTicket() error {
|
|
||||||
if !hs.hello.ticketSupported {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
c := hs.c
|
|
||||||
m := new(newSessionTicketMsg)
|
|
||||||
|
|
||||||
var err error
|
|
||||||
state := sessionState{
|
|
||||||
vers: c.vers,
|
|
||||||
cipherSuite: hs.suite.id,
|
|
||||||
masterSecret: hs.masterSecret,
|
|
||||||
certificates: hs.certsFromClient,
|
|
||||||
}
|
|
||||||
m.ticket, err = c.encryptTicket(&state)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
hs.finishedHash.Write(m.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, m.marshal())
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hs *serverHandshakeState) sendFinished() error {
|
|
||||||
c := hs.c
|
|
||||||
|
|
||||||
c.writeRecord(recordTypeChangeCipherSpec, []byte{1})
|
|
||||||
|
|
||||||
finished := new(finishedMsg)
|
|
||||||
finished.verifyData = hs.finishedHash.serverSum(hs.masterSecret)
|
|
||||||
hs.finishedHash.Write(finished.marshal())
|
|
||||||
c.writeRecord(recordTypeHandshake, finished.marshal())
|
|
||||||
|
|
||||||
c.cipherSuite = hs.suite.id
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// processCertsFromClient takes a chain of client certificates either from a
|
|
||||||
// Certificates message or from a sessionState and verifies them. It returns
|
|
||||||
// the public key of the leaf certificate.
|
|
||||||
func (hs *serverHandshakeState) processCertsFromClient(certificates [][]byte) (crypto.PublicKey, error) {
|
|
||||||
c := hs.c
|
|
||||||
|
|
||||||
hs.certsFromClient = certificates
|
|
||||||
certs := make([]*x509.Certificate, len(certificates))
|
|
||||||
var err error
|
|
||||||
for i, asn1Data := range certificates {
|
|
||||||
if certs[i], err = x509.ParseCertificate(asn1Data); err != nil {
|
|
||||||
c.sendAlert(alertBadCertificate)
|
|
||||||
return nil, errors.New("tls: failed to parse client certificate: " + err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.config.ClientAuth >= VerifyClientCertIfGiven && len(certs) > 0 {
|
|
||||||
opts := x509.VerifyOptions{
|
|
||||||
Roots: c.config.ClientCAs,
|
|
||||||
CurrentTime: c.config.time(),
|
|
||||||
Intermediates: x509.NewCertPool(),
|
|
||||||
KeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, cert := range certs[1:] {
|
|
||||||
opts.Intermediates.AddCert(cert)
|
|
||||||
}
|
|
||||||
|
|
||||||
chains, err := certs[0].Verify(opts)
|
|
||||||
if err != nil {
|
|
||||||
c.sendAlert(alertBadCertificate)
|
|
||||||
return nil, errors.New("tls: failed to verify client's certificate: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
ok := false
|
|
||||||
for _, ku := range certs[0].ExtKeyUsage {
|
|
||||||
if ku == x509.ExtKeyUsageClientAuth {
|
|
||||||
ok = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
c.sendAlert(alertHandshakeFailure)
|
|
||||||
return nil, errors.New("tls: client's certificate's extended key usage doesn't permit it to be used for client authentication")
|
|
||||||
}
|
|
||||||
|
|
||||||
c.verifiedChains = chains
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(certs) > 0 {
|
|
||||||
var pub crypto.PublicKey
|
|
||||||
switch key := certs[0].PublicKey.(type) {
|
|
||||||
case *ecdsa.PublicKey, *rsa.PublicKey:
|
|
||||||
pub = key
|
|
||||||
default:
|
|
||||||
return nil, c.sendAlert(alertUnsupportedCertificate)
|
|
||||||
}
|
|
||||||
c.peerCertificates = certs
|
|
||||||
return pub, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// tryCipherSuite returns a cipherSuite with the given id if that cipher suite
|
|
||||||
// is acceptable to use.
|
|
||||||
func (c *Conn) tryCipherSuite(id uint16, supportedCipherSuites []uint16, version uint16, ellipticOk, ecdsaOk bool) *cipherSuite {
|
|
||||||
for _, supported := range supportedCipherSuites {
|
|
||||||
if id == supported {
|
|
||||||
var candidate *cipherSuite
|
|
||||||
|
|
||||||
for _, s := range cipherSuites {
|
|
||||||
if s.id == id {
|
|
||||||
candidate = s
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if candidate == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Don't select a ciphersuite which we can't
|
|
||||||
// support for this client.
|
|
||||||
if (candidate.flags&suiteECDHE != 0) && !ellipticOk {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (candidate.flags&suiteECDSA != 0) != ecdsaOk {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if version < VersionTLS12 && candidate.flags&suiteTLS12 != 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return candidate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,400 +0,0 @@
|
||||||
// Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto"
|
|
||||||
"crypto/ecdsa"
|
|
||||||
"crypto/elliptic"
|
|
||||||
"crypto/md5"
|
|
||||||
"crypto/rsa"
|
|
||||||
"crypto/sha1"
|
|
||||||
"crypto/sha256"
|
|
||||||
"crypto/x509"
|
|
||||||
"encoding/asn1"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"math/big"
|
|
||||||
)
|
|
||||||
|
|
||||||
// rsaKeyAgreement implements the standard TLS key agreement where the client
|
|
||||||
// encrypts the pre-master secret to the server's public key.
|
|
||||||
type rsaKeyAgreement struct{}
|
|
||||||
|
|
||||||
func (ka rsaKeyAgreement) generateServerKeyExchange(config *Config, cert *Certificate, clientHello *clientHelloMsg, hello *serverHelloMsg) (*serverKeyExchangeMsg, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ka rsaKeyAgreement) processClientKeyExchange(config *Config, cert *Certificate, ckx *clientKeyExchangeMsg, version uint16) ([]byte, error) {
|
|
||||||
preMasterSecret := make([]byte, 48)
|
|
||||||
_, err := io.ReadFull(config.rand(), preMasterSecret[2:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ckx.ciphertext) < 2 {
|
|
||||||
return nil, errors.New("bad ClientKeyExchange")
|
|
||||||
}
|
|
||||||
|
|
||||||
ciphertext := ckx.ciphertext
|
|
||||||
if version != VersionSSL30 {
|
|
||||||
ciphertextLen := int(ckx.ciphertext[0])<<8 | int(ckx.ciphertext[1])
|
|
||||||
if ciphertextLen != len(ckx.ciphertext)-2 {
|
|
||||||
return nil, errors.New("bad ClientKeyExchange")
|
|
||||||
}
|
|
||||||
ciphertext = ckx.ciphertext[2:]
|
|
||||||
}
|
|
||||||
|
|
||||||
err = rsa.DecryptPKCS1v15SessionKey(config.rand(), cert.PrivateKey.(*rsa.PrivateKey), ciphertext, preMasterSecret)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// We don't check the version number in the premaster secret. For one,
|
|
||||||
// by checking it, we would leak information about the validity of the
|
|
||||||
// encrypted pre-master secret. Secondly, it provides only a small
|
|
||||||
// benefit against a downgrade attack and some implementations send the
|
|
||||||
// wrong version anyway. See the discussion at the end of section
|
|
||||||
// 7.4.7.1 of RFC 4346.
|
|
||||||
return preMasterSecret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ka rsaKeyAgreement) processServerKeyExchange(config *Config, clientHello *clientHelloMsg, serverHello *serverHelloMsg, cert *x509.Certificate, skx *serverKeyExchangeMsg) error {
|
|
||||||
return errors.New("unexpected ServerKeyExchange")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ka rsaKeyAgreement) generateClientKeyExchange(config *Config, clientHello *clientHelloMsg, cert *x509.Certificate) ([]byte, *clientKeyExchangeMsg, error) {
|
|
||||||
preMasterSecret := make([]byte, 48)
|
|
||||||
preMasterSecret[0] = byte(clientHello.vers >> 8)
|
|
||||||
preMasterSecret[1] = byte(clientHello.vers)
|
|
||||||
_, err := io.ReadFull(config.rand(), preMasterSecret[2:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
encrypted, err := rsa.EncryptPKCS1v15(config.rand(), cert.PublicKey.(*rsa.PublicKey), preMasterSecret)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
ckx := new(clientKeyExchangeMsg)
|
|
||||||
ckx.ciphertext = make([]byte, len(encrypted)+2)
|
|
||||||
ckx.ciphertext[0] = byte(len(encrypted) >> 8)
|
|
||||||
ckx.ciphertext[1] = byte(len(encrypted))
|
|
||||||
copy(ckx.ciphertext[2:], encrypted)
|
|
||||||
return preMasterSecret, ckx, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// sha1Hash calculates a SHA1 hash over the given byte slices.
|
|
||||||
func sha1Hash(slices [][]byte) []byte {
|
|
||||||
hsha1 := sha1.New()
|
|
||||||
for _, slice := range slices {
|
|
||||||
hsha1.Write(slice)
|
|
||||||
}
|
|
||||||
return hsha1.Sum(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// md5SHA1Hash implements TLS 1.0's hybrid hash function which consists of the
|
|
||||||
// concatenation of an MD5 and SHA1 hash.
|
|
||||||
func md5SHA1Hash(slices [][]byte) []byte {
|
|
||||||
md5sha1 := make([]byte, md5.Size+sha1.Size)
|
|
||||||
hmd5 := md5.New()
|
|
||||||
for _, slice := range slices {
|
|
||||||
hmd5.Write(slice)
|
|
||||||
}
|
|
||||||
copy(md5sha1, hmd5.Sum(nil))
|
|
||||||
copy(md5sha1[md5.Size:], sha1Hash(slices))
|
|
||||||
return md5sha1
|
|
||||||
}
|
|
||||||
|
|
||||||
// sha256Hash implements TLS 1.2's hash function.
|
|
||||||
func sha256Hash(slices [][]byte) []byte {
|
|
||||||
h := sha256.New()
|
|
||||||
for _, slice := range slices {
|
|
||||||
h.Write(slice)
|
|
||||||
}
|
|
||||||
return h.Sum(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// hashForServerKeyExchange hashes the given slices and returns their digest
|
|
||||||
// and the identifier of the hash function used. The hashFunc argument is only
|
|
||||||
// used for >= TLS 1.2 and precisely identifies the hash function to use.
|
|
||||||
func hashForServerKeyExchange(sigType, hashFunc uint8, version uint16, slices ...[]byte) ([]byte, crypto.Hash, error) {
|
|
||||||
if version >= VersionTLS12 {
|
|
||||||
switch hashFunc {
|
|
||||||
case hashSHA256:
|
|
||||||
return sha256Hash(slices), crypto.SHA256, nil
|
|
||||||
case hashSHA1:
|
|
||||||
return sha1Hash(slices), crypto.SHA1, nil
|
|
||||||
default:
|
|
||||||
return nil, crypto.Hash(0), errors.New("tls: unknown hash function used by peer")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if sigType == signatureECDSA {
|
|
||||||
return sha1Hash(slices), crypto.SHA1, nil
|
|
||||||
}
|
|
||||||
return md5SHA1Hash(slices), crypto.MD5SHA1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// pickTLS12HashForSignature returns a TLS 1.2 hash identifier for signing a
|
|
||||||
// ServerKeyExchange given the signature type being used and the client's
|
|
||||||
// advertized list of supported signature and hash combinations.
|
|
||||||
func pickTLS12HashForSignature(sigType uint8, clientSignatureAndHashes []signatureAndHash) (uint8, error) {
|
|
||||||
if len(clientSignatureAndHashes) == 0 {
|
|
||||||
// If the client didn't specify any signature_algorithms
|
|
||||||
// extension then we can assume that it supports SHA1. See
|
|
||||||
// http://tools.ietf.org/html/rfc5246#section-7.4.1.4.1
|
|
||||||
return hashSHA1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, sigAndHash := range clientSignatureAndHashes {
|
|
||||||
if sigAndHash.signature != sigType {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch sigAndHash.hash {
|
|
||||||
case hashSHA1, hashSHA256:
|
|
||||||
return sigAndHash.hash, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0, errors.New("tls: client doesn't support any common hash functions")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ecdheRSAKeyAgreement implements a TLS key agreement where the server
|
|
||||||
// generates a ephemeral EC public/private key pair and signs it. The
|
|
||||||
// pre-master secret is then calculated using ECDH. The signature may
|
|
||||||
// either be ECDSA or RSA.
|
|
||||||
type ecdheKeyAgreement struct {
|
|
||||||
version uint16
|
|
||||||
sigType uint8
|
|
||||||
privateKey []byte
|
|
||||||
curve elliptic.Curve
|
|
||||||
x, y *big.Int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ka *ecdheKeyAgreement) generateServerKeyExchange(config *Config, cert *Certificate, clientHello *clientHelloMsg, hello *serverHelloMsg) (*serverKeyExchangeMsg, error) {
|
|
||||||
var curveid uint16
|
|
||||||
|
|
||||||
Curve:
|
|
||||||
for _, c := range clientHello.supportedCurves {
|
|
||||||
switch c {
|
|
||||||
case curveP256:
|
|
||||||
ka.curve = elliptic.P256()
|
|
||||||
curveid = c
|
|
||||||
break Curve
|
|
||||||
case curveP384:
|
|
||||||
ka.curve = elliptic.P384()
|
|
||||||
curveid = c
|
|
||||||
break Curve
|
|
||||||
case curveP521:
|
|
||||||
ka.curve = elliptic.P521()
|
|
||||||
curveid = c
|
|
||||||
break Curve
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if curveid == 0 {
|
|
||||||
return nil, errors.New("tls: no supported elliptic curves offered")
|
|
||||||
}
|
|
||||||
|
|
||||||
var x, y *big.Int
|
|
||||||
var err error
|
|
||||||
ka.privateKey, x, y, err = elliptic.GenerateKey(ka.curve, config.rand())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ecdhePublic := elliptic.Marshal(ka.curve, x, y)
|
|
||||||
|
|
||||||
// http://tools.ietf.org/html/rfc4492#section-5.4
|
|
||||||
serverECDHParams := make([]byte, 1+2+1+len(ecdhePublic))
|
|
||||||
serverECDHParams[0] = 3 // named curve
|
|
||||||
serverECDHParams[1] = byte(curveid >> 8)
|
|
||||||
serverECDHParams[2] = byte(curveid)
|
|
||||||
serverECDHParams[3] = byte(len(ecdhePublic))
|
|
||||||
copy(serverECDHParams[4:], ecdhePublic)
|
|
||||||
|
|
||||||
var tls12HashId uint8
|
|
||||||
if ka.version >= VersionTLS12 {
|
|
||||||
if tls12HashId, err = pickTLS12HashForSignature(ka.sigType, clientHello.signatureAndHashes); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
digest, hashFunc, err := hashForServerKeyExchange(ka.sigType, tls12HashId, ka.version, clientHello.random, hello.random, serverECDHParams)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var sig []byte
|
|
||||||
switch ka.sigType {
|
|
||||||
case signatureECDSA:
|
|
||||||
privKey, ok := cert.PrivateKey.(*ecdsa.PrivateKey)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("ECDHE ECDSA requires an ECDSA server private key")
|
|
||||||
}
|
|
||||||
r, s, err := ecdsa.Sign(config.rand(), privKey, digest)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("failed to sign ECDHE parameters: " + err.Error())
|
|
||||||
}
|
|
||||||
sig, err = asn1.Marshal(ecdsaSignature{r, s})
|
|
||||||
case signatureRSA:
|
|
||||||
privKey, ok := cert.PrivateKey.(*rsa.PrivateKey)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("ECDHE RSA requires a RSA server private key")
|
|
||||||
}
|
|
||||||
sig, err = rsa.SignPKCS1v15(config.rand(), privKey, hashFunc, digest)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("failed to sign ECDHE parameters: " + err.Error())
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return nil, errors.New("unknown ECDHE signature algorithm")
|
|
||||||
}
|
|
||||||
|
|
||||||
skx := new(serverKeyExchangeMsg)
|
|
||||||
sigAndHashLen := 0
|
|
||||||
if ka.version >= VersionTLS12 {
|
|
||||||
sigAndHashLen = 2
|
|
||||||
}
|
|
||||||
skx.key = make([]byte, len(serverECDHParams)+sigAndHashLen+2+len(sig))
|
|
||||||
copy(skx.key, serverECDHParams)
|
|
||||||
k := skx.key[len(serverECDHParams):]
|
|
||||||
if ka.version >= VersionTLS12 {
|
|
||||||
k[0] = tls12HashId
|
|
||||||
k[1] = ka.sigType
|
|
||||||
k = k[2:]
|
|
||||||
}
|
|
||||||
k[0] = byte(len(sig) >> 8)
|
|
||||||
k[1] = byte(len(sig))
|
|
||||||
copy(k[2:], sig)
|
|
||||||
|
|
||||||
return skx, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ka *ecdheKeyAgreement) processClientKeyExchange(config *Config, cert *Certificate, ckx *clientKeyExchangeMsg, version uint16) ([]byte, error) {
|
|
||||||
if len(ckx.ciphertext) == 0 || int(ckx.ciphertext[0]) != len(ckx.ciphertext)-1 {
|
|
||||||
return nil, errors.New("bad ClientKeyExchange")
|
|
||||||
}
|
|
||||||
x, y := elliptic.Unmarshal(ka.curve, ckx.ciphertext[1:])
|
|
||||||
if x == nil {
|
|
||||||
return nil, errors.New("bad ClientKeyExchange")
|
|
||||||
}
|
|
||||||
x, _ = ka.curve.ScalarMult(x, y, ka.privateKey)
|
|
||||||
preMasterSecret := make([]byte, (ka.curve.Params().BitSize+7)>>3)
|
|
||||||
xBytes := x.Bytes()
|
|
||||||
copy(preMasterSecret[len(preMasterSecret)-len(xBytes):], xBytes)
|
|
||||||
|
|
||||||
return preMasterSecret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var errServerKeyExchange = errors.New("invalid ServerKeyExchange")
|
|
||||||
|
|
||||||
func (ka *ecdheKeyAgreement) processServerKeyExchange(config *Config, clientHello *clientHelloMsg, serverHello *serverHelloMsg, cert *x509.Certificate, skx *serverKeyExchangeMsg) error {
|
|
||||||
if len(skx.key) < 4 {
|
|
||||||
return errServerKeyExchange
|
|
||||||
}
|
|
||||||
if skx.key[0] != 3 { // named curve
|
|
||||||
return errors.New("server selected unsupported curve")
|
|
||||||
}
|
|
||||||
curveid := uint16(skx.key[1])<<8 | uint16(skx.key[2])
|
|
||||||
|
|
||||||
switch curveid {
|
|
||||||
case curveP256:
|
|
||||||
ka.curve = elliptic.P256()
|
|
||||||
case curveP384:
|
|
||||||
ka.curve = elliptic.P384()
|
|
||||||
case curveP521:
|
|
||||||
ka.curve = elliptic.P521()
|
|
||||||
default:
|
|
||||||
return errors.New("server selected unsupported curve")
|
|
||||||
}
|
|
||||||
|
|
||||||
publicLen := int(skx.key[3])
|
|
||||||
if publicLen+4 > len(skx.key) {
|
|
||||||
return errServerKeyExchange
|
|
||||||
}
|
|
||||||
ka.x, ka.y = elliptic.Unmarshal(ka.curve, skx.key[4:4+publicLen])
|
|
||||||
if ka.x == nil {
|
|
||||||
return errServerKeyExchange
|
|
||||||
}
|
|
||||||
serverECDHParams := skx.key[:4+publicLen]
|
|
||||||
|
|
||||||
sig := skx.key[4+publicLen:]
|
|
||||||
if len(sig) < 2 {
|
|
||||||
return errServerKeyExchange
|
|
||||||
}
|
|
||||||
|
|
||||||
var tls12HashId uint8
|
|
||||||
if ka.version >= VersionTLS12 {
|
|
||||||
// handle SignatureAndHashAlgorithm
|
|
||||||
var sigAndHash []uint8
|
|
||||||
sigAndHash, sig = sig[:2], sig[2:]
|
|
||||||
if sigAndHash[1] != ka.sigType {
|
|
||||||
return errServerKeyExchange
|
|
||||||
}
|
|
||||||
tls12HashId = sigAndHash[0]
|
|
||||||
if len(sig) < 2 {
|
|
||||||
return errServerKeyExchange
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sigLen := int(sig[0])<<8 | int(sig[1])
|
|
||||||
if sigLen+2 != len(sig) {
|
|
||||||
return errServerKeyExchange
|
|
||||||
}
|
|
||||||
sig = sig[2:]
|
|
||||||
|
|
||||||
digest, hashFunc, err := hashForServerKeyExchange(ka.sigType, tls12HashId, ka.version, clientHello.random, serverHello.random, serverECDHParams)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch ka.sigType {
|
|
||||||
case signatureECDSA:
|
|
||||||
pubKey, ok := cert.PublicKey.(*ecdsa.PublicKey)
|
|
||||||
if !ok {
|
|
||||||
return errors.New("ECDHE ECDSA requires a ECDSA server public key")
|
|
||||||
}
|
|
||||||
ecdsaSig := new(ecdsaSignature)
|
|
||||||
if _, err := asn1.Unmarshal(sig, ecdsaSig); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if ecdsaSig.R.Sign() <= 0 || ecdsaSig.S.Sign() <= 0 {
|
|
||||||
return errors.New("ECDSA signature contained zero or negative values")
|
|
||||||
}
|
|
||||||
if !ecdsa.Verify(pubKey, digest, ecdsaSig.R, ecdsaSig.S) {
|
|
||||||
return errors.New("ECDSA verification failure")
|
|
||||||
}
|
|
||||||
case signatureRSA:
|
|
||||||
pubKey, ok := cert.PublicKey.(*rsa.PublicKey)
|
|
||||||
if !ok {
|
|
||||||
return errors.New("ECDHE RSA requires a RSA server public key")
|
|
||||||
}
|
|
||||||
if err := rsa.VerifyPKCS1v15(pubKey, hashFunc, digest, sig); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return errors.New("unknown ECDHE signature algorithm")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ka *ecdheKeyAgreement) generateClientKeyExchange(config *Config, clientHello *clientHelloMsg, cert *x509.Certificate) ([]byte, *clientKeyExchangeMsg, error) {
|
|
||||||
if ka.curve == nil {
|
|
||||||
return nil, nil, errors.New("missing ServerKeyExchange message")
|
|
||||||
}
|
|
||||||
priv, mx, my, err := elliptic.GenerateKey(ka.curve, config.rand())
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
x, _ := ka.curve.ScalarMult(ka.x, ka.y, priv)
|
|
||||||
preMasterSecret := make([]byte, (ka.curve.Params().BitSize+7)>>3)
|
|
||||||
xBytes := x.Bytes()
|
|
||||||
copy(preMasterSecret[len(preMasterSecret)-len(xBytes):], xBytes)
|
|
||||||
|
|
||||||
serialized := elliptic.Marshal(ka.curve, mx, my)
|
|
||||||
|
|
||||||
ckx := new(clientKeyExchangeMsg)
|
|
||||||
ckx.ciphertext = make([]byte, 1+len(serialized))
|
|
||||||
ckx.ciphertext[0] = byte(len(serialized))
|
|
||||||
copy(ckx.ciphertext[1:], serialized)
|
|
||||||
|
|
||||||
return preMasterSecret, ckx, nil
|
|
||||||
}
|
|
|
@ -1,291 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto"
|
|
||||||
"crypto/hmac"
|
|
||||||
"crypto/md5"
|
|
||||||
"crypto/sha1"
|
|
||||||
"crypto/sha256"
|
|
||||||
"hash"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Split a premaster secret in two as specified in RFC 4346, section 5.
|
|
||||||
func splitPreMasterSecret(secret []byte) (s1, s2 []byte) {
|
|
||||||
s1 = secret[0 : (len(secret)+1)/2]
|
|
||||||
s2 = secret[len(secret)/2:]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// pHash implements the P_hash function, as defined in RFC 4346, section 5.
|
|
||||||
func pHash(result, secret, seed []byte, hash func() hash.Hash) {
|
|
||||||
h := hmac.New(hash, secret)
|
|
||||||
h.Write(seed)
|
|
||||||
a := h.Sum(nil)
|
|
||||||
|
|
||||||
j := 0
|
|
||||||
for j < len(result) {
|
|
||||||
h.Reset()
|
|
||||||
h.Write(a)
|
|
||||||
h.Write(seed)
|
|
||||||
b := h.Sum(nil)
|
|
||||||
todo := len(b)
|
|
||||||
if j+todo > len(result) {
|
|
||||||
todo = len(result) - j
|
|
||||||
}
|
|
||||||
copy(result[j:j+todo], b)
|
|
||||||
j += todo
|
|
||||||
|
|
||||||
h.Reset()
|
|
||||||
h.Write(a)
|
|
||||||
a = h.Sum(nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// prf10 implements the TLS 1.0 pseudo-random function, as defined in RFC 2246, section 5.
|
|
||||||
func prf10(result, secret, label, seed []byte) {
|
|
||||||
hashSHA1 := sha1.New
|
|
||||||
hashMD5 := md5.New
|
|
||||||
|
|
||||||
labelAndSeed := make([]byte, len(label)+len(seed))
|
|
||||||
copy(labelAndSeed, label)
|
|
||||||
copy(labelAndSeed[len(label):], seed)
|
|
||||||
|
|
||||||
s1, s2 := splitPreMasterSecret(secret)
|
|
||||||
pHash(result, s1, labelAndSeed, hashMD5)
|
|
||||||
result2 := make([]byte, len(result))
|
|
||||||
pHash(result2, s2, labelAndSeed, hashSHA1)
|
|
||||||
|
|
||||||
for i, b := range result2 {
|
|
||||||
result[i] ^= b
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// prf12 implements the TLS 1.2 pseudo-random function, as defined in RFC 5246, section 5.
|
|
||||||
func prf12(result, secret, label, seed []byte) {
|
|
||||||
labelAndSeed := make([]byte, len(label)+len(seed))
|
|
||||||
copy(labelAndSeed, label)
|
|
||||||
copy(labelAndSeed[len(label):], seed)
|
|
||||||
|
|
||||||
pHash(result, secret, labelAndSeed, sha256.New)
|
|
||||||
}
|
|
||||||
|
|
||||||
// prf30 implements the SSL 3.0 pseudo-random function, as defined in
|
|
||||||
// www.mozilla.org/projects/security/pki/nss/ssl/draft302.txt section 6.
|
|
||||||
func prf30(result, secret, label, seed []byte) {
|
|
||||||
hashSHA1 := sha1.New()
|
|
||||||
hashMD5 := md5.New()
|
|
||||||
|
|
||||||
done := 0
|
|
||||||
i := 0
|
|
||||||
// RFC5246 section 6.3 says that the largest PRF output needed is 128
|
|
||||||
// bytes. Since no more ciphersuites will be added to SSLv3, this will
|
|
||||||
// remain true. Each iteration gives us 16 bytes so 10 iterations will
|
|
||||||
// be sufficient.
|
|
||||||
var b [11]byte
|
|
||||||
for done < len(result) {
|
|
||||||
for j := 0; j <= i; j++ {
|
|
||||||
b[j] = 'A' + byte(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
hashSHA1.Reset()
|
|
||||||
hashSHA1.Write(b[:i+1])
|
|
||||||
hashSHA1.Write(secret)
|
|
||||||
hashSHA1.Write(seed)
|
|
||||||
digest := hashSHA1.Sum(nil)
|
|
||||||
|
|
||||||
hashMD5.Reset()
|
|
||||||
hashMD5.Write(secret)
|
|
||||||
hashMD5.Write(digest)
|
|
||||||
|
|
||||||
done += copy(result[done:], hashMD5.Sum(nil))
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
tlsRandomLength = 32 // Length of a random nonce in TLS 1.1.
|
|
||||||
masterSecretLength = 48 // Length of a master secret in TLS 1.1.
|
|
||||||
finishedVerifyLength = 12 // Length of verify_data in a Finished message.
|
|
||||||
)
|
|
||||||
|
|
||||||
var masterSecretLabel = []byte("master secret")
|
|
||||||
var keyExpansionLabel = []byte("key expansion")
|
|
||||||
var clientFinishedLabel = []byte("client finished")
|
|
||||||
var serverFinishedLabel = []byte("server finished")
|
|
||||||
|
|
||||||
func prfForVersion(version uint16) func(result, secret, label, seed []byte) {
|
|
||||||
switch version {
|
|
||||||
case VersionSSL30:
|
|
||||||
return prf30
|
|
||||||
case VersionTLS10, VersionTLS11:
|
|
||||||
return prf10
|
|
||||||
case VersionTLS12:
|
|
||||||
return prf12
|
|
||||||
default:
|
|
||||||
panic("unknown version")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// masterFromPreMasterSecret generates the master secret from the pre-master
|
|
||||||
// secret. See http://tools.ietf.org/html/rfc5246#section-8.1
|
|
||||||
func masterFromPreMasterSecret(version uint16, preMasterSecret, clientRandom, serverRandom []byte) []byte {
|
|
||||||
var seed [tlsRandomLength * 2]byte
|
|
||||||
copy(seed[0:len(clientRandom)], clientRandom)
|
|
||||||
copy(seed[len(clientRandom):], serverRandom)
|
|
||||||
masterSecret := make([]byte, masterSecretLength)
|
|
||||||
prfForVersion(version)(masterSecret, preMasterSecret, masterSecretLabel, seed[0:])
|
|
||||||
return masterSecret
|
|
||||||
}
|
|
||||||
|
|
||||||
// keysFromMasterSecret generates the connection keys from the master
|
|
||||||
// secret, given the lengths of the MAC key, cipher key and IV, as defined in
|
|
||||||
// RFC 2246, section 6.3.
|
|
||||||
func keysFromMasterSecret(version uint16, masterSecret, clientRandom, serverRandom []byte, macLen, keyLen, ivLen int) (clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV []byte) {
|
|
||||||
var seed [tlsRandomLength * 2]byte
|
|
||||||
copy(seed[0:len(clientRandom)], serverRandom)
|
|
||||||
copy(seed[len(serverRandom):], clientRandom)
|
|
||||||
|
|
||||||
n := 2*macLen + 2*keyLen + 2*ivLen
|
|
||||||
keyMaterial := make([]byte, n)
|
|
||||||
prfForVersion(version)(keyMaterial, masterSecret, keyExpansionLabel, seed[0:])
|
|
||||||
clientMAC = keyMaterial[:macLen]
|
|
||||||
keyMaterial = keyMaterial[macLen:]
|
|
||||||
serverMAC = keyMaterial[:macLen]
|
|
||||||
keyMaterial = keyMaterial[macLen:]
|
|
||||||
clientKey = keyMaterial[:keyLen]
|
|
||||||
keyMaterial = keyMaterial[keyLen:]
|
|
||||||
serverKey = keyMaterial[:keyLen]
|
|
||||||
keyMaterial = keyMaterial[keyLen:]
|
|
||||||
clientIV = keyMaterial[:ivLen]
|
|
||||||
keyMaterial = keyMaterial[ivLen:]
|
|
||||||
serverIV = keyMaterial[:ivLen]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func newFinishedHash(version uint16) finishedHash {
|
|
||||||
if version >= VersionTLS12 {
|
|
||||||
return finishedHash{sha256.New(), sha256.New(), nil, nil, version}
|
|
||||||
}
|
|
||||||
return finishedHash{sha1.New(), sha1.New(), md5.New(), md5.New(), version}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A finishedHash calculates the hash of a set of handshake messages suitable
|
|
||||||
// for including in a Finished message.
|
|
||||||
type finishedHash struct {
|
|
||||||
client hash.Hash
|
|
||||||
server hash.Hash
|
|
||||||
|
|
||||||
// Prior to TLS 1.2, an additional MD5 hash is required.
|
|
||||||
clientMD5 hash.Hash
|
|
||||||
serverMD5 hash.Hash
|
|
||||||
|
|
||||||
version uint16
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h finishedHash) Write(msg []byte) (n int, err error) {
|
|
||||||
h.client.Write(msg)
|
|
||||||
h.server.Write(msg)
|
|
||||||
|
|
||||||
if h.version < VersionTLS12 {
|
|
||||||
h.clientMD5.Write(msg)
|
|
||||||
h.serverMD5.Write(msg)
|
|
||||||
}
|
|
||||||
return len(msg), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// finishedSum30 calculates the contents of the verify_data member of a SSLv3
|
|
||||||
// Finished message given the MD5 and SHA1 hashes of a set of handshake
|
|
||||||
// messages.
|
|
||||||
func finishedSum30(md5, sha1 hash.Hash, masterSecret []byte, magic [4]byte) []byte {
|
|
||||||
md5.Write(magic[:])
|
|
||||||
md5.Write(masterSecret)
|
|
||||||
md5.Write(ssl30Pad1[:])
|
|
||||||
md5Digest := md5.Sum(nil)
|
|
||||||
|
|
||||||
md5.Reset()
|
|
||||||
md5.Write(masterSecret)
|
|
||||||
md5.Write(ssl30Pad2[:])
|
|
||||||
md5.Write(md5Digest)
|
|
||||||
md5Digest = md5.Sum(nil)
|
|
||||||
|
|
||||||
sha1.Write(magic[:])
|
|
||||||
sha1.Write(masterSecret)
|
|
||||||
sha1.Write(ssl30Pad1[:40])
|
|
||||||
sha1Digest := sha1.Sum(nil)
|
|
||||||
|
|
||||||
sha1.Reset()
|
|
||||||
sha1.Write(masterSecret)
|
|
||||||
sha1.Write(ssl30Pad2[:40])
|
|
||||||
sha1.Write(sha1Digest)
|
|
||||||
sha1Digest = sha1.Sum(nil)
|
|
||||||
|
|
||||||
ret := make([]byte, len(md5Digest)+len(sha1Digest))
|
|
||||||
copy(ret, md5Digest)
|
|
||||||
copy(ret[len(md5Digest):], sha1Digest)
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
var ssl3ClientFinishedMagic = [4]byte{0x43, 0x4c, 0x4e, 0x54}
|
|
||||||
var ssl3ServerFinishedMagic = [4]byte{0x53, 0x52, 0x56, 0x52}
|
|
||||||
|
|
||||||
// clientSum returns the contents of the verify_data member of a client's
|
|
||||||
// Finished message.
|
|
||||||
func (h finishedHash) clientSum(masterSecret []byte) []byte {
|
|
||||||
if h.version == VersionSSL30 {
|
|
||||||
return finishedSum30(h.clientMD5, h.client, masterSecret, ssl3ClientFinishedMagic)
|
|
||||||
}
|
|
||||||
|
|
||||||
out := make([]byte, finishedVerifyLength)
|
|
||||||
if h.version >= VersionTLS12 {
|
|
||||||
seed := h.client.Sum(nil)
|
|
||||||
prf12(out, masterSecret, clientFinishedLabel, seed)
|
|
||||||
} else {
|
|
||||||
seed := make([]byte, 0, md5.Size+sha1.Size)
|
|
||||||
seed = h.clientMD5.Sum(seed)
|
|
||||||
seed = h.client.Sum(seed)
|
|
||||||
prf10(out, masterSecret, clientFinishedLabel, seed)
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// serverSum returns the contents of the verify_data member of a server's
|
|
||||||
// Finished message.
|
|
||||||
func (h finishedHash) serverSum(masterSecret []byte) []byte {
|
|
||||||
if h.version == VersionSSL30 {
|
|
||||||
return finishedSum30(h.serverMD5, h.server, masterSecret, ssl3ServerFinishedMagic)
|
|
||||||
}
|
|
||||||
|
|
||||||
out := make([]byte, finishedVerifyLength)
|
|
||||||
if h.version >= VersionTLS12 {
|
|
||||||
seed := h.server.Sum(nil)
|
|
||||||
prf12(out, masterSecret, serverFinishedLabel, seed)
|
|
||||||
} else {
|
|
||||||
seed := make([]byte, 0, md5.Size+sha1.Size)
|
|
||||||
seed = h.serverMD5.Sum(seed)
|
|
||||||
seed = h.server.Sum(seed)
|
|
||||||
prf10(out, masterSecret, serverFinishedLabel, seed)
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// hashForClientCertificate returns a digest, hash function, and TLS 1.2 hash
|
|
||||||
// id suitable for signing by a TLS client certificate.
|
|
||||||
func (h finishedHash) hashForClientCertificate(sigType uint8) ([]byte, crypto.Hash, uint8) {
|
|
||||||
if h.version >= VersionTLS12 {
|
|
||||||
digest := h.server.Sum(nil)
|
|
||||||
return digest, crypto.SHA256, hashSHA256
|
|
||||||
}
|
|
||||||
if sigType == signatureECDSA {
|
|
||||||
digest := h.server.Sum(nil)
|
|
||||||
return digest, crypto.SHA1, hashSHA1
|
|
||||||
}
|
|
||||||
|
|
||||||
digest := make([]byte, 0, 36)
|
|
||||||
digest = h.serverMD5.Sum(digest)
|
|
||||||
digest = h.server.Sum(digest)
|
|
||||||
return digest, crypto.MD5SHA1, 0 /* not specified in TLS 1.2. */
|
|
||||||
}
|
|
|
@ -1,182 +0,0 @@
|
||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"crypto/aes"
|
|
||||||
"crypto/cipher"
|
|
||||||
"crypto/hmac"
|
|
||||||
"crypto/sha256"
|
|
||||||
"crypto/subtle"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// sessionState contains the information that is serialized into a session
|
|
||||||
// ticket in order to later resume a connection.
|
|
||||||
type sessionState struct {
|
|
||||||
vers uint16
|
|
||||||
cipherSuite uint16
|
|
||||||
masterSecret []byte
|
|
||||||
certificates [][]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *sessionState) equal(i interface{}) bool {
|
|
||||||
s1, ok := i.(*sessionState)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.vers != s1.vers ||
|
|
||||||
s.cipherSuite != s1.cipherSuite ||
|
|
||||||
!bytes.Equal(s.masterSecret, s1.masterSecret) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(s.certificates) != len(s1.certificates) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range s.certificates {
|
|
||||||
if !bytes.Equal(s.certificates[i], s1.certificates[i]) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *sessionState) marshal() []byte {
|
|
||||||
length := 2 + 2 + 2 + len(s.masterSecret) + 2
|
|
||||||
for _, cert := range s.certificates {
|
|
||||||
length += 4 + len(cert)
|
|
||||||
}
|
|
||||||
|
|
||||||
ret := make([]byte, length)
|
|
||||||
x := ret
|
|
||||||
x[0] = byte(s.vers >> 8)
|
|
||||||
x[1] = byte(s.vers)
|
|
||||||
x[2] = byte(s.cipherSuite >> 8)
|
|
||||||
x[3] = byte(s.cipherSuite)
|
|
||||||
x[4] = byte(len(s.masterSecret) >> 8)
|
|
||||||
x[5] = byte(len(s.masterSecret))
|
|
||||||
x = x[6:]
|
|
||||||
copy(x, s.masterSecret)
|
|
||||||
x = x[len(s.masterSecret):]
|
|
||||||
|
|
||||||
x[0] = byte(len(s.certificates) >> 8)
|
|
||||||
x[1] = byte(len(s.certificates))
|
|
||||||
x = x[2:]
|
|
||||||
|
|
||||||
for _, cert := range s.certificates {
|
|
||||||
x[0] = byte(len(cert) >> 24)
|
|
||||||
x[1] = byte(len(cert) >> 16)
|
|
||||||
x[2] = byte(len(cert) >> 8)
|
|
||||||
x[3] = byte(len(cert))
|
|
||||||
copy(x[4:], cert)
|
|
||||||
x = x[4+len(cert):]
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *sessionState) unmarshal(data []byte) bool {
|
|
||||||
if len(data) < 8 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
s.vers = uint16(data[0])<<8 | uint16(data[1])
|
|
||||||
s.cipherSuite = uint16(data[2])<<8 | uint16(data[3])
|
|
||||||
masterSecretLen := int(data[4])<<8 | int(data[5])
|
|
||||||
data = data[6:]
|
|
||||||
if len(data) < masterSecretLen {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
s.masterSecret = data[:masterSecretLen]
|
|
||||||
data = data[masterSecretLen:]
|
|
||||||
|
|
||||||
if len(data) < 2 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
numCerts := int(data[0])<<8 | int(data[1])
|
|
||||||
data = data[2:]
|
|
||||||
|
|
||||||
s.certificates = make([][]byte, numCerts)
|
|
||||||
for i := range s.certificates {
|
|
||||||
if len(data) < 4 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
certLen := int(data[0])<<24 | int(data[1])<<16 | int(data[2])<<8 | int(data[3])
|
|
||||||
data = data[4:]
|
|
||||||
if certLen < 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(data) < certLen {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
s.certificates[i] = data[:certLen]
|
|
||||||
data = data[certLen:]
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(data) > 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) encryptTicket(state *sessionState) ([]byte, error) {
|
|
||||||
serialized := state.marshal()
|
|
||||||
encrypted := make([]byte, aes.BlockSize+len(serialized)+sha256.Size)
|
|
||||||
iv := encrypted[:aes.BlockSize]
|
|
||||||
macBytes := encrypted[len(encrypted)-sha256.Size:]
|
|
||||||
|
|
||||||
if _, err := io.ReadFull(c.config.rand(), iv); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
block, err := aes.NewCipher(c.config.SessionTicketKey[:16])
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("tls: failed to create cipher while encrypting ticket: " + err.Error())
|
|
||||||
}
|
|
||||||
cipher.NewCTR(block, iv).XORKeyStream(encrypted[aes.BlockSize:], serialized)
|
|
||||||
|
|
||||||
mac := hmac.New(sha256.New, c.config.SessionTicketKey[16:32])
|
|
||||||
mac.Write(encrypted[:len(encrypted)-sha256.Size])
|
|
||||||
mac.Sum(macBytes[:0])
|
|
||||||
|
|
||||||
return encrypted, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) decryptTicket(encrypted []byte) (*sessionState, bool) {
|
|
||||||
if len(encrypted) < aes.BlockSize+sha256.Size {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
iv := encrypted[:aes.BlockSize]
|
|
||||||
macBytes := encrypted[len(encrypted)-sha256.Size:]
|
|
||||||
|
|
||||||
mac := hmac.New(sha256.New, c.config.SessionTicketKey[16:32])
|
|
||||||
mac.Write(encrypted[:len(encrypted)-sha256.Size])
|
|
||||||
expected := mac.Sum(nil)
|
|
||||||
|
|
||||||
if subtle.ConstantTimeCompare(macBytes, expected) != 1 {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
block, err := aes.NewCipher(c.config.SessionTicketKey[:16])
|
|
||||||
if err != nil {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
ciphertext := encrypted[aes.BlockSize : len(encrypted)-sha256.Size]
|
|
||||||
plaintext := ciphertext
|
|
||||||
cipher.NewCTR(block, iv).XORKeyStream(plaintext, ciphertext)
|
|
||||||
|
|
||||||
state := new(sessionState)
|
|
||||||
ok := state.unmarshal(plaintext)
|
|
||||||
return state, ok
|
|
||||||
}
|
|
|
@ -1,225 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package tls partially implements TLS 1.2, as specified in RFC 5246.
|
|
||||||
package tls
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto"
|
|
||||||
"crypto/ecdsa"
|
|
||||||
"crypto/rsa"
|
|
||||||
"crypto/x509"
|
|
||||||
"encoding/pem"
|
|
||||||
"errors"
|
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Server returns a new TLS server side connection
|
|
||||||
// using conn as the underlying transport.
|
|
||||||
// The configuration config must be non-nil and must have
|
|
||||||
// at least one certificate.
|
|
||||||
func Server(conn net.Conn, config *Config) *Conn {
|
|
||||||
return &Conn{conn: conn, config: config}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Client returns a new TLS client side connection
|
|
||||||
// using conn as the underlying transport.
|
|
||||||
// Client interprets a nil configuration as equivalent to
|
|
||||||
// the zero configuration; see the documentation of Config
|
|
||||||
// for the defaults.
|
|
||||||
func Client(conn net.Conn, config *Config) *Conn {
|
|
||||||
return &Conn{conn: conn, config: config, isClient: true}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A listener implements a network listener (net.Listener) for TLS connections.
|
|
||||||
type listener struct {
|
|
||||||
net.Listener
|
|
||||||
config *Config
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accept waits for and returns the next incoming TLS connection.
|
|
||||||
// The returned connection c is a *tls.Conn.
|
|
||||||
func (l *listener) Accept() (c net.Conn, err error) {
|
|
||||||
c, err = l.Listener.Accept()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c = Server(c, l.config)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewListener creates a Listener which accepts connections from an inner
|
|
||||||
// Listener and wraps each connection with Server.
|
|
||||||
// The configuration config must be non-nil and must have
|
|
||||||
// at least one certificate.
|
|
||||||
func NewListener(inner net.Listener, config *Config) net.Listener {
|
|
||||||
l := new(listener)
|
|
||||||
l.Listener = inner
|
|
||||||
l.config = config
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listen creates a TLS listener accepting connections on the
|
|
||||||
// given network address using net.Listen.
|
|
||||||
// The configuration config must be non-nil and must have
|
|
||||||
// at least one certificate.
|
|
||||||
func Listen(network, laddr string, config *Config) (net.Listener, error) {
|
|
||||||
if config == nil || len(config.Certificates) == 0 {
|
|
||||||
return nil, errors.New("tls.Listen: no certificates in configuration")
|
|
||||||
}
|
|
||||||
l, err := net.Listen(network, laddr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return NewListener(l, config), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dial connects to the given network address using net.Dial
|
|
||||||
// and then initiates a TLS handshake, returning the resulting
|
|
||||||
// TLS connection.
|
|
||||||
// Dial interprets a nil configuration as equivalent to
|
|
||||||
// the zero configuration; see the documentation of Config
|
|
||||||
// for the defaults.
|
|
||||||
func Dial(network, addr string, config *Config) (*Conn, error) {
|
|
||||||
raddr := addr
|
|
||||||
c, err := net.Dial(network, raddr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
colonPos := strings.LastIndex(raddr, ":")
|
|
||||||
if colonPos == -1 {
|
|
||||||
colonPos = len(raddr)
|
|
||||||
}
|
|
||||||
hostname := raddr[:colonPos]
|
|
||||||
|
|
||||||
if config == nil {
|
|
||||||
config = defaultConfig()
|
|
||||||
}
|
|
||||||
// If no ServerName is set, infer the ServerName
|
|
||||||
// from the hostname we're connecting to.
|
|
||||||
if config.ServerName == "" {
|
|
||||||
// Make a copy to avoid polluting argument or default.
|
|
||||||
c := *config
|
|
||||||
c.ServerName = hostname
|
|
||||||
config = &c
|
|
||||||
}
|
|
||||||
conn := Client(c, config)
|
|
||||||
if err = conn.Handshake(); err != nil {
|
|
||||||
c.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return conn, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadX509KeyPair reads and parses a public/private key pair from a pair of
|
|
||||||
// files. The files must contain PEM encoded data.
|
|
||||||
func LoadX509KeyPair(certFile, keyFile string) (cert Certificate, err error) {
|
|
||||||
certPEMBlock, err := ioutil.ReadFile(certFile)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
keyPEMBlock, err := ioutil.ReadFile(keyFile)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return X509KeyPair(certPEMBlock, keyPEMBlock)
|
|
||||||
}
|
|
||||||
|
|
||||||
// X509KeyPair parses a public/private key pair from a pair of
|
|
||||||
// PEM encoded data.
|
|
||||||
func X509KeyPair(certPEMBlock, keyPEMBlock []byte) (cert Certificate, err error) {
|
|
||||||
var certDERBlock *pem.Block
|
|
||||||
for {
|
|
||||||
certDERBlock, certPEMBlock = pem.Decode(certPEMBlock)
|
|
||||||
if certDERBlock == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if certDERBlock.Type == "CERTIFICATE" {
|
|
||||||
cert.Certificate = append(cert.Certificate, certDERBlock.Bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cert.Certificate) == 0 {
|
|
||||||
err = errors.New("crypto/tls: failed to parse certificate PEM data")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var keyDERBlock *pem.Block
|
|
||||||
for {
|
|
||||||
keyDERBlock, keyPEMBlock = pem.Decode(keyPEMBlock)
|
|
||||||
if keyDERBlock == nil {
|
|
||||||
err = errors.New("crypto/tls: failed to parse key PEM data")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if keyDERBlock.Type == "PRIVATE KEY" || strings.HasSuffix(keyDERBlock.Type, " PRIVATE KEY") {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cert.PrivateKey, err = parsePrivateKey(keyDERBlock.Bytes)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't need to parse the public key for TLS, but we so do anyway
|
|
||||||
// to check that it looks sane and matches the private key.
|
|
||||||
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch pub := x509Cert.PublicKey.(type) {
|
|
||||||
case *rsa.PublicKey:
|
|
||||||
priv, ok := cert.PrivateKey.(*rsa.PrivateKey)
|
|
||||||
if !ok {
|
|
||||||
err = errors.New("crypto/tls: private key type does not match public key type")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if pub.N.Cmp(priv.N) != 0 {
|
|
||||||
err = errors.New("crypto/tls: private key does not match public key")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case *ecdsa.PublicKey:
|
|
||||||
priv, ok := cert.PrivateKey.(*ecdsa.PrivateKey)
|
|
||||||
if !ok {
|
|
||||||
err = errors.New("crypto/tls: private key type does not match public key type")
|
|
||||||
return
|
|
||||||
|
|
||||||
}
|
|
||||||
if pub.X.Cmp(priv.X) != 0 || pub.Y.Cmp(priv.Y) != 0 {
|
|
||||||
err = errors.New("crypto/tls: private key does not match public key")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
err = errors.New("crypto/tls: unknown public key algorithm")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to parse the given private key DER block. OpenSSL 0.9.8 generates
|
|
||||||
// PKCS#1 private keys by default, while OpenSSL 1.0.0 generates PKCS#8 keys.
|
|
||||||
// OpenSSL ecparam generates SEC1 EC private keys for ECDSA. We try all three.
|
|
||||||
func parsePrivateKey(der []byte) (crypto.PrivateKey, error) {
|
|
||||||
if key, err := x509.ParsePKCS1PrivateKey(der); err == nil {
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
if key, err := x509.ParsePKCS8PrivateKey(der); err == nil {
|
|
||||||
switch key := key.(type) {
|
|
||||||
case *rsa.PrivateKey, *ecdsa.PrivateKey:
|
|
||||||
return key, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("crypto/tls: found unknown private key type in PKCS#8 wrapping")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if key, err := x509.ParseECPrivateKey(der); err == nil {
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New("crypto/tls: failed to parse private key")
|
|
||||||
}
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Azure Service Management packages for Go
|
||||||
|
|
||||||
|
The `github.com/Azure/azure-sdk-for-go/management` packages are used to perform operations using the Azure Service Management (ASM), aka classic deployment model. Read more about [Azure Resource Manager vs. classic deployment](https://azure.microsoft.com/documentation/articles/resource-manager-deployment-model/). Packages for Azure Resource Manager are in the [arm](../arm) folder.
|
||||||
|
|
||||||
|
## First a Sidenote: Authentication and the Azure Service Manager
|
||||||
|
|
||||||
|
The client currently supports authentication to the Service Management
|
||||||
|
API with certificates or Azure `.publishSettings` file. You can
|
||||||
|
download the `.publishSettings` file for your subscriptions
|
||||||
|
[here](https://manage.windowsazure.com/publishsettings).
|
||||||
|
|
||||||
|
### Example: Creating a Linux Virtual Machine
|
||||||
|
|
||||||
|
Complete source code for this example can be found in [example.go](/management/examples/example.go).To try this example, [download your .publishSettings](https://manage.windowsazure.com/publishsettings) and add its path in the first line of the main function. Run the example with commands:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cd management/examples
|
||||||
|
$ go run example.go
|
||||||
|
```
|
|
@ -2,10 +2,9 @@ package management
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
||||||
"github.com/Azure/azure-sdk-for-go/core/tls"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -85,18 +84,15 @@ func (client client) sendAzureRequest(method, url, contentType string, data []by
|
||||||
// the subscription for this client.
|
// the subscription for this client.
|
||||||
func (client client) createHTTPClient() *http.Client {
|
func (client client) createHTTPClient() *http.Client {
|
||||||
cert, _ := tls.X509KeyPair(client.publishSettings.SubscriptionCert, client.publishSettings.SubscriptionKey)
|
cert, _ := tls.X509KeyPair(client.publishSettings.SubscriptionCert, client.publishSettings.SubscriptionKey)
|
||||||
|
return &http.Client{
|
||||||
ssl := &tls.Config{}
|
|
||||||
ssl.Certificates = []tls.Certificate{cert}
|
|
||||||
|
|
||||||
httpClient := &http.Client{
|
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
Proxy: http.ProxyFromEnvironment,
|
Proxy: http.ProxyFromEnvironment,
|
||||||
TLSClientConfig: ssl,
|
TLSClientConfig: &tls.Config{
|
||||||
|
Renegotiation: tls.RenegotiateOnceAsClient,
|
||||||
|
Certificates: []tls.Certificate{cert},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return httpClient
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendRequest sends a request to the Azure management API using the given
|
// sendRequest sends a request to the Azure management API using the given
|
||||||
|
|
|
@ -29,3 +29,16 @@ func (c OSImageClient) ListOSImages() (ListOSImagesResponse, error) {
|
||||||
err = xml.Unmarshal(response, &l)
|
err = xml.Unmarshal(response, &l)
|
||||||
return l, err
|
return l, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddOSImage adds an operating system image to the image repository that is associated with the specified subscription.
|
||||||
|
//
|
||||||
|
// See https://msdn.microsoft.com/en-us/library/azure/jj157192.aspx for details.
|
||||||
|
func (c OSImageClient) AddOSImage(osi *OSImage) (management.OperationID, error) {
|
||||||
|
data, err := xml.Marshal(osi)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.client.SendAzurePostRequest(azureImageListURL, data)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -17,26 +17,28 @@ type ListOSImagesResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type OSImage struct {
|
type OSImage struct {
|
||||||
Category string // Public || Private || MSDN
|
XMLName xml.Name `xml:"http://schemas.microsoft.com/windowsazure OSImage"`
|
||||||
Label string // Specifies an identifier for the image.
|
Category string // Public || Private || MSDN
|
||||||
LogicalSizeInGB float64 //Specifies the size, in GB, of the image.
|
Label string // Specifies an identifier for the image.
|
||||||
Name string // Specifies the name of the operating system image. This is the name that is used when creating one or more virtual machines using the image.
|
LogicalSizeInGB float64 //Specifies the size, in GB, of the image.
|
||||||
OS string // Linux || Windows
|
Name string // Specifies the name of the operating system image. This is the name that is used when creating one or more virtual machines using the image.
|
||||||
Eula string // Specifies the End User License Agreement that is associated with the image. The value for this element is a string, but it is recommended that the value be a URL that points to a EULA.
|
OS string // Linux || Windows
|
||||||
Description string // Specifies the description of the image.
|
Eula string // Specifies the End User License Agreement that is associated with the image. The value for this element is a string, but it is recommended that the value be a URL that points to a EULA.
|
||||||
Location string // The geo-location in which this media is located. The Location value is derived from storage account that contains the blob in which the media is located. If the storage account belongs to an affinity group the value is NULL.
|
Description string // Specifies the description of the image.
|
||||||
AffinityGroup string // Specifies the affinity in which the media is located. The AffinityGroup value is derived from storage account that contains the blob in which the media is located. If the storage account does not belong to an affinity group the value is NULL and the element is not displayed in the response. This value is NULL for platform images.
|
Location string // The geo-location in which this media is located. The Location value is derived from storage account that contains the blob in which the media is located. If the storage account belongs to an affinity group the value is NULL.
|
||||||
MediaLink string // Specifies the location of the vhd file for the image. The storage account where the vhd is located must be associated with the specified subscription.
|
AffinityGroup string // Specifies the affinity in which the media is located. The AffinityGroup value is derived from storage account that contains the blob in which the media is located. If the storage account does not belong to an affinity group the value is NULL and the element is not displayed in the response. This value is NULL for platform images.
|
||||||
ImageFamily string // Specifies a value that can be used to group images.
|
MediaLink string // Specifies the location of the vhd file for the image. The storage account where the vhd is located must be associated with the specified subscription.
|
||||||
PublishedDate string // Specifies the date when the image was added to the image repository.
|
ImageFamily string // Specifies a value that can be used to group images.
|
||||||
IsPremium string // Indicates whether the image contains software or associated services that will incur charges above the core price for the virtual machine. For additional details, see the PricingDetailLink element.
|
PublishedDate string // Specifies the date when the image was added to the image repository.
|
||||||
PrivacyURI string `xml:"PrivacyUri"` // Specifies the URI that points to a document that contains the privacy policy related to the image.
|
IsPremium string // Indicates whether the image contains software or associated services that will incur charges above the core price for the virtual machine. For additional details, see the PricingDetailLink element.
|
||||||
RecommendedVMSize string // Specifies the size to use for the virtual machine that is created from the image.
|
PrivacyURI string `xml:"PrivacyUri"` // Specifies the URI that points to a document that contains the privacy policy related to the image.
|
||||||
PublisherName string // The name of the publisher of the image. All user images have a publisher name of User.
|
RecommendedVMSize string // Specifies the size to use for the virtual machine that is created from the image.
|
||||||
PricingDetailLink string // Specifies a URL for an image with IsPremium set to true, which contains the pricing details for a virtual machine that is created from the image.
|
PublisherName string // The name of the publisher of the image. All user images have a publisher name of User.
|
||||||
SmallIconURI string `xml:"SmallIconUri"` // Specifies the URI to the small icon that is displayed when the image is presented in the Microsoft Azure Management Portal.
|
PricingDetailLink string // Specifies a URL for an image with IsPremium set to true, which contains the pricing details for a virtual machine that is created from the image.
|
||||||
Language string // Specifies the language of the image.
|
IconURI string `xml:"IconUri"` // Specifies the Uri to the icon that is displayed for the image in the Management Portal.
|
||||||
IOType IOType // Provisioned || Standard
|
SmallIconURI string `xml:"SmallIconUri"` // Specifies the URI to the small icon that is displayed when the image is presented in the Microsoft Azure Management Portal.
|
||||||
|
Language string // Specifies the language of the image.
|
||||||
|
IOType IOType // Provisioned || Standard
|
||||||
}
|
}
|
||||||
|
|
||||||
type IOType string
|
type IOType string
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package management
|
package management
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getResponseBody(response *http.Response) ([]byte, error) {
|
func getResponseBody(response *http.Response) ([]byte, error) {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Azure Storage SDK for Go
|
||||||
|
|
||||||
|
The `github.com/Azure/azure-sdk-for-go/storage` package is used to perform operations in Azure Storage Service. To manage your storage accounts (Azure Resource Manager / ARM), use the [github.com/Azure/azure-sdk-for-go/arm/storage](../arm/storage) package. For your classic storage accounts (Azure Service Management / ASM), use [github.com/Azure/azure-sdk-for-go/management/storageservice](../management/storageservice) package.
|
||||||
|
|
||||||
|
This package includes support for [Azure Storage Emulator](https://azure.microsoft.com/documentation/articles/storage-use-emulator/)
|
|
@ -1,9 +1,11 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileServiceClient contains operations for Microsoft Azure File Service.
|
// FileServiceClient contains operations for Microsoft Azure File Service.
|
||||||
|
@ -11,11 +13,99 @@ type FileServiceClient struct {
|
||||||
client Client
|
client Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A Share is an entry in ShareListResponse.
|
||||||
|
type Share struct {
|
||||||
|
Name string `xml:"Name"`
|
||||||
|
Properties ShareProperties `xml:"Properties"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareProperties contains various properties of a share returned from
|
||||||
|
// various endpoints like ListShares.
|
||||||
|
type ShareProperties struct {
|
||||||
|
LastModified string `xml:"Last-Modified"`
|
||||||
|
Etag string `xml:"Etag"`
|
||||||
|
Quota string `xml:"Quota"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareListResponse contains the response fields from
|
||||||
|
// ListShares call.
|
||||||
|
//
|
||||||
|
// See https://msdn.microsoft.com/en-us/library/azure/dn167009.aspx
|
||||||
|
type ShareListResponse struct {
|
||||||
|
XMLName xml.Name `xml:"EnumerationResults"`
|
||||||
|
Xmlns string `xml:"xmlns,attr"`
|
||||||
|
Prefix string `xml:"Prefix"`
|
||||||
|
Marker string `xml:"Marker"`
|
||||||
|
NextMarker string `xml:"NextMarker"`
|
||||||
|
MaxResults int64 `xml:"MaxResults"`
|
||||||
|
Shares []Share `xml:"Shares>Share"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListSharesParameters defines the set of customizable parameters to make a
|
||||||
|
// List Shares call.
|
||||||
|
//
|
||||||
|
// See https://msdn.microsoft.com/en-us/library/azure/dn167009.aspx
|
||||||
|
type ListSharesParameters struct {
|
||||||
|
Prefix string
|
||||||
|
Marker string
|
||||||
|
Include string
|
||||||
|
MaxResults uint
|
||||||
|
Timeout uint
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareHeaders contains various properties of a file and is an entry
|
||||||
|
// in SetShareProperties
|
||||||
|
type ShareHeaders struct {
|
||||||
|
Quota string `header:"x-ms-share-quota"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ListSharesParameters) getParameters() url.Values {
|
||||||
|
out := url.Values{}
|
||||||
|
|
||||||
|
if p.Prefix != "" {
|
||||||
|
out.Set("prefix", p.Prefix)
|
||||||
|
}
|
||||||
|
if p.Marker != "" {
|
||||||
|
out.Set("marker", p.Marker)
|
||||||
|
}
|
||||||
|
if p.Include != "" {
|
||||||
|
out.Set("include", p.Include)
|
||||||
|
}
|
||||||
|
if p.MaxResults != 0 {
|
||||||
|
out.Set("maxresults", fmt.Sprintf("%v", p.MaxResults))
|
||||||
|
}
|
||||||
|
if p.Timeout != 0 {
|
||||||
|
out.Set("timeout", fmt.Sprintf("%v", p.Timeout))
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// pathForFileShare returns the URL path segment for a File Share resource
|
// pathForFileShare returns the URL path segment for a File Share resource
|
||||||
func pathForFileShare(name string) string {
|
func pathForFileShare(name string) string {
|
||||||
return fmt.Sprintf("/%s", name)
|
return fmt.Sprintf("/%s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListShares returns the list of shares in a storage account along with
|
||||||
|
// pagination token and other response details.
|
||||||
|
//
|
||||||
|
// See https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx
|
||||||
|
func (f FileServiceClient) ListShares(params ListSharesParameters) (ShareListResponse, error) {
|
||||||
|
q := mergeParams(params.getParameters(), url.Values{"comp": {"list"}})
|
||||||
|
uri := f.client.getEndpoint(fileServiceName, "", q)
|
||||||
|
headers := f.client.getStandardHeaders()
|
||||||
|
|
||||||
|
var out ShareListResponse
|
||||||
|
resp, err := f.client.exec("GET", uri, headers, nil)
|
||||||
|
if err != nil {
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
defer resp.body.Close()
|
||||||
|
|
||||||
|
err = xmlUnmarshal(resp.body, &out)
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
// CreateShare operation creates a new share under the specified account. If the
|
// CreateShare operation creates a new share under the specified account. If the
|
||||||
// share with the same name already exists, the operation fails.
|
// share with the same name already exists, the operation fails.
|
||||||
//
|
//
|
||||||
|
@ -29,6 +119,30 @@ func (f FileServiceClient) CreateShare(name string) error {
|
||||||
return checkRespCode(resp.statusCode, []int{http.StatusCreated})
|
return checkRespCode(resp.statusCode, []int{http.StatusCreated})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShareExists returns true if a share with given name exists
|
||||||
|
// on the storage account, otherwise returns false.
|
||||||
|
func (f FileServiceClient) ShareExists(name string) (bool, error) {
|
||||||
|
uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), url.Values{"restype": {"share"}})
|
||||||
|
headers := f.client.getStandardHeaders()
|
||||||
|
|
||||||
|
resp, err := f.client.exec("HEAD", uri, headers, nil)
|
||||||
|
if resp != nil {
|
||||||
|
defer resp.body.Close()
|
||||||
|
if resp.statusCode == http.StatusOK || resp.statusCode == http.StatusNotFound {
|
||||||
|
return resp.statusCode == http.StatusOK, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetShareURL gets the canonical URL to the share with the specified name in the
|
||||||
|
// specified container. This method does not create a publicly accessible URL if
|
||||||
|
// the file is private and this method does not check if the file
|
||||||
|
// exists.
|
||||||
|
func (f FileServiceClient) GetShareURL(name string) string {
|
||||||
|
return f.client.getEndpoint(fileServiceName, pathForFileShare(name), url.Values{})
|
||||||
|
}
|
||||||
|
|
||||||
// CreateShareIfNotExists creates a new share under the specified account if
|
// CreateShareIfNotExists creates a new share under the specified account if
|
||||||
// it does not exist. Returns true if container is newly created or false if
|
// it does not exist. Returns true if container is newly created or false if
|
||||||
// container already exists.
|
// container already exists.
|
||||||
|
@ -55,6 +169,60 @@ func (f FileServiceClient) createShare(name string) (*storageResponse, error) {
|
||||||
return f.client.exec("PUT", uri, headers, nil)
|
return f.client.exec("PUT", uri, headers, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetShareProperties provides various information about the specified
|
||||||
|
// file. See https://msdn.microsoft.com/en-us/library/azure/dn689099.aspx
|
||||||
|
func (f FileServiceClient) GetShareProperties(name string) (*ShareProperties, error) {
|
||||||
|
uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), url.Values{"restype": {"share"}})
|
||||||
|
|
||||||
|
headers := f.client.getStandardHeaders()
|
||||||
|
resp, err := f.client.exec("HEAD", uri, headers, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.body.Close()
|
||||||
|
|
||||||
|
if err := checkRespCode(resp.statusCode, []int{http.StatusOK}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ShareProperties{
|
||||||
|
LastModified: resp.headers.Get("Last-Modified"),
|
||||||
|
Etag: resp.headers.Get("Etag"),
|
||||||
|
Quota: resp.headers.Get("x-ms-share-quota"),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShareProperties replaces the ShareHeaders for the specified file.
|
||||||
|
//
|
||||||
|
// Some keys may be converted to Camel-Case before sending. All keys
|
||||||
|
// are returned in lower case by SetShareProperties. HTTP header names
|
||||||
|
// are case-insensitive so case munging should not matter to other
|
||||||
|
// applications either.
|
||||||
|
//
|
||||||
|
// See https://msdn.microsoft.com/en-us/library/azure/mt427368.aspx
|
||||||
|
func (f FileServiceClient) SetShareProperties(name string, shareHeaders ShareHeaders) error {
|
||||||
|
params := url.Values{}
|
||||||
|
params.Set("restype", "share")
|
||||||
|
params.Set("comp", "properties")
|
||||||
|
|
||||||
|
uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), params)
|
||||||
|
headers := f.client.getStandardHeaders()
|
||||||
|
|
||||||
|
extraHeaders := headersFromStruct(shareHeaders)
|
||||||
|
|
||||||
|
for k, v := range extraHeaders {
|
||||||
|
headers[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := f.client.exec("PUT", uri, headers, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.body.Close()
|
||||||
|
|
||||||
|
return checkRespCode(resp.statusCode, []int{http.StatusOK})
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteShare operation marks the specified share for deletion. The share
|
// DeleteShare operation marks the specified share for deletion. The share
|
||||||
// and any files contained within it are later deleted during garbage
|
// and any files contained within it are later deleted during garbage
|
||||||
// collection.
|
// collection.
|
||||||
|
@ -96,6 +264,84 @@ func (f FileServiceClient) deleteShare(name string) (*storageResponse, error) {
|
||||||
return f.client.exec("DELETE", uri, f.client.getStandardHeaders(), nil)
|
return f.client.exec("DELETE", uri, f.client.getStandardHeaders(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetShareMetadata replaces the metadata for the specified Share.
|
||||||
|
//
|
||||||
|
// Some keys may be converted to Camel-Case before sending. All keys
|
||||||
|
// are returned in lower case by GetShareMetadata. HTTP header names
|
||||||
|
// are case-insensitive so case munging should not matter to other
|
||||||
|
// applications either.
|
||||||
|
//
|
||||||
|
// See https://msdn.microsoft.com/en-us/library/azure/dd179414.aspx
|
||||||
|
func (f FileServiceClient) SetShareMetadata(name string, metadata map[string]string, extraHeaders map[string]string) error {
|
||||||
|
params := url.Values{}
|
||||||
|
params.Set("restype", "share")
|
||||||
|
params.Set("comp", "metadata")
|
||||||
|
|
||||||
|
uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), params)
|
||||||
|
headers := f.client.getStandardHeaders()
|
||||||
|
for k, v := range metadata {
|
||||||
|
headers[userDefinedMetadataHeaderPrefix+k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range extraHeaders {
|
||||||
|
headers[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := f.client.exec("PUT", uri, headers, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.body.Close()
|
||||||
|
|
||||||
|
return checkRespCode(resp.statusCode, []int{http.StatusOK})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetShareMetadata returns all user-defined metadata for the specified share.
|
||||||
|
//
|
||||||
|
// All metadata keys will be returned in lower case. (HTTP header
|
||||||
|
// names are case-insensitive.)
|
||||||
|
//
|
||||||
|
// See https://msdn.microsoft.com/en-us/library/azure/dd179414.aspx
|
||||||
|
func (f FileServiceClient) GetShareMetadata(name string) (map[string]string, error) {
|
||||||
|
params := url.Values{}
|
||||||
|
params.Set("restype", "share")
|
||||||
|
params.Set("comp", "metadata")
|
||||||
|
|
||||||
|
uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), params)
|
||||||
|
headers := f.client.getStandardHeaders()
|
||||||
|
|
||||||
|
resp, err := f.client.exec("GET", uri, headers, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.body.Close()
|
||||||
|
|
||||||
|
if err := checkRespCode(resp.statusCode, []int{http.StatusOK}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata := make(map[string]string)
|
||||||
|
for k, v := range resp.headers {
|
||||||
|
// Can't trust CanonicalHeaderKey() to munge case
|
||||||
|
// reliably. "_" is allowed in identifiers:
|
||||||
|
// https://msdn.microsoft.com/en-us/library/azure/dd179414.aspx
|
||||||
|
// https://msdn.microsoft.com/library/aa664670(VS.71).aspx
|
||||||
|
// http://tools.ietf.org/html/rfc7230#section-3.2
|
||||||
|
// ...but "_" is considered invalid by
|
||||||
|
// CanonicalMIMEHeaderKey in
|
||||||
|
// https://golang.org/src/net/textproto/reader.go?s=14615:14659#L542
|
||||||
|
// so k can be "X-Ms-Meta-Foo" or "x-ms-meta-foo_bar".
|
||||||
|
k = strings.ToLower(k)
|
||||||
|
if len(v) == 0 || !strings.HasPrefix(k, strings.ToLower(userDefinedMetadataHeaderPrefix)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// metadata["foo"] = content of the last X-Ms-Meta-Foo header
|
||||||
|
k = k[len(userDefinedMetadataHeaderPrefix):]
|
||||||
|
metadata[k] = v[len(v)-1]
|
||||||
|
}
|
||||||
|
return metadata, nil
|
||||||
|
}
|
||||||
|
|
||||||
//checkForStorageEmulator determines if the client is setup for use with
|
//checkForStorageEmulator determines if the client is setup for use with
|
||||||
//Azure Storage Emulator, and returns a relevant error
|
//Azure Storage Emulator, and returns a relevant error
|
||||||
func (f FileServiceClient) checkForStorageEmulator() error {
|
func (f FileServiceClient) checkForStorageEmulator() error {
|
||||||
|
|
|
@ -98,6 +98,10 @@ func (c *TableServiceClient) QueryTableEntities(tableName AzureTable, previousCo
|
||||||
|
|
||||||
resp, err := c.client.execTable("GET", uri, headers, nil)
|
resp, err := c.client.execTable("GET", uri, headers, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
contToken := extractContinuationTokenFromHeaders(resp.headers)
|
contToken := extractContinuationTokenFromHeaders(resp.headers)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue