55 "context"
66 "fmt"
77 "sync"
8+ "time"
89
910 "github.com/Azure/azure-sdk-for-go/sdk/azcore"
1011 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
@@ -17,6 +18,7 @@ import (
1718 "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
1819 "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
1920 "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/pageblob"
21+ "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas"
2022 "github.com/sirupsen/logrus"
2123
2224 aztypes "github.com/openshift/installer/pkg/types/azure"
@@ -190,7 +192,7 @@ func CreatePageBlob(ctx context.Context, in *CreatePageBlobInput) (*CreatePageBl
190192 // XXX: Should try all of them until one is successful
191193 sharedKeyCredential , err := azblob .NewSharedKeyCredential (in .StorageAccountName , * in .StorageAccountKeys [0 ].Value )
192194 if err != nil {
193- return nil , fmt .Errorf ("failed to get shared crdentials for storage account: %w" , err )
195+ return nil , fmt .Errorf ("failed to get shared credentials for storage account: %w" , err )
194196 }
195197
196198 logrus .Debugf ("Getting page blob client" )
@@ -326,11 +328,9 @@ func doUploadPagesFromURL(ctx context.Context, pageBlobClient *pageblob.Client,
326328// CreateBlockBlobInput containers the input parameters used for creating a
327329// block blob.
328330type CreateBlockBlobInput struct {
329- StorageURL string
330- BlobURL string
331- //ImageURL string
331+ StorageURL string
332+ BlobURL string
332333 StorageAccountName string
333- //ImageLength int64
334334 BootstrapIgnData []byte
335335 StorageAccountKeys []armstorage.AccountKey
336336 CloudConfiguration cloud.Configuration
@@ -344,13 +344,13 @@ type CreateBlockBlobOutput struct {
344344}
345345
346346// CreateBlockBlob creates a block blob and uploads a file from a URL to it.
347- func CreateBlockBlob (ctx context.Context , in * CreateBlockBlobInput ) (* CreateBlockBlobOutput , error ) {
347+ func CreateBlockBlob (ctx context.Context , in * CreateBlockBlobInput ) (string , error ) {
348348 logrus .Debugf ("Getting block blob credentials" )
349349
350350 // XXX: Should try all of them until one is successful
351351 sharedKeyCredential , err := azblob .NewSharedKeyCredential (in .StorageAccountName , * in .StorageAccountKeys [0 ].Value )
352352 if err != nil {
353- return nil , fmt .Errorf ("failed to get shared crdentials for storage account: %w" , err )
353+ return "" , fmt .Errorf ("failed to get shared crdentials for storage account: %w" , err )
354354 }
355355
356356 logrus .Debugf ("Getting block blob client" )
@@ -364,7 +364,7 @@ func CreateBlockBlob(ctx context.Context, in *CreateBlockBlobInput) (*CreateBloc
364364 },
365365 )
366366 if err != nil {
367- return nil , fmt .Errorf ("failed to get page blob client: %w" , err )
367+ return "" , fmt .Errorf ("failed to get page blob client: %w" , err )
368368 }
369369
370370 logrus .Debugf ("Creating block blob" )
@@ -374,9 +374,13 @@ func CreateBlockBlob(ctx context.Context, in *CreateBlockBlobInput) (*CreateBloc
374374 Tier : & accessTier ,
375375 })
376376 if err != nil {
377- return nil , fmt .Errorf ("failed to create block blob: %w" , err )
377+ return "" , fmt .Errorf ("failed to create block blob: %w" , err )
378+ }
379+
380+ sasURL , err := blockBlobClient .GetSASURL (sas.BlobPermissions {Read : true }, time .Now ().Add (time .Minute * 60 ), & blob.GetSASURLOptions {})
381+ if err != nil {
382+ return "" , fmt .Errorf ("failed to get SAS URL: %w" , err )
378383 }
379384
380- // XXX what more to do here?
381- return nil , nil
385+ return sasURL , nil
382386}
0 commit comments