-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI supports building in test mode to enable mocking the profile See README for details.
- Loading branch information
1 parent
1e64065
commit 80bbd67
Showing
9 changed files
with
292 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,9 +98,12 @@ jobs: | |
|
||
- name: build the CLI | ||
run: go build . | ||
- name: build the CLI in test mode | ||
run: make build-test | ||
- name: set up the config | ||
run: cp otdfctl-example.yaml otdfctl.yaml | ||
- name: Setup Bats and bats libs | ||
uses: bats-core/[email protected] | ||
- run: tests/encrypt-decrypt.bats | ||
- run: tests/kas-grants.bats | ||
- run: tests/profile.bats |
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
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,74 @@ | ||
package profiles | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/opentdf/otdfctl/pkg/config" | ||
"github.com/zalando/go-keyring" | ||
) | ||
|
||
const testModeMsg = ` | ||
******************** | ||
RUNNING IN TEST MODE | ||
test config: %s | ||
******************** | ||
` | ||
|
||
var ( | ||
testProfile *Profile | ||
testCfg = os.Getenv("OTDFCTL_TEST_PROFILE") | ||
) | ||
|
||
type testConfig struct { | ||
// global config is used to get the store in a bad state | ||
GlobalConfig config.Config `json:"globalConfig,omitempty"` | ||
|
||
// set the default profile | ||
DefaultProfile string `json:"defaultProfile,omitempty"` | ||
|
||
// profiles to add | ||
Profiles []ProfileConfig `json:"profiles,omitempty"` | ||
} | ||
|
||
func init() { | ||
// If running in test mode, use the mock keyring | ||
if config.TestMode == "true" { | ||
fmt.Printf(testModeMsg, testCfg) | ||
|
||
keyring.MockInit() | ||
|
||
// configure the keyring based on the test config | ||
// unmarsal the test config | ||
if testCfg != "" { | ||
var err error | ||
var cfg testConfig | ||
if err := json.NewDecoder(bytes.NewReader([]byte(testCfg))).Decode(&cfg); err != nil { | ||
panic(err) | ||
} | ||
|
||
testProfile, err = New() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, p := range cfg.Profiles { | ||
err := testProfile.AddProfile(p.Name, p.Endpoint, p.TlsNoVerify, cfg.DefaultProfile == p.Name) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// set default | ||
if cfg.DefaultProfile != "" { | ||
if err := testProfile.SetDefaultProfile(cfg.DefaultProfile); err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.