Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

databrokerglobal/dxc: datasources/host-check.go; 66 LoC #18438

Open
githubvet opened this issue Jan 9, 2021 · 0 comments
Open

databrokerglobal/dxc: datasources/host-check.go; 66 LoC #18438

githubvet opened this issue Jan 9, 2021 · 0 comments
Labels
fresh no one has ever voted on this issue medium between 50-100 lines of code

Comments

@githubvet
Copy link
Collaborator

Found a possible issue in databrokerglobal/dxc at datasources/host-check.go

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

Click here to see the code in its original context.

Click here to show the 66 line(s) of Go which triggered the analyzer.
		for _, datasource := range *datasources {
			notfounderror := errors.New("No file found. Please check filename or path")
			if datasource.Host != "" && datasource.Host != "N/A" && datasource.Name != "" {
				if datasource.Protocol == "LOCAL" {
					path := strings.Replace(datasource.Host, "file://", "", -1)
					_, notfounderror = os.Stat(path)
				} else if datasource.Type == "API" || datasource.Protocol == "HTTP" || datasource.Protocol == "HTTPS" {
					// note we are checking API HOST also as protocol used is HTTP/HTTPS for those datasources
					_, notfounderror = http.Get(datasource.Host)
				} else if datasource.Protocol == "FTP" || datasource.Protocol == "FTPS" {
					filename := path.Base(datasource.Host)
					// get server address and path of file
					server, path, err := getFtpServer(datasource.Protocol, datasource.Host, filename)
					// get client of ftp server
					client, err := ftp.Dial(server)
					if err == nil {
						// now connect to server
						err := client.Login(datasource.Ftpusername, datasource.Ftppassword)
						// Close connection
						defer client.Quit()
						if err == nil {
							// change directory to path
							client.ChangeDir(path)
							// get file entry
							entries, _ := client.List(filename)
							if len(entries) > 0 {
								notfounderror = nil
							}
						}
					}
				} else if datasource.Protocol == "SFTP" {
					filename := path.Base(datasource.Host)
					// get server address and path of file
					server, path, err := getFtpServer(datasource.Protocol, datasource.Host, filename)
					// get client of ftp server
					config := &ssh.ClientConfig{
						User: datasource.Ftpusername,
						Auth: []ssh.AuthMethod{
							ssh.Password(datasource.Ftppassword),
						},
						HostKeyCallback: ssh.InsecureIgnoreHostKey(),
						//Ciphers: []string{"3des-cbc", "aes256-cbc", "aes192-cbc", "aes128-cbc"},
					}
					conn, err := ssh.Dial("tcp", server, config)
					if err == nil {
						client, err := sftp.NewClient(conn)
						// Close connection
						defer client.Close()
						defer conn.Close()
						if err == nil {
							// change directory to path
							cwd, err := client.ReadDir(path) // []os.FileInfo
							if err == nil {
								if contains(cwd, filename) {
									notfounderror = nil
								}
							}
						}
					}
				} else {
					// future implementation dataosurce with streams or other protocols
				}
				datasource.Available = notfounderror == nil
				database.DBInstance.UpdateDatasource(&datasource)
			}
		}
Click here to show extra information the analyzer produced.
No path was found through the callgraph that could lead to a function which writes a pointer argument.

No path was found through the callgraph that could lead to a function which passes a pointer to third-party code.

root signature {UpdateDatasource 1} was not found in the callgraph; reference was passed directly to third-party code

Leave a reaction on this issue to contribute to the project by classifying this instance as a Bug 👎, Mitigated 👍, or Desirable Behavior 🚀
See the descriptions of the classifications here for more information.

commit ID: b30274fcdbfe768b4350f346194abb54776009a0

@githubvet githubvet added fresh no one has ever voted on this issue medium between 50-100 lines of code labels Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fresh no one has ever voted on this issue medium between 50-100 lines of code
Projects
None yet
Development

No branches or pull requests

1 participant