in cmd/make.go [76:178]
func (cookedArgs cookedMakeCmdArgs) process() (err error) {
ctx := context.WithValue(context.TODO(), ste.ServiceAPIVersionOverride, ste.DefaultServiceApiVersion)
resourceStringParts, err := SplitResourceString(cookedArgs.resourceURL.String(), cookedArgs.resourceLocation)
if err != nil {
return err
}
if err := common.VerifyIsURLResolvable(resourceStringParts.Value); cookedArgs.resourceLocation.IsRemote() && err != nil {
return fmt.Errorf("failed to resolve target: %w", err)
}
credentialInfo, _, err := GetCredentialInfoForLocation(ctx, cookedArgs.resourceLocation, resourceStringParts, false, common.CpkOptions{})
if err != nil {
return err
}
var reauthTok *common.ScopedAuthenticator
if at, ok := credentialInfo.OAuthTokenInfo.TokenCredential.(common.AuthenticateToken); ok { // We don't need two different tokens here since it gets passed in just the same either way.
// This will cause a reauth with StorageScope, which is fine, that's the original Authenticate call as it stands.
reauthTok = (*common.ScopedAuthenticator)(common.NewScopedCredential(at, common.ECredentialType.OAuthToken()))
}
// Note : trailing dot is only applicable to file operations anyway, so setting this to false
options := createClientOptions(common.AzcopyCurrentJobLogger, nil, reauthTok)
resourceURL := cookedArgs.resourceURL.String()
cred := credentialInfo.OAuthTokenInfo.TokenCredential
switch cookedArgs.resourceLocation {
case common.ELocation.BlobFS():
var filesystemClient *filesystem.Client
if credentialInfo.CredentialType.IsAzureOAuth() {
filesystemClient, err = filesystem.NewClient(resourceURL, cred, &filesystem.ClientOptions{ClientOptions: options})
} else if credentialInfo.CredentialType.IsSharedKey() {
var sharedKeyCred *azdatalake.SharedKeyCredential
sharedKeyCred, err = common.GetDatalakeSharedKeyCredential()
if err != nil {
return err
}
filesystemClient, err = filesystem.NewClientWithSharedKeyCredential(resourceURL, sharedKeyCred, &filesystem.ClientOptions{ClientOptions: options})
} else {
filesystemClient, err = filesystem.NewClientWithNoCredential(resourceURL, &filesystem.ClientOptions{ClientOptions: options})
}
if err != nil {
return err
}
if _, err = filesystemClient.Create(ctx, nil); err != nil {
// print a nicer error message if container already exists
if datalakeerror.HasCode(err, datalakeerror.FileSystemAlreadyExists) {
return fmt.Errorf("the filesystem already exists")
} else if datalakeerror.HasCode(err, datalakeerror.ResourceNotFound) {
return fmt.Errorf("please specify a valid filesystem URL with corresponding credentials")
}
// print the ugly error if unexpected
return err
}
case common.ELocation.Blob():
// TODO : Ensure it is a container URL here and fail early?
var containerClient *container.Client
if credentialInfo.CredentialType.IsAzureOAuth() {
containerClient, err = container.NewClient(resourceURL, cred, &container.ClientOptions{ClientOptions: options})
} else {
containerClient, err = container.NewClientWithNoCredential(resourceURL, &container.ClientOptions{ClientOptions: options})
}
if err != nil {
return err
}
if _, err = containerClient.Create(ctx, nil); err != nil {
// print a nicer error message if container already exists
if bloberror.HasCode(err, bloberror.ContainerAlreadyExists) {
return fmt.Errorf("the container already exists")
} else if bloberror.HasCode(err, bloberror.ResourceNotFound) {
return fmt.Errorf("please specify a valid container URL with corresponding credentials")
}
// print the ugly error if unexpected
return err
}
case common.ELocation.File():
var shareClient *share.Client
shareClient, err = share.NewClientWithNoCredential(resourceURL, &share.ClientOptions{ClientOptions: options})
if err != nil {
return err
}
quota := &cookedArgs.quota
if quota != nil && *quota == 0 {
quota = nil
}
if _, err = shareClient.Create(ctx, &share.CreateOptions{Quota: quota}); err != nil {
// print a nicer error message if share already exists
if fileerror.HasCode(err, fileerror.ShareAlreadyExists) {
return fmt.Errorf("the file share already exists")
} else if fileerror.HasCode(err, fileerror.ResourceNotFound) {
return fmt.Errorf("please specify a valid share URL with corresponding credentials")
}
// print the ugly error if unexpected
return err
}
default:
return fmt.Errorf("operation not supported, cannot create resource %s type at the moment", cookedArgs.resourceURL.String())
}
return nil
}