This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git


The following commit(s) were added to refs/heads/main by this push:
     new 6962ac7  Verify user access to config file (#80)
6962ac7 is described below

commit 6962ac7d32e2d7c148212e8b62c6a3d84890a391
Author: Pearl Dsilva <[email protected]>
AuthorDate: Tue Aug 3 11:04:27 2021 +0530

    Verify user access to config file (#80)
---
 config/config.go | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/config/config.go b/config/config.go
index b64832e..0b82c4d 100644
--- a/config/config.go
+++ b/config/config.go
@@ -97,7 +97,22 @@ func (c Config) CacheFile() string {
        return path.Join(cacheDir, cacheFileName)
 }
 
+func hasAccess(path string) bool {
+       status := true
+       file, err := os.Open(path)
+       if (err != nil) {
+               status = false
+       }
+       file.Close()
+       return status
+}
+
 func checkAndCreateDir(path string) string {
+       isAccsessible := hasAccess(path)
+       if !isAccsessible {
+               fmt.Println("User isn't authorized to access the config file")
+               os.Exit(1)
+       }
        if fileInfo, err := os.Stat(path); os.IsNotExist(err) || 
!fileInfo.IsDir() {
                err := os.Mkdir(path, 0700)
                if err != nil {

Reply via email to