Skip to content

Commit bc4cd41

Browse files
author
Shailza Thakur
committed
Remove option for service-credentials. Set 3 variables to default properties
1 parent b36dc7b commit bc4cd41

File tree

1 file changed

+21
-63
lines changed

1 file changed

+21
-63
lines changed

code-engine-cos2cos/main.go

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"os"
66

77
"github.com/IBM/ibm-cos-sdk-go/service/s3"
8-
"github.com/joho/godotenv"
98
"ibm.com/codeengine/cos2cos/bucketOperations"
109
"ibm.com/codeengine/cos2cos/process"
1110
)
@@ -16,74 +15,34 @@ import (
1615
func main() {
1716
fmt.Println("Starting application with Job Index:", os.Getenv("JOB_INDEX"))
1817

19-
// Default Values for running the program
20-
// Use service credentials and
21-
var isInCodeEngine bool = true
22-
var isUsingTrustedProfile bool = true
18+
os.Setenv("IBM_COS_CRTokenFilePath_PRIMARY", "/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token")
19+
os.Setenv("IBM_COS_CRTokenFilePath_SECONDARY", "/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token")
20+
os.Setenv("BUCKET_TIMESTAMP_FILENAME", "last_modified_time.json")
2321

24-
// First argument states if the program is running in code engine env. (Default: Yes)
25-
if len(os.Args) > 1 {
26-
isInCodeEngine = os.Args[1] == "true"
27-
if !isInCodeEngine {
28-
os.Setenv("JOB_ARRAY_SIZE", "1")
29-
os.Setenv("JOB_INDEX", "0")
30-
}
31-
}
32-
33-
// Second argument states if the program uses trustedProfile (Default: Yes)
34-
if len(os.Args) > 2 {
35-
isUsingTrustedProfile = os.Args[2] == "true"
36-
}
37-
38-
if !isInCodeEngine {
39-
err := godotenv.Load()
40-
if err != nil {
41-
fmt.Println("Error loading env file")
42-
return
43-
}
44-
}
45-
46-
fmt.Println("Any errors while processing objects:", processingMain(isUsingTrustedProfile))
22+
fmt.Println("Any errors while processing objects:", processingMain())
4723

48-
fmt.Println("Clsoing application")
24+
fmt.Println("Closing application")
4925
}
5026

5127
// Function will initiate the buckets, sessions and trigger the StartProcessing function for actual processing
5228
// accepts a boolean argument which decides how to create COS-Client (Using TrustedProfile or Service Credentials)
53-
func processingMain(useTrustedProfile bool) error {
54-
// fmt.Println("hehe")
55-
29+
func processingMain() error {
5630
var cosClient_PRIMARY, cosClient_SECONDARY *s3.S3
5731

58-
if !useTrustedProfile {
59-
// Create a cosClient using Service Credentials
60-
cosClient_PRIMARY = bucketOperations.NewCosClient(os.Getenv("IBM_COS_API_KEY_PRIMARY"),
61-
os.Getenv("IBM_COS_RESOURCE_INSTANCE_ID_PRIMARY"),
62-
os.Getenv("IBM_COS_ENDPOINT_PRIMARY"),
63-
os.Getenv("IBM_COS_REGION_PRIMARY"),
64-
)
65-
66-
cosClient_SECONDARY = bucketOperations.NewCosClient(os.Getenv("IBM_COS_API_KEY_SECONDARY"),
67-
os.Getenv("IBM_COS_RESOURCE_INSTANCE_ID_SECONDARY"),
68-
os.Getenv("IBM_COS_ENDPOINT_SECONDARY"),
69-
os.Getenv("IBM_COS_REGION_SECONDARY"),
70-
)
71-
} else {
72-
// Create a cosClient using Trusted Profile
73-
cosClient_PRIMARY = bucketOperations.NewCosClientTrustedProfile(os.Getenv("IBM_COS_TRUSTED_PROFILE_ID_PRIMARY"),
74-
os.Getenv("IBM_COS_CRTokenFilePath_PRIMARY"),
75-
os.Getenv("IBM_COS_RESOURCE_INSTANCE_ID_PRIMARY"),
76-
os.Getenv("IBM_COS_ENDPOINT_PRIMARY"),
77-
os.Getenv("IBM_COS_REGION_PRIMARY"),
78-
)
32+
// Create a cosClient using Trusted Profile
33+
cosClient_PRIMARY = bucketOperations.NewCosClientTrustedProfile(os.Getenv("IBM_COS_TRUSTED_PROFILE_ID_PRIMARY"),
34+
os.Getenv("IBM_COS_CRTokenFilePath_PRIMARY"),
35+
os.Getenv("IBM_COS_RESOURCE_INSTANCE_ID_PRIMARY"),
36+
os.Getenv("IBM_COS_ENDPOINT_PRIMARY"),
37+
os.Getenv("IBM_COS_REGION_PRIMARY"),
38+
)
7939

80-
cosClient_SECONDARY = bucketOperations.NewCosClientTrustedProfile(os.Getenv("IBM_COS_TRUSTED_PROFILE_ID_SECONDARY"),
81-
os.Getenv("IBM_COS_CRTokenFilePath_SECONDARY"),
82-
os.Getenv("IBM_COS_RESOURCE_INSTANCE_ID_SECONDARY"),
83-
os.Getenv("IBM_COS_ENDPOINT_SECONDARY"),
84-
os.Getenv("IBM_COS_REGION_SECONDARY"),
85-
)
86-
}
40+
cosClient_SECONDARY = bucketOperations.NewCosClientTrustedProfile(os.Getenv("IBM_COS_TRUSTED_PROFILE_ID_SECONDARY"),
41+
os.Getenv("IBM_COS_CRTokenFilePath_SECONDARY"),
42+
os.Getenv("IBM_COS_RESOURCE_INSTANCE_ID_SECONDARY"),
43+
os.Getenv("IBM_COS_ENDPOINT_SECONDARY"),
44+
os.Getenv("IBM_COS_REGION_SECONDARY"),
45+
)
8746

8847
// Creating Primary bucket instance
8948
primary_bucket := bucketOperations.NewBucket(
@@ -96,15 +55,14 @@ func processingMain(useTrustedProfile bool) error {
9655
os.Getenv("SECONDARY_COS_BUCKET_NAME"),
9756
cosClient_SECONDARY,
9857
)
99-
// fmt.Println("hehe")
10058
// Initiate the process from primary bucket to secondary bucket
10159
// err := process.StartProcessing(primary_bucket, secondary_bucket)
10260
err := process.StartProcessingPagination(primary_bucket, secondary_bucket)
10361
if err != nil {
104-
return fmt.Errorf("\nBackup failed: %v", err)
62+
return fmt.Errorf("\nProcessing failed: %v", err)
10563
}
10664

107-
fmt.Println("\nBackup completed successfully.")
65+
fmt.Println("\nProcessing completed successfully.")
10866

10967
return nil
11068
}

0 commit comments

Comments
 (0)