-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.go
55 lines (43 loc) · 1.13 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import(
"os"
"fmt"
"github.com/forj-oss/goforjj"
"golang.org/x/sys/unix"
)
//IsWritable Linux support only
func isWritable(path string) (res bool) {
return unix.Access(path, unix.W_OK) == nil
}
// reqCheckPath return false if something is wrong.
// check path is writable.
func reqCheckPath(name, path string, ret *goforjj.PluginData) bool {
if path == "" {
ret.ErrorMessage = name + " is empty."
return true
}
if _, err := os.Stat(path); err != nil {
ret.ErrorMessage = fmt.Sprintf(name+" mounted '%s' is inexistent.", path)
return true
}
if !isWritable(path) {
ret.ErrorMessage = fmt.Sprintf(name+" mounted '%s' is NOT writable", path)
return true
}
return false
}
//verifyReqFails verify check params (TODO)
func (gls *GitlabPlugin) verifyReqFails(ret *goforjj.PluginData, check map[string]bool) bool{
if v, ok := check["source"]; ok && v {
if reqCheckPath("source (forjj-source-mount)", gls.sourcePath, ret){
return true
}
}
if v, ok := check["token"]; ok && v {
if gls.token == ""{
ret.ErrorMessage = fmt.Sprint("gitlab token is empty - Required")
return true
}
}
return false
}