7
7
"os"
8
8
9
9
"github.com/openshift/ocm-container/pkg/engine"
10
+ log "github.com/sirupsen/logrus"
10
11
)
11
12
12
13
const (
@@ -18,7 +19,7 @@ const (
18
19
)
19
20
20
21
type Config struct {
21
- Token string
22
+ Token string `json:"token"`
22
23
Env map [string ]string
23
24
Mounts []engine.VolumeMount
24
25
}
@@ -48,26 +49,36 @@ func New(home string, rw bool) (*Config, error) {
48
49
49
50
// Else we need to read the token from the file
50
51
t := home + "/" + jiraTokenFile
52
+ log .Debug (fmt .Sprintf ("Jira token ('%v') or authType ('%v') not found in env, reading from file: %v" , token , authType , t ))
51
53
_ , err = os .Stat (t )
52
54
if err != nil {
53
- return config , fmt .Errorf ("error: problem reading Jira token file: %v: %v, err " , t , err )
55
+ return config , fmt .Errorf ("error: problem reading Jira token file: %v: %v" , t , err )
54
56
}
55
57
56
58
f , err := os .Open (t )
57
59
if err != nil {
58
- return config , fmt .Errorf ("error: problem reading Jira token file: %v: %v, err " , t , err )
60
+ return config , fmt .Errorf ("error: problem reading Jira token file: %v: %v" , t , err )
59
61
}
60
62
defer f .Close ()
61
63
62
64
b , err := io .ReadAll (f )
63
65
if err != nil {
64
- return config , fmt .Errorf ("error: problem reading Jira token file: %v: %v, err " , t , err )
66
+ return config , fmt .Errorf ("error: problem reading Jira token file: %v: %v" , t , err )
65
67
}
66
68
67
- json .Unmarshal (b , & token )
68
- config .Env [jiraTokenEnv ] = token
69
+ err = json .Unmarshal (b , & config )
70
+ if err != nil {
71
+ return config , fmt .Errorf ("error: problem reading Jira token file: %v: %v" , t , err )
72
+ }
73
+ config .Env [jiraTokenEnv ] = config .Token
69
74
config .Env [jiraAuthTypeEnv ] = "bearer"
70
75
76
+ log .Debug (fmt .Sprintf ("Using JiraConfig: %v" , config ))
77
+
78
+ if config .Env [jiraTokenEnv ] == "" {
79
+ return config , fmt .Errorf ("error: Jira token not found in env or file: %v" , t )
80
+ }
81
+
71
82
return config , nil
72
83
}
73
84
0 commit comments