refactor code so that packer/version is not a dependency of sdk code or plugin code
This commit is contained in:
parent
cd59d938b2
commit
1ecd715221
|
@ -11,8 +11,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
|
||||
"github.com/hashicorp/packer/builder/alicloud/version"
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
"github.com/hashicorp/packer/version"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
|
@ -78,7 +78,7 @@ func (c *AlicloudAccessConfig) Client() (*ClientWrapper, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
client.AppendUserAgent(Packer, version.FormattedVersion())
|
||||
client.AppendUserAgent(Packer, version.AlicloudPluginVersion.FormattedVersion())
|
||||
client.SetReadTimeout(DefaultRequestReadTimeout)
|
||||
c.client = &ClientWrapper{client}
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/helper/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var AlicloudPluginVersion = version.PluginVersion{
|
||||
Version: packerVersion.Version,
|
||||
VersionPrerelease: packerVersion.VersionPrerelease,
|
||||
}
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/Azure/go-autorest/autorest/adal"
|
||||
"github.com/Azure/go-autorest/autorest/azure"
|
||||
"github.com/hashicorp/packer/builder/azure/common"
|
||||
"github.com/hashicorp/packer/builder/azure/version"
|
||||
"github.com/hashicorp/packer/helper/useragent"
|
||||
)
|
||||
|
||||
|
@ -140,97 +141,97 @@ func NewAzureClient(subscriptionID, sigSubscriptionID, resourceGroupName, storag
|
|||
azureClient.DeploymentsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.DeploymentsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.DeploymentsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.DeploymentsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.DeploymentsClient.UserAgent)
|
||||
azureClient.DeploymentsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.DeploymentsClient.UserAgent)
|
||||
azureClient.DeploymentsClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.DeploymentOperationsClient = resources.NewDeploymentOperationsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.DeploymentOperationsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.DeploymentOperationsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.DeploymentOperationsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.DeploymentOperationsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.DeploymentOperationsClient.UserAgent)
|
||||
azureClient.DeploymentOperationsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.DeploymentOperationsClient.UserAgent)
|
||||
azureClient.DeploymentOperationsClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.DisksClient = compute.NewDisksClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.DisksClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.DisksClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.DisksClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.DisksClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.DisksClient.UserAgent)
|
||||
azureClient.DisksClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.DisksClient.UserAgent)
|
||||
azureClient.DisksClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.GroupsClient = resources.NewGroupsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.GroupsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.GroupsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.GroupsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.GroupsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.GroupsClient.UserAgent)
|
||||
azureClient.GroupsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.GroupsClient.UserAgent)
|
||||
azureClient.GroupsClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.ImagesClient = compute.NewImagesClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.ImagesClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.ImagesClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.ImagesClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.ImagesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.ImagesClient.UserAgent)
|
||||
azureClient.ImagesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.ImagesClient.UserAgent)
|
||||
azureClient.ImagesClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.InterfacesClient = network.NewInterfacesClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.InterfacesClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.InterfacesClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.InterfacesClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.InterfacesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.InterfacesClient.UserAgent)
|
||||
azureClient.InterfacesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.InterfacesClient.UserAgent)
|
||||
azureClient.InterfacesClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.SubnetsClient = network.NewSubnetsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.SubnetsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.SubnetsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.SubnetsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.SubnetsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.SubnetsClient.UserAgent)
|
||||
azureClient.SubnetsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.SubnetsClient.UserAgent)
|
||||
azureClient.SubnetsClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.VirtualNetworksClient = network.NewVirtualNetworksClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.VirtualNetworksClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.VirtualNetworksClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.VirtualNetworksClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.VirtualNetworksClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.VirtualNetworksClient.UserAgent)
|
||||
azureClient.VirtualNetworksClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.VirtualNetworksClient.UserAgent)
|
||||
azureClient.VirtualNetworksClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.SecurityGroupsClient = network.NewSecurityGroupsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.SecurityGroupsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.SecurityGroupsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.SecurityGroupsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.SecurityGroupsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.SecurityGroupsClient.UserAgent)
|
||||
azureClient.SecurityGroupsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.SecurityGroupsClient.UserAgent)
|
||||
|
||||
azureClient.PublicIPAddressesClient = network.NewPublicIPAddressesClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.PublicIPAddressesClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.PublicIPAddressesClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.PublicIPAddressesClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.PublicIPAddressesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.PublicIPAddressesClient.UserAgent)
|
||||
azureClient.PublicIPAddressesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.PublicIPAddressesClient.UserAgent)
|
||||
azureClient.PublicIPAddressesClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.VirtualMachinesClient = compute.NewVirtualMachinesClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.VirtualMachinesClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.VirtualMachinesClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.VirtualMachinesClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), templateCapture(azureClient), errorCapture(azureClient))
|
||||
azureClient.VirtualMachinesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.VirtualMachinesClient.UserAgent)
|
||||
azureClient.VirtualMachinesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.VirtualMachinesClient.UserAgent)
|
||||
azureClient.VirtualMachinesClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.SnapshotsClient = compute.NewSnapshotsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.SnapshotsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.SnapshotsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.SnapshotsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.SnapshotsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.SnapshotsClient.UserAgent)
|
||||
azureClient.SnapshotsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.SnapshotsClient.UserAgent)
|
||||
azureClient.SnapshotsClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.AccountsClient = armStorage.NewAccountsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.AccountsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.AccountsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.AccountsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.AccountsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.AccountsClient.UserAgent)
|
||||
azureClient.AccountsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.AccountsClient.UserAgent)
|
||||
azureClient.AccountsClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
azureClient.GalleryImageVersionsClient = newCompute.NewGalleryImageVersionsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.GalleryImageVersionsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.GalleryImageVersionsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.GalleryImageVersionsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.GalleryImageVersionsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.GalleryImageVersionsClient.UserAgent)
|
||||
azureClient.GalleryImageVersionsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.GalleryImageVersionsClient.UserAgent)
|
||||
azureClient.GalleryImageVersionsClient.Client.PollingDuration = sharedGalleryTimeout
|
||||
azureClient.GalleryImageVersionsClient.SubscriptionID = sigSubscriptionID
|
||||
|
||||
|
@ -238,7 +239,7 @@ func NewAzureClient(subscriptionID, sigSubscriptionID, resourceGroupName, storag
|
|||
azureClient.GalleryImagesClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.GalleryImagesClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.GalleryImagesClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.GalleryImagesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.GalleryImagesClient.UserAgent)
|
||||
azureClient.GalleryImagesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.GalleryImagesClient.UserAgent)
|
||||
azureClient.GalleryImagesClient.Client.PollingDuration = pollingDuration
|
||||
azureClient.GalleryImagesClient.SubscriptionID = sigSubscriptionID
|
||||
|
||||
|
@ -251,7 +252,7 @@ func NewAzureClient(subscriptionID, sigSubscriptionID, resourceGroupName, storag
|
|||
azureClient.VaultClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalTokenVault)
|
||||
azureClient.VaultClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.VaultClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.VaultClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.VaultClient.UserAgent)
|
||||
azureClient.VaultClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.VaultClient.UserAgent)
|
||||
azureClient.VaultClient.Client.PollingDuration = pollingDuration
|
||||
|
||||
// This client is different than the above because it manages the vault
|
||||
|
@ -260,7 +261,7 @@ func NewAzureClient(subscriptionID, sigSubscriptionID, resourceGroupName, storag
|
|||
azureClient.VaultClientDelete.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.VaultClientDelete.RequestInspector = withInspection(maxlen)
|
||||
azureClient.VaultClientDelete.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.VaultClientDelete.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.VaultClientDelete.UserAgent)
|
||||
azureClient.VaultClientDelete.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.VaultClientDelete.UserAgent)
|
||||
azureClient.VaultClientDelete.Client.PollingDuration = pollingDuration
|
||||
|
||||
// If this is a managed disk build, this should be ignored.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"time"
|
||||
|
@ -10,6 +11,7 @@ import (
|
|||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
|
||||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute/computeapi"
|
||||
"github.com/Azure/go-autorest/autorest"
|
||||
version "github.com/hashicorp/packer/builder/azure/version"
|
||||
)
|
||||
|
||||
type AzureClientSet interface {
|
||||
|
@ -64,7 +66,10 @@ func (s azureClientSet) SubscriptionID() string {
|
|||
}
|
||||
|
||||
func (s azureClientSet) configureAutorestClient(c *autorest.Client) {
|
||||
c.AddToUserAgent(useragent.String())
|
||||
err := c.AddToUserAgent(useragent.String(version.AzurePluginVersion.FormattedVersion()))
|
||||
if err != nil {
|
||||
log.Printf("Error appending Packer plugin version to user agent.")
|
||||
}
|
||||
c.Authorizer = s.authorizer
|
||||
c.Sender = s.sender
|
||||
}
|
||||
|
@ -72,7 +77,7 @@ func (s azureClientSet) configureAutorestClient(c *autorest.Client) {
|
|||
func (s azureClientSet) MetadataClient() MetadataClientAPI {
|
||||
return metadataClient{
|
||||
s.sender,
|
||||
useragent.String(),
|
||||
useragent.String(version.AzurePluginVersion.FormattedVersion()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/Azure/go-autorest/autorest/adal"
|
||||
"github.com/Azure/go-autorest/autorest/azure"
|
||||
"github.com/Azure/go-autorest/autorest/to"
|
||||
version "github.com/hashicorp/packer/builder/azure/version"
|
||||
"github.com/hashicorp/packer/helper/useragent"
|
||||
)
|
||||
|
||||
|
@ -123,7 +124,7 @@ func tokenFromFile(say func(string), oauthCfg adal.OAuthConfig, tokenPath, clien
|
|||
// endpoint is polled until user gives consent, denies or the flow times out.
|
||||
// Returned token must be saved.
|
||||
func tokenFromDeviceFlow(say func(string), oauthCfg adal.OAuthConfig, clientID, resource string) (*adal.ServicePrincipalToken, error) {
|
||||
cl := autorest.NewClientWithUserAgent(useragent.String())
|
||||
cl := autorest.NewClientWithUserAgent(useragent.String(version.AzurePluginVersion.FormattedVersion()))
|
||||
deviceCode, err := adal.InitiateDeviceAuth(&cl, oauthCfg, clientID, resource)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to start device auth: %v", err)
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/Azure/go-autorest/autorest/adal"
|
||||
"github.com/Azure/go-autorest/autorest/azure"
|
||||
"github.com/hashicorp/packer/builder/azure/common"
|
||||
"github.com/hashicorp/packer/builder/azure/version"
|
||||
"github.com/hashicorp/packer/helper/useragent"
|
||||
)
|
||||
|
||||
|
@ -142,28 +143,28 @@ func NewAzureClient(subscriptionID, resourceGroupName string,
|
|||
azureClient.DtlVirtualMachineClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.DtlVirtualMachineClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.DtlVirtualMachineClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), templateCapture(azureClient), errorCapture(azureClient))
|
||||
azureClient.DtlVirtualMachineClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.DtlVirtualMachineClient.UserAgent)
|
||||
azureClient.DtlVirtualMachineClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.DtlVirtualMachineClient.UserAgent)
|
||||
azureClient.DtlVirtualMachineClient.Client.PollingDuration = PollingDuration
|
||||
|
||||
azureClient.DtlEnvironmentsClient = dtl.NewEnvironmentsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.DtlEnvironmentsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.DtlEnvironmentsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.DtlEnvironmentsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), templateCapture(azureClient), errorCapture(azureClient))
|
||||
azureClient.DtlEnvironmentsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.DtlEnvironmentsClient.UserAgent)
|
||||
azureClient.DtlEnvironmentsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.DtlEnvironmentsClient.UserAgent)
|
||||
azureClient.DtlEnvironmentsClient.Client.PollingDuration = PollingDuration
|
||||
|
||||
azureClient.DtlLabsClient = dtl.NewLabsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.DtlLabsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.DtlLabsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.DtlLabsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), templateCapture(azureClient), errorCapture(azureClient))
|
||||
azureClient.DtlLabsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.DtlLabsClient.UserAgent)
|
||||
azureClient.DtlLabsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.DtlLabsClient.UserAgent)
|
||||
azureClient.DtlLabsClient.Client.PollingDuration = PollingDuration
|
||||
|
||||
azureClient.DtlCustomImageClient = dtl.NewCustomImagesClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.DtlCustomImageClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.DtlCustomImageClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.DtlCustomImageClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), templateCapture(azureClient), errorCapture(azureClient))
|
||||
azureClient.DtlCustomImageClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.DtlCustomImageClient.UserAgent)
|
||||
azureClient.DtlCustomImageClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.DtlCustomImageClient.UserAgent)
|
||||
azureClient.DtlCustomImageClient.PollingDuration = autorest.DefaultPollingDuration
|
||||
azureClient.DtlCustomImageClient.Client.PollingDuration = PollingDuration
|
||||
|
||||
|
@ -171,14 +172,14 @@ func NewAzureClient(subscriptionID, resourceGroupName string,
|
|||
azureClient.DtlVirtualNetworksClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.DtlVirtualNetworksClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.DtlVirtualNetworksClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), templateCapture(azureClient), errorCapture(azureClient))
|
||||
azureClient.DtlVirtualNetworksClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.DtlVirtualNetworksClient.UserAgent)
|
||||
azureClient.DtlVirtualNetworksClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.DtlVirtualNetworksClient.UserAgent)
|
||||
azureClient.DtlVirtualNetworksClient.Client.PollingDuration = PollingDuration
|
||||
|
||||
azureClient.GalleryImageVersionsClient = newCompute.NewGalleryImageVersionsClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
|
||||
azureClient.GalleryImageVersionsClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.GalleryImageVersionsClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.GalleryImageVersionsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.GalleryImageVersionsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.GalleryImageVersionsClient.UserAgent)
|
||||
azureClient.GalleryImageVersionsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.GalleryImageVersionsClient.UserAgent)
|
||||
azureClient.GalleryImageVersionsClient.Client.PollingDuration = SharedGalleryTimeout
|
||||
azureClient.GalleryImageVersionsClient.Client.PollingDuration = PollingDuration
|
||||
|
||||
|
@ -186,7 +187,7 @@ func NewAzureClient(subscriptionID, resourceGroupName string,
|
|||
azureClient.GalleryImagesClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)
|
||||
azureClient.GalleryImagesClient.RequestInspector = withInspection(maxlen)
|
||||
azureClient.GalleryImagesClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
|
||||
azureClient.GalleryImagesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.GalleryImagesClient.UserAgent)
|
||||
azureClient.GalleryImagesClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(version.AzurePluginVersion.FormattedVersion()), azureClient.GalleryImagesClient.UserAgent)
|
||||
azureClient.GalleryImagesClient.Client.PollingDuration = PollingDuration
|
||||
|
||||
return azureClient, nil
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/helper/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var AzurePluginVersion = version.PluginVersion{
|
||||
Version: packerVersion.Version,
|
||||
VersionPrerelease: packerVersion.VersionPrerelease,
|
||||
}
|
|
@ -17,6 +17,7 @@ import (
|
|||
"google.golang.org/api/option"
|
||||
oslogin "google.golang.org/api/oslogin/v1"
|
||||
|
||||
"github.com/hashicorp/packer/builder/googlecompute/version"
|
||||
"github.com/hashicorp/packer/common/retry"
|
||||
"github.com/hashicorp/packer/helper/useragent"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
|
@ -146,7 +147,7 @@ func NewDriverGCE(config GCEDriverConfig) (Driver, error) {
|
|||
}
|
||||
|
||||
// Set UserAgent
|
||||
service.UserAgent = useragent.String()
|
||||
service.UserAgent = useragent.String(version.GCEPluginVersion.FormattedVersion())
|
||||
|
||||
return &driverGCE{
|
||||
projectId: config.ProjectId,
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/helper/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var GCEPluginVersion = version.PluginVersion{
|
||||
Version: packerVersion.Version,
|
||||
VersionPrerelease: packerVersion.VersionPrerelease,
|
||||
}
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/hashicorp/packer/version"
|
||||
"github.com/hashicorp/packer/builder/linode/version"
|
||||
"github.com/linode/linodego"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ func newLinodeClient(pat string) linodego.Client {
|
|||
|
||||
projectURL := "https://www.packer.io"
|
||||
userAgent := fmt.Sprintf("Packer/%s (+%s) linodego/%s",
|
||||
version.FormattedVersion(), projectURL, linodego.Version)
|
||||
version.LinodePluginVersion.FormattedVersion(), projectURL, linodego.Version)
|
||||
|
||||
client.SetUserAgent(userAgent)
|
||||
return client
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/helper/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var LinodePluginVersion = version.PluginVersion{
|
||||
Version: packerVersion.Version,
|
||||
VersionPrerelease: packerVersion.VersionPrerelease,
|
||||
}
|
|
@ -9,6 +9,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/hashicorp/packer/builder/scaleway/version"
|
||||
"github.com/hashicorp/packer/common"
|
||||
"github.com/hashicorp/packer/common/uuid"
|
||||
"github.com/hashicorp/packer/helper/communicator"
|
||||
|
@ -114,7 +115,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
|||
|
||||
var warnings []string
|
||||
|
||||
c.UserAgent = useragent.String()
|
||||
c.UserAgent = useragent.String(version.ScalewayPluginVersion.FormattedVersion())
|
||||
|
||||
// Deprecated variables
|
||||
if c.Organization == "" {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/helper/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var ScalewayPluginVersion = version.PluginVersion{
|
||||
Version: packerVersion.Version,
|
||||
VersionPrerelease: packerVersion.VersionPrerelease,
|
||||
}
|
|
@ -10,8 +10,8 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/hashicorp/packer/builder/ucloud/version"
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
"github.com/hashicorp/packer/version"
|
||||
"github.com/ucloud/ucloud-sdk-go/external"
|
||||
"github.com/ucloud/ucloud-sdk-go/private/protocol/http"
|
||||
"github.com/ucloud/ucloud-sdk-go/services/uaccount"
|
||||
|
@ -68,7 +68,7 @@ func (c *AccessConfig) Client() (*UCloudClient, error) {
|
|||
cfg.BaseUrl = c.BaseUrl
|
||||
}
|
||||
cfg.LogLevel = log.PanicLevel
|
||||
cfg.UserAgent = fmt.Sprintf("Packer-UCloud/%s", version.FormattedVersion())
|
||||
cfg.UserAgent = fmt.Sprintf("Packer-UCloud/%s", version.UcloudPluginVersion.FormattedVersion())
|
||||
// set default max retry count
|
||||
cfg.MaxRetries = 3
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/helper/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var UcloudPluginVersion = version.PluginVersion{
|
||||
Version: packerVersion.Version,
|
||||
VersionPrerelease: packerVersion.VersionPrerelease,
|
||||
}
|
|
@ -14,6 +14,7 @@ import (
|
|||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
"github.com/hashicorp/packer/builder/yandex/version"
|
||||
"github.com/yandex-cloud/go-genproto/yandex/cloud/compute/v1"
|
||||
"github.com/yandex-cloud/go-genproto/yandex/cloud/endpoint"
|
||||
"github.com/yandex-cloud/go-genproto/yandex/cloud/vpc/v1"
|
||||
|
@ -83,7 +84,7 @@ func NewDriverYC(ui packer.Ui, ac *AccessConfig) (Driver, error) {
|
|||
// Now we will have new request id for every retry attempt.
|
||||
interceptorChain := grpc_middleware.ChainUnaryClient(retryInterceptor, requestIDInterceptor)
|
||||
|
||||
userAgentMD := metadata.Pairs("user-agent", useragent.String())
|
||||
userAgentMD := metadata.Pairs("user-agent", useragent.String(version.YandexPluginVersion.FormattedVersion()))
|
||||
|
||||
sdk, err := ycsdk.Build(context.Background(), sdkConfig,
|
||||
grpc.WithDefaultCallOptions(grpc.Header(&userAgentMD)),
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/helper/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var YandexPluginVersion = version.PluginVersion{
|
||||
Version: packerVersion.Version,
|
||||
VersionPrerelease: packerVersion.VersionPrerelease,
|
||||
}
|
|
@ -3,8 +3,6 @@ package useragent
|
|||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -19,17 +17,10 @@ var (
|
|||
|
||||
// goarch is the architecture - variable for tests.
|
||||
goarch = runtime.GOARCH
|
||||
|
||||
// versionFunc is the func that returns the current version. This is a
|
||||
// function to take into account the different build processes and distinguish
|
||||
// between enterprise and oss builds.
|
||||
versionFunc = func() string {
|
||||
return version.FormattedVersion()
|
||||
}
|
||||
)
|
||||
|
||||
// String returns the consistent user-agent string for Packer.
|
||||
func String() string {
|
||||
func String(packerVersion string) string {
|
||||
return fmt.Sprintf("Packer/%s (+%s; %s; %s/%s)",
|
||||
versionFunc(), projectURL, rt, goos, goarch)
|
||||
packerVersion, projectURL, rt, goos, goarch)
|
||||
}
|
||||
|
|
|
@ -9,9 +9,8 @@ func TestUserAgent(t *testing.T) {
|
|||
rt = "go5.0"
|
||||
goos = "linux"
|
||||
goarch = "amd64"
|
||||
versionFunc = func() string { return "1.2.3" }
|
||||
|
||||
act := String()
|
||||
act := String("1.2.3")
|
||||
|
||||
exp := "Packer/1.2.3 (+https://packer-test.com; go5.0; linux/amd64)"
|
||||
if exp != act {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
// Version helps plugin creators set and track the plugin version using the same
|
||||
// convenience functions used by the Packer core.
|
||||
package version
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
)
|
||||
|
||||
// The git commit that was compiled. This will be filled in by the compiler.
|
||||
var GitCommit string
|
||||
|
||||
type PluginVersion struct {
|
||||
// The main version number that is being run at the moment.
|
||||
Version string
|
||||
// A pre-release marker for the version. If this is "" (empty string)
|
||||
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||
// such as "dev" (in development), "beta", "rc1", etc.
|
||||
VersionPrerelease string
|
||||
}
|
||||
|
||||
func (p *PluginVersion) FormattedVersion() string {
|
||||
var versionString bytes.Buffer
|
||||
fmt.Fprintf(&versionString, "%s", p.Version)
|
||||
if p.VersionPrerelease != "" {
|
||||
fmt.Fprintf(&versionString, "-%s", p.VersionPrerelease)
|
||||
|
||||
if GitCommit != "" {
|
||||
fmt.Fprintf(&versionString, " (%s)", GitCommit)
|
||||
}
|
||||
}
|
||||
|
||||
return versionString.String()
|
||||
}
|
||||
|
||||
func (p *PluginVersion) Semver() *version.Version {
|
||||
// SemVer is an instance of version.Version. This has the secondary
|
||||
// benefit of verifying during tests and init time that our version is a
|
||||
// proper semantic version, which should always be the case.
|
||||
SemVer := version.Must(version.NewVersion(p.Version))
|
||||
return SemVer
|
||||
}
|
||||
|
||||
// String returns the complete version string, including prerelease
|
||||
func (p *PluginVersion) String() string {
|
||||
if p.VersionPrerelease != "" {
|
||||
return fmt.Sprintf("%s-%s", p.Version, p.VersionPrerelease)
|
||||
}
|
||||
return p.Version
|
||||
}
|
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/common/packerbuilderdata"
|
||||
"github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
func boolPointer(tf bool) *bool {
|
||||
|
@ -41,6 +42,7 @@ func testDefaultPackerConfig() map[string]interface{} {
|
|||
return map[string]interface{}{
|
||||
BuildNameConfigKey: "test",
|
||||
BuilderTypeConfigKey: "foo",
|
||||
CoreVersionConfigKey: version.FormattedVersion(),
|
||||
DebugConfigKey: false,
|
||||
ForceConfigKey: false,
|
||||
OnErrorConfigKey: "cleanup",
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
"github.com/hashicorp/packer/helper/config"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/post-processor/artifice"
|
||||
"github.com/hashicorp/packer/version"
|
||||
"github.com/hashicorp/packer/post-processor/exoscale-import/version"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -51,7 +51,7 @@ type Config struct {
|
|||
}
|
||||
|
||||
func init() {
|
||||
egoscale.UserAgent = "Packer-Exoscale/" + version.FormattedVersion() + " " + egoscale.UserAgent
|
||||
egoscale.UserAgent = "Packer-Exoscale/" + version.ExoscaleImportPluginVersion.FormattedVersion() + " " + egoscale.UserAgent
|
||||
}
|
||||
|
||||
type PostProcessor struct {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/helper/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var ExoscaleImportPluginVersion = version.PluginVersion{
|
||||
Version: packerVersion.Version,
|
||||
VersionPrerelease: packerVersion.VersionPrerelease,
|
||||
}
|
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/packer/common/packerbuilderdata"
|
||||
"github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
func TestFuncBuildName(t *testing.T) {
|
||||
|
@ -413,7 +412,9 @@ func TestFuncPackerBuild(t *testing.T) {
|
|||
func TestFuncPackerVersion(t *testing.T) {
|
||||
template := `{{packer_version}}`
|
||||
|
||||
ctx := &Context{}
|
||||
ctx := &Context{
|
||||
CorePackerVersionString: "1.4.3-dev [DEADC0DE]",
|
||||
}
|
||||
i := &I{Value: template}
|
||||
|
||||
result, err := i.Render(ctx)
|
||||
|
@ -422,9 +423,9 @@ func TestFuncPackerVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
// Only match the X.Y.Z portion of the whole version string.
|
||||
if !strings.HasPrefix(result, version.Version) {
|
||||
if !strings.HasPrefix(result, "1.4.3-dev [DEADC0DE]") {
|
||||
t.Fatalf("Expected input to include: %s\n\nGot: %s",
|
||||
version.Version, result)
|
||||
"1.4.3-dev [DEADC0DE]", result)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
pluginVersion "github.com/hashicorp/packer/helper/version"
|
||||
)
|
||||
|
||||
// The git commit that was compiled. This will be filled in by the compiler.
|
||||
|
@ -18,18 +16,13 @@ const Version = "1.6.6"
|
|||
// such as "dev" (in development), "beta", "rc1", etc.
|
||||
const VersionPrerelease = "dev"
|
||||
|
||||
var PackerVersion = pluginVersion.PluginVersion{
|
||||
Version: Version,
|
||||
VersionPrerelease: VersionPrerelease,
|
||||
}
|
||||
|
||||
func FormattedVersion() string {
|
||||
var versionString bytes.Buffer
|
||||
fmt.Fprintf(&versionString, "%s", Version)
|
||||
if VersionPrerelease != "" {
|
||||
fmt.Fprintf(&versionString, "-%s", VersionPrerelease)
|
||||
|
||||
if GitCommit != "" {
|
||||
fmt.Fprintf(&versionString, " (%s)", GitCommit)
|
||||
}
|
||||
}
|
||||
|
||||
return versionString.String()
|
||||
return PackerVersion.FormattedVersion()
|
||||
}
|
||||
|
||||
// SemVer is an instance of version.Version. This has the secondary
|
||||
|
@ -43,8 +36,5 @@ func init() {
|
|||
|
||||
// String returns the complete version string, including prerelease
|
||||
func String() string {
|
||||
if VersionPrerelease != "" {
|
||||
return fmt.Sprintf("%s-%s", Version, VersionPrerelease)
|
||||
}
|
||||
return Version
|
||||
return PackerVersion.String()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue