forked from edgexfoundry/edgex-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(security): Fix redis start issue edgexfoundry#2863
Now redis starts with conf file with credentials and thus insecure gap is removed - Refactor security-bootstrap-redis to absorbed into security-bootstrapper as one of command - Remove security-bootstrap-redis binary build - Redis db server starts with config file with credentials - Update snaps Closes: edgexfoundry#2863 Signed-off-by: Jim Wang <[email protected]>
- Loading branch information
1 parent
c250855
commit bfc1fc6
Showing
20 changed files
with
587 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
* Copyright 2021 Intel 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 helper | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// MarkComplete creates a doneFile file | ||
func MarkComplete(dirPath, doneFile string) error { | ||
doneFilePath := filepath.Join(dirPath, doneFile) | ||
if !checkIfFileExists(doneFilePath) { | ||
if err := writeFile(doneFilePath); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// CreateDirectoryIfNotExists makes a directory if not exists yet | ||
func CreateDirectoryIfNotExists(dirName string) (err error) { | ||
if _, err = os.Stat(dirName); err == nil { | ||
// already exists, skip | ||
return nil | ||
} else if os.IsNotExist(err) { | ||
// dirName not exists yet, create it | ||
err = os.MkdirAll(dirName, os.ModePerm) | ||
} | ||
|
||
return | ||
} | ||
|
||
func checkIfFileExists(fileName string) bool { | ||
fileInfo, statErr := os.Stat(fileName) | ||
if os.IsNotExist(statErr) { | ||
return false | ||
} | ||
return !fileInfo.IsDir() | ||
} | ||
|
||
func writeFile(aFileName string) error { | ||
timestamp := []byte(strconv.FormatInt(time.Now().Unix(), 10)) | ||
return ioutil.WriteFile(aFileName, timestamp, 0400) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/******************************************************************************* | ||
* Copyright 2021 Intel 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 helper | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMarkComplete(t *testing.T) { | ||
testDir := "testDir" | ||
doneFile := "testDone" | ||
|
||
defer (cleanupDir(testDir))() | ||
|
||
err := os.MkdirAll(testDir, os.ModePerm) | ||
require.NoError(t, err) | ||
|
||
err = MarkComplete(testDir, doneFile) | ||
require.NoError(t, err) | ||
|
||
require.FileExists(t, filepath.Join(testDir, doneFile)) | ||
} | ||
|
||
func TestCreateDirectoryIfNotExists(t *testing.T) { | ||
testDir := "testDirNew" | ||
require.NoDirExists(t, testDir) | ||
defer (cleanupDir(testDir))() | ||
|
||
err := CreateDirectoryIfNotExists(testDir) | ||
require.NoError(t, err) | ||
require.DirExists(t, testDir) | ||
|
||
testPreCreatedDir := "pre-created-dir" | ||
defer (cleanupDir(testPreCreatedDir))() | ||
|
||
err = os.MkdirAll(testPreCreatedDir, os.ModePerm) | ||
require.NoError(t, err) | ||
err = CreateDirectoryIfNotExists(testPreCreatedDir) | ||
require.NoError(t, err) | ||
require.DirExists(t, testPreCreatedDir) | ||
} | ||
|
||
// cleanupDir deletes all files in the directory and files in the directory | ||
func cleanupDir(dir string) func() { | ||
return func() { | ||
_ = os.RemoveAll(dir) | ||
} | ||
} |
Oops, something went wrong.