@@ -23,7 +23,6 @@ import (
23
23
"encoding/json"
24
24
"fmt"
25
25
"io"
26
- "io/ioutil"
27
26
"net"
28
27
"net/http"
29
28
"os"
@@ -1451,7 +1450,7 @@ func (fs *FileSystem) updatePlan(t *bolt.Tx, workspaceId, projectId string, plan
1451
1450
if project .Status [types .ProjectStatusPlanning ] {
1452
1451
return types.ErrorOngoing {Id : projectId }
1453
1452
}
1454
- planBytes , err := ioutil .ReadAll (plan )
1453
+ planBytes , err := io .ReadAll (plan )
1455
1454
if err != nil {
1456
1455
return fmt .Errorf ("failed to read the plan. Error: %q" , err )
1457
1456
}
@@ -1467,7 +1466,7 @@ func (fs *FileSystem) updatePlan(t *bolt.Tx, workspaceId, projectId string, plan
1467
1466
}
1468
1467
// effects
1469
1468
planFilePath := filepath .Join (common .Config .DataDir , PROJECTS_DIR , projectId , INPUTS_DIR , EXPANDED_DIR , M2K_PLAN_FILENAME )
1470
- if err := ioutil .WriteFile (planFilePath , planBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
1469
+ if err := os .WriteFile (planFilePath , planBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
1471
1470
return fmt .Errorf ("failed to write to the plan file at path %s . Error: %q" , planFilePath , err )
1472
1471
}
1473
1472
return nil
@@ -1664,7 +1663,7 @@ func (fs *FileSystem) startTransformation(t *bolt.Tx, workspaceId, projectId str
1664
1663
var planBytes []byte
1665
1664
if plan == nil {
1666
1665
srcPlanPath := filepath .Join (projInputsDir , EXPANDED_DIR , M2K_PLAN_FILENAME )
1667
- planBytes , err = ioutil .ReadFile (srcPlanPath )
1666
+ planBytes , err = os .ReadFile (srcPlanPath )
1668
1667
if err != nil {
1669
1668
err := fmt .Errorf ("failed to read the plan file at path %s . Error: %q" , srcPlanPath , err )
1670
1669
logrus .Error (err )
@@ -1674,7 +1673,7 @@ func (fs *FileSystem) startTransformation(t *bolt.Tx, workspaceId, projectId str
1674
1673
return err
1675
1674
}
1676
1675
} else {
1677
- planBytes , err = ioutil .ReadAll (plan )
1676
+ planBytes , err = io .ReadAll (plan )
1678
1677
if err != nil {
1679
1678
return fmt .Errorf ("failed to read the plan. Error: %q" , err )
1680
1679
}
@@ -1713,7 +1712,7 @@ func (fs *FileSystem) startTransformation(t *bolt.Tx, workspaceId, projectId str
1713
1712
return fmt .Errorf ("failed to make the project output directory at path %s . Error: %q" , currentRunDir , err )
1714
1713
}
1715
1714
planPath := filepath .Join (currentRunDir , M2K_PLAN_FILENAME )
1716
- if err := ioutil .WriteFile (planPath , []byte (planStr ), DEFAULT_FILE_PERMISSIONS ); err != nil {
1715
+ if err := os .WriteFile (planPath , []byte (planStr ), DEFAULT_FILE_PERMISSIONS ); err != nil {
1717
1716
return fmt .Errorf ("failed to write the plan to a file at path %s . Error: %q" , planPath , err )
1718
1717
}
1719
1718
// default is empty string, if the input source is given, the value is updated
@@ -2007,7 +2006,7 @@ func (fs *FileSystem) getQuestion(t *bolt.Tx, workspaceId, projectId, projOutput
2007
2006
return "" , fmt .Errorf ("got an error response status code. Status: %s" , resp .Status )
2008
2007
}
2009
2008
defer resp .Body .Close ()
2010
- respBodyBytes , err := ioutil .ReadAll (resp .Body )
2009
+ respBodyBytes , err := io .ReadAll (resp .Body )
2011
2010
if err != nil {
2012
2011
return "" , fmt .Errorf ("failed to read the response body. Error: %q" , err )
2013
2012
}
@@ -2068,12 +2067,16 @@ func (fs *FileSystem) postSolution(t *bolt.Tx, workspaceId, projectId, projOutpu
2068
2067
}
2069
2068
if resp .StatusCode < 200 || resp .StatusCode > 299 {
2070
2069
if resp .StatusCode == 406 {
2071
- return types.ErrorValidation {Reason : "not a valid answer to the question" }
2070
+ respBodyBytes , err := io .ReadAll (resp .Body )
2071
+ if err != nil {
2072
+ return types.ErrorValidation {Reason : "not a valid answer to the question" }
2073
+ }
2074
+ return types.ErrorValidation {Reason : string (respBodyBytes )}
2072
2075
}
2073
2076
return fmt .Errorf ("got an error response status code. Status: %s" , resp .Status )
2074
2077
}
2075
2078
defer resp .Body .Close ()
2076
- respBodyBytes , err := ioutil .ReadAll (resp .Body )
2079
+ respBodyBytes , err := io .ReadAll (resp .Body )
2077
2080
if err != nil {
2078
2081
return fmt .Errorf ("failed to read the response body. Error: %q" , err )
2079
2082
}
@@ -2526,28 +2529,28 @@ func copyOverPlanConfigAndQACache(srcDir, destDir string) error {
2526
2529
if err != nil {
2527
2530
return fmt .Errorf ("failed to read the plan file at path %s . Error: %q" , planSrcPath , err )
2528
2531
}
2529
- if err := ioutil .WriteFile (planDestPath , planBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
2532
+ if err := os .WriteFile (planDestPath , planBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
2530
2533
return fmt .Errorf ("failed to write the plan file to the path %s . Error: %q" , planDestPath , err )
2531
2534
}
2532
2535
configBytes , err := os .ReadFile (configSrcPath )
2533
2536
if err != nil {
2534
2537
return fmt .Errorf ("failed to read the config file at path %s . Error: %q" , configSrcPath , err )
2535
2538
}
2536
- if err := ioutil .WriteFile (configDestPath , configBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
2539
+ if err := os .WriteFile (configDestPath , configBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
2537
2540
return fmt .Errorf ("failed to write the config file to the path %s . Error: %q" , configDestPath , err )
2538
2541
}
2539
2542
graphBytes , err := os .ReadFile (graphSrcPath )
2540
2543
if err != nil {
2541
2544
return fmt .Errorf ("failed to read the m2k graph file at path %s . Error: %q" , graphSrcPath , err )
2542
2545
}
2543
- if err := ioutil .WriteFile (graphDestPath , graphBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
2546
+ if err := os .WriteFile (graphDestPath , graphBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
2544
2547
return fmt .Errorf ("failed to write the m2k graph file to the path %s . Error: %q" , graphDestPath , err )
2545
2548
}
2546
2549
qaCacheBytes , err := os .ReadFile (qaCacheSrcPath )
2547
2550
if err != nil {
2548
2551
return fmt .Errorf ("failed to read the qa cache file at path %s . Error: %q" , qaCacheSrcPath , err )
2549
2552
}
2550
- if err := ioutil .WriteFile (qaCacheDestPath , qaCacheBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
2553
+ if err := os .WriteFile (qaCacheDestPath , qaCacheBytes , DEFAULT_FILE_PERMISSIONS ); err != nil {
2551
2554
return fmt .Errorf ("failed to write the qa cache file to the path %s . Error: %q" , qaCacheDestPath , err )
2552
2555
}
2553
2556
return nil
@@ -2565,7 +2568,7 @@ func generateVerboseLogs(message string) {
2565
2568
syncLoggingLevel (loggingLevel , message )
2566
2569
}
2567
2570
2568
- //syncLoggingLevel matches log levels of Move2Kube-api and Move2Kube
2571
+ // syncLoggingLevel matches log levels of Move2Kube-api and Move2Kube
2569
2572
func syncLoggingLevel (loggingLevel , message string ) {
2570
2573
switch {
2571
2574
case loggingLevel == "trace" :
@@ -2594,7 +2597,7 @@ func putM2KIgnore(path string) error {
2594
2597
return fmt .Errorf ("failed to create a directory at the path %s . Error: %q" , path , err )
2595
2598
}
2596
2599
m2kIgnorePath := filepath .Join (path , ".m2kignore" )
2597
- if err := ioutil .WriteFile (m2kIgnorePath , []byte ("." ), DEFAULT_FILE_PERMISSIONS ); err != nil {
2600
+ if err := os .WriteFile (m2kIgnorePath , []byte ("." ), DEFAULT_FILE_PERMISSIONS ); err != nil {
2598
2601
return fmt .Errorf ("failed to write a .m2kingore file to the path %s . Error: %q" , m2kIgnorePath , err )
2599
2602
}
2600
2603
return nil
0 commit comments