Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>
  • Loading branch information
mabhi committed Nov 8, 2023
1 parent b9e2292 commit d6ae3ba
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 97 deletions.
5 changes: 0 additions & 5 deletions pkg/blockstorage/azure/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ type AzureAuthenticator interface {
}

func NewAzureAuthenticator(config map[string]string) (AzureAuthenticator, error) {
// NewAzureAuthenticator opens up the possibility to Auth with:
//1. Env variables
//2. Managed Identity
//3. Workload Identity
//4. AzureCli
switch {
case isMSICredsAvailable(config):
return &MsiAuthenticator{}, nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/blockstorage/azure/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (s *AdStorage) SnapshotCopyWithArgs(ctx context.Context, from blockstorage.
if err != nil {
return nil, errors.Wrap(err, "Poller failed to retrieve snapshot")
}
snap, err := s.SnapshotGet(ctx, blockstorage.String(createSnapRes.ID))
snap, err := s.SnapshotGet(ctx, blockstorage.StringFromPtr(createSnapRes.ID))
if err != nil {
return nil, errors.Wrapf(err, "Failed to Get Snapshot after create, snaphotName %s", snapName)
}
Expand Down Expand Up @@ -379,21 +379,21 @@ func (s *AdStorage) VolumeParse(ctx context.Context, volume interface{}) (*block
if vol.Tags != nil {
tags = blockstorage.StringMap(vol.Tags)
}
az := blockstorage.String(vol.Location)
az := blockstorage.StringFromPtr(vol.Location)
if z := vol.Zones; len(z) > 0 {
az = az + "-" + *(z[0])
}

return &blockstorage.Volume{
Type: s.Type(),
ID: blockstorage.String(vol.ID),
ID: blockstorage.StringFromPtr(vol.ID),
Encrypted: encrypted,
SizeInBytes: blockstorage.Int64(vol.Properties.DiskSizeBytes),
Az: az,
Tags: blockstorage.MapToKeyValue(tags),
VolumeType: string(*vol.SKU.Name),
CreationTime: blockstorage.TimeStamp(*vol.Properties.TimeCreated),
Attributes: map[string]string{"Users": blockstorage.String(vol.ManagedBy)},
Attributes: map[string]string{"Users": blockstorage.StringFromPtr(vol.ManagedBy)},
}, nil
}

Expand Down
38 changes: 0 additions & 38 deletions pkg/blockstorage/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ func (h *HelperSuite) TestStringSlice(c *C) {
c.Assert(target[1], Equals, source[1])
}

func (s *HelperSuite) TestStringSlicePtr(c *C) {
source := []string{"test1", "test2"}
res := StringSlicePtr(source)
target := *res
c.Assert(target[0], Equals, source[0])
c.Assert(target[1], Equals, source[1])
}

func (s *HelperSuite) TestSliceStringPtr(c *C) {
source := []string{"test1", "test2"}
res := SliceStringPtr(source)
Expand All @@ -35,18 +27,6 @@ func (s *HelperSuite) TestSliceStringPtr(c *C) {
}
}

func (s *HelperSuite) TestBoolFromPtr(c *C) {
source := true
target := Bool(&source)
c.Assert(target, Equals, source)
}

func (s *HelperSuite) TestBoolToPtr(c *C) {
source := true
target := BoolPtr(source)
c.Assert(*target, Equals, source)
}

func (s *HelperSuite) TestIntFromPtr(c *C) {
source := 1
target := Int(&source)
Expand All @@ -59,24 +39,6 @@ func (s *HelperSuite) TestIntToPtr(c *C) {
c.Assert(*target, Equals, source)
}

func (s *HelperSuite) TestFloat32FromPtr(c *C) {
source := float32(1)
target := Float32(&source)
c.Assert(target, Equals, source)
}

func (s *HelperSuite) TestFloat32ToPtr(c *C) {
source := float32(1)
target := Float32Ptr(source)
c.Assert(*target, Equals, source)
}

func (s *HelperSuite) TestStringFromPtr(c *C) {
source := "test"
target := String(&source)
c.Assert(target, Equals, source)
}

func (s *HelperSuite) TestStringToPtr(c *C) {
source := "test"
target := StringPtr(source)
Expand Down
51 changes: 1 addition & 50 deletions pkg/blockstorage/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ func StringSlice(s *[]string) []string {
return nil
}

// StringSlicePtr returns a pointer to the passed string slice.
func StringSlicePtr(s []string) *[]string {
return azto.Ptr(s)
}

// SliceStringPtr returns a slice of string pointers from the passed string slice.
func SliceStringPtr(s []string) []*string {
ms := make([]*string, len(s))
Expand All @@ -155,19 +150,6 @@ func SliceStringPtr(s []string) []*string {
return ms
}

// Bool returns a bool value for the passed bool pointer. It returns false if the pointer is nil.
func Bool(b *bool) bool {
if b != nil {
return *b
}
return false
}

// BoolPtr returns a pointer to the passed bool.
func BoolPtr(b bool) *bool {
return &b
}

// Int returns an int value for the passed int pointer. It returns 0 if the pointer is nil.
func Int(i *int) int {
if i != nil {
Expand Down Expand Up @@ -202,40 +184,9 @@ func Int64(i *int64) int64 {
return 0
}

// Int64Ptr returns a pointer to the passed int64.
func Int64Ptr(i int64) *int64 {
return &i
}

// Float32 returns an int value for the passed int pointer. It returns 0.0 if the pointer is nil.
func Float32(i *float32) float32 {
if i != nil {
return *i
}
return 0.0
}

// Float32Ptr returns a pointer to the passed float32.
func Float32Ptr(i float32) *float32 {
return &i
}

// ToFloat64 returns an int value for the passed int pointer. It returns 0.0 if the pointer is nil.
func Float64(i *float64) float64 {
if i != nil {
return *i
}
return 0.0
}

// Float64Ptr returns a pointer to the passed float64.
func Float64Ptr(i float64) *float64 {
return &i
}

// String returns a string value for the passed string pointer. It returns the empty string if the
// pointer is nil.
func String(s *string) string {
func StringFromPtr(s *string) string {
if s != nil {
return *s
}
Expand Down

0 comments on commit d6ae3ba

Please sign in to comment.