Skip to content

Commit

Permalink
Merge pull request #108 from HewlettPackard/fix_lint
Browse files Browse the repository at this point in the history
 Fix Lint issues
  • Loading branch information
gandharvas authored Feb 4, 2022
2 parents 2bd3149 + 72dfe32 commit e0731a4
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 15 deletions.
6 changes: 5 additions & 1 deletion internal/acceptance_test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) {
}

apiClient := api_client.NewAPIClient(&cfg)
apiClient.SetMeta(nil, func(ctx *context.Context, meta interface{}) {
err := apiClient.SetMeta(nil, func(ctx *context.Context, meta interface{}) {
d := &utils.ResourceData{
Data: map[string]interface{}{
"iam_service_url": os.Getenv("HPEGL_IAM_SERVICE_URL"),
Expand Down Expand Up @@ -64,6 +64,10 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) {
}
})

if err != nil {
log.Printf("[WARN] Error: %s", err)
}

return apiClient, cfg
}

Expand Down
5 changes: 4 additions & 1 deletion internal/cmp/cloud_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ func (f *cloudFolder) Read(ctx context.Context, d *utils.Data, meta interface{})

for _, cf := range folders.Folders {
if cf.Name == name {
d.Set("code", cf.ExternalID)
err = d.Set("code", cf.ExternalID)
if err != nil {
return err
}
d.SetID(cf.ID)

return nil
Expand Down
5 changes: 4 additions & 1 deletion internal/cmp/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func (n *domain) Read(ctx context.Context, d *utils.Data, meta interface{}) erro
return errors.New("error coudn't find exact domain, please check the name")
}

tftags.Set(d, domains.NetworkDomains[0])
err = tftags.Set(d, domains.NetworkDomains[0])
if err != nil {
return err
}

// post check
return d.Error()
Expand Down
15 changes: 12 additions & 3 deletions internal/cmp/instance_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func readInstance(ctx context.Context, sharedClient instanceSharedClient, d *uti
})

if isClone {
d.Set("layout_id", instance.Instance.Layout.ID)
err = d.Set("layout_id", instance.Instance.Layout.ID)
if err != nil {
return err
}
}

tfInstance.Network, err = instanceGetNetworkModel(tfInstance.Network, serverRetry)
Expand All @@ -83,7 +86,10 @@ func readInstance(ctx context.Context, sharedClient instanceSharedClient, d *uti
tfInstance.History = instanceGetHistoryModel(historyRetry)
tfInstance.Containers = instance.Instance.ContainerDetails

tftags.Set(d, tfInstance)
err = tftags.Set(d, tfInstance)
if err != nil {
return err
}

d.SetID(instance.Instance.ID)

Expand Down Expand Up @@ -542,7 +548,10 @@ func instanceSetServerID(ctx context.Context, d *utils.Data, sharedClient instan
if len(servers.Server) != 1 {
return fmt.Errorf(errExactMatch, "server")
}
d.Set("server_id", servers.Server[0].ID)
err = d.Set("server_id", servers.Server[0].ID)
if err != nil {
return err
}

return nil
}
Expand Down
5 changes: 4 additions & 1 deletion internal/cmp/network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func (c *networkInterface) Read(ctx context.Context, d *utils.Data, meta interfa

for _, n := range networkInterface.Data.NetworkTypes {
if n.Name == name {
d.Set("code", n.Code)
err = d.Set("code", n.Code)
if err != nil {
return err
}
d.SetID(n.ID)

return d.Error()
Expand Down
6 changes: 4 additions & 2 deletions internal/cmp/network_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ func newNetworkProxy(nClient *client.NetworksAPIService) *networkProxy {
func (n *networkProxy) Read(ctx context.Context, d *utils.Data, meta interface{}) error {
setMeta(meta, n.nClient.Client)
tfProxy := models.GetNetworkProxy{}
tftags.Get(d, &tfProxy)

err := tftags.Get(d, &tfProxy)
if err != nil {
return err
}
proxyResp, err := n.nClient.GetNetworkProxy(ctx, map[string]string{
nameKey: tfProxy.Name,
})
Expand Down
14 changes: 10 additions & 4 deletions internal/cmp/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func (r *router) Create(ctx context.Context, d *utils.Data, meta interface{}) er
return err
}
// align createReq and fill json related fields
r.routerAlignRouterRequest(ctx, meta, &createReq)

if err := r.routerAlignRouterRequest(ctx, meta, &createReq); err != nil {
return err
}
routerResp, err := r.rClient.CreateRouter(ctx, createReq)
if err != nil {
return err
Expand All @@ -60,9 +61,12 @@ func (r *router) Create(ctx context.Context, d *utils.Data, meta interface{}) er
return response.(models.GetSpecificRouterResp).NetworkRouter.Status == "ok", nil
},
}
retry.Retry(ctx, meta, func(ctx context.Context) (interface{}, error) {
_, err = retry.Retry(ctx, meta, func(ctx context.Context) (interface{}, error) {
return r.rClient.GetSpecificRouter(ctx, routerResp.ID)
})
if err != nil {
return err
}

return tftags.Set(d, createReq.NetworkRouter)
}
Expand All @@ -73,7 +77,9 @@ func (r *router) Update(ctx context.Context, d *utils.Data, meta interface{}) er
return err
}
// align createReq and fill json related fields
r.routerAlignRouterRequest(ctx, meta, &createReq)
if err := r.routerAlignRouterRequest(ctx, meta, &createReq); err != nil {
return err
}

// HaMode cannot be updated, setting it to empty so that it is ignored in the API Payload.
createReq.NetworkRouter.Config.HaMode = ""
Expand Down
6 changes: 5 additions & 1 deletion pkg/atf/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/md5"
"encoding/json"
"fmt"
"log"
"math/rand"
"runtime"
"strconv"
Expand Down Expand Up @@ -87,7 +88,10 @@ func toInt(str string) int {
func newRand() *rand.Rand {
s := myCaller()
m := md5.New()
m.Write([]byte(s))
_, err := m.Write([]byte(s))
if err != nil {
log.Printf("[WARN]: Error while writing to Hash object %s", err)
}
sourceStr := m.Sum(nil)
var sourceInt int64
for _, i := range sourceStr {
Expand Down
6 changes: 5 additions & 1 deletion pkg/utils/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func SetMeta(apiClient *client.APIClient, r *schema.ResourceData) {
apiClient.SetMeta(nil, func(ctx *context.Context, meta interface{}) {
err := apiClient.SetMeta(nil, func(ctx *context.Context, meta interface{}) {
// Initialise token handler
h, err := serviceclient.NewHandler(r)
if err != nil {
Expand All @@ -27,4 +27,8 @@ func SetMeta(apiClient *client.APIClient, r *schema.ResourceData) {
*ctx = context.WithValue(*ctx, client.ContextAccessToken, token)
}
})

if err != nil {
log.Printf("[WARN] Error: %s", err)
}
}

0 comments on commit e0731a4

Please sign in to comment.