-
Couldn't load subscription status.
- Fork 8
Add validation of cert file path #195
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
base: main
Are you sure you want to change the base?
Changes from all commits
da47ac4
267e7b5
3c3286d
f99c5ab
171d368
928c709
f76f764
c0dc6db
7d93680
6d3cf88
1e953d2
9007e9d
71adb89
57e0768
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||||||||
| // Copyright 2023 LY Corporation | ||||||||||||||||
| // | ||||||||||||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||
| // you may not use this file except in compliance with the License. | ||||||||||||||||
| // You may obtain a copy of the License at | ||||||||||||||||
| // | ||||||||||||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||
| // | ||||||||||||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||||||||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||
| // See the License for the specific language governing permissions and | ||||||||||||||||
| // limitations under the License. | ||||||||||||||||
|
|
||||||||||||||||
| package config | ||||||||||||||||
|
|
||||||||||||||||
| import ( | ||||||||||||||||
| "fmt" | ||||||||||||||||
| "os" | ||||||||||||||||
| "path/filepath" | ||||||||||||||||
|
|
||||||||||||||||
| "golang.org/x/sys/unix" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| func validFilePath(file_path string) error { | ||||||||||||||||
| dir_path := filepath.Dir(file_path) | ||||||||||||||||
| var target_path string | ||||||||||||||||
| _, file_err := os.Stat(file_path) | ||||||||||||||||
| _, dir_err := os.Stat(dir_path) | ||||||||||||||||
|
|
||||||||||||||||
| if file_err == nil { | ||||||||||||||||
| // validate file path | ||||||||||||||||
| target_path = file_path | ||||||||||||||||
| } else if os.IsNotExist(file_err) && dir_err == nil { | ||||||||||||||||
| // validate dir path | ||||||||||||||||
| target_path = dir_path | ||||||||||||||||
| } else { | ||||||||||||||||
| return fmt.Errorf("file path not exist: %w, %w", file_err, dir_err) | ||||||||||||||||
|
||||||||||||||||
| return fmt.Errorf("file path not exist: %w, %w", file_err, dir_err) | |
| return fmt.Errorf("file path does not exist: %w, %w", file_err, dir_err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was wondering if you can write a separate function for this, instead of including within the validFilePath()
func getPath(path string) error, string {
_, err:= os.Stat(filePath)
if err == nil {
return nil, filePath
}
if !os.IsNotExist(err) {
return "", fmt.Errorf("error accessing path '%s': %w", filePath, err)
}
dirPath := filepath.Dir(filePath)
if _, dirErr := osStat(dirPath); dirErr != nil { return "", fmt.Errorf("todo error"); }
return dirPath, nil
}Then just do
if err := unix.Access(getPath(path), unix.W_OK); err != nil {
return fmt.Errorf("file permission error: %w", err)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not write ocmments or good function name so please do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a background why we do this
(Can we have more comments for "why" this function exists)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a why please thanks. Why do we skip for LocalCert Mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits but:
| err := validFilePath(keyFile) | |
| if err != nil { | |
| return err | |
| } | |
| if err := validFilePath(keyFile); err != nil { | |
| return err | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write a comment please.