File tree 1 file changed +18
-2
lines changed
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -73,14 +73,14 @@ func init() {
73
73
}
74
74
75
75
func configureProvider (d * schema.ResourceData ) (interface {}, error ) {
76
- usr , err := user . Current ()
76
+ userHome , err := currentUserHome ()
77
77
if err != nil {
78
78
log .Fatal (err )
79
79
}
80
80
config := Config {
81
81
Endpoint : d .Get ("endpoint" ).(string ),
82
82
}
83
- configFile := fmt .Sprintf ("%s/.ovh.conf" , usr . HomeDir )
83
+ configFile := fmt .Sprintf ("%s/.ovh.conf" , userHome )
84
84
if _ , err := os .Stat (configFile ); err == nil {
85
85
c , err := ini .Load (configFile )
86
86
if err != nil {
@@ -111,3 +111,19 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) {
111
111
112
112
return & config , nil
113
113
}
114
+
115
+ // currentUserHome attempts to get current user's home directory
116
+ func currentUserHome () (string , error ) {
117
+ userHome := ""
118
+ usr , err := user .Current ()
119
+ if err != nil {
120
+ // Fallback by trying to read $HOME
121
+ userHome = os .Getenv ("HOME" )
122
+ if userHome != "" {
123
+ err = nil
124
+ }
125
+ } else {
126
+ userHome = usr .HomeDir
127
+ }
128
+ return userHome , nil
129
+ }
You can’t perform that action at this time.
0 commit comments