Skip to content

Commit

Permalink
Merge pull request #48 from fqutishat/update
Browse files Browse the repository at this point in the history
feat: add dev mode flag
  • Loading branch information
fqutishat authored Jul 8, 2021
2 parents 9580ec8 + b786a44 commit ff750b2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 526 deletions.
27 changes: 25 additions & 2 deletions cmd/vct/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ const (
tlsServeKeyPathFlagUsage = "Path to the private key to use when serving HTTPS." +
" Alternatively, this can be set with the following environment variable: " + tlsServeKeyPathFlagEnvKey
tlsServeKeyPathFlagEnvKey = envPrefix + "TLS_SERVE_KEY"

devModeFlagName = "dev-mode"
devModeFlagUsage = "Enable dev mode." +
" Alternatively, this can be set with the following environment variable: " + devModeFlagEnvKey
devModeFlagEnvKey = envPrefix + "DEV_MODE"
)

const (
Expand Down Expand Up @@ -198,6 +203,7 @@ type agentParameters struct {
kmsEndpoint string
tlsParams *tlsParameters
server server
devMode bool
}

type tlsParameters struct {
Expand Down Expand Up @@ -253,7 +259,7 @@ func parseLogs(logsRaw string, issuersRaw []string) []command.Log {
return result
}

func createStartCMD(server server) *cobra.Command {
func createStartCMD(server server) *cobra.Command { //nolint: funlen
return &cobra.Command{
Use: "start",
Short: "Starts vct service",
Expand All @@ -267,6 +273,7 @@ func createStartCMD(server server) *cobra.Command {
timeoutStr := getUserSetVarOptional(cmd, timeoutFlagName, timeoutEnvKey)
syncTimeoutStr := getUserSetVarOptional(cmd, syncTimeoutFlagName, syncTimeoutEnvKey)
issuersStr := getUserSetVarOptional(cmd, issuersFlagName, issuersEnvKey)
devModeStr := getUserSetVarOptional(cmd, devModeFlagName, devModeFlagEnvKey)

var issuers []string
if issuersStr != "" {
Expand All @@ -293,6 +300,15 @@ func createStartCMD(server server) *cobra.Command {
return fmt.Errorf("get variable (%s or %s): %w", logsFlagName, logsEnvKey, err)
}

devMode := false

if devModeStr != "" {
devMode, err = strconv.ParseBool(devModeStr)
if err != nil {
return fmt.Errorf("dev mode is not a bool: %w", err)
}
}

parameters := &agentParameters{
server: server,
host: host,
Expand All @@ -304,6 +320,7 @@ func createStartCMD(server server) *cobra.Command {
databasePrefix: databasePrefix,
tlsParams: tlsParams,
baseURL: baseURL,
devMode: devMode,
}

return startAgent(parameters)
Expand Down Expand Up @@ -459,7 +476,7 @@ func startAgent(parameters *agentParameters) error { // nolint: funlen
Crypto: cr,
VDR: vdr.New(
vdr.WithVDR(vdrkey.New()),
vdr.WithVDR(&webVDR{http: httpClient, VDR: vdrweb.New()}),
vdr.WithVDR(&webVDR{http: httpClient, VDR: vdrweb.New(), useHTTPOpt: parameters.devMode}),
),
Logs: parameters.logs,
Key: command.Key{
Expand Down Expand Up @@ -492,9 +509,14 @@ func startAgent(parameters *agentParameters) error { // nolint: funlen
type webVDR struct {
http *http.Client
*vdrweb.VDR
useHTTPOpt bool
}

func (w *webVDR) Read(didID string, opts ...vdrapi.DIDMethodOption) (*did.DocResolution, error) {
if w.useHTTPOpt {
opts = append(opts, vdrapi.WithOption(vdrweb.UseHTTPOpt, true))
}

return w.VDR.Read(didID, append(opts, vdrapi.WithOption(vdrweb.HTTPClientOpt, w.http))...) // nolint: wrapcheck
}

Expand Down Expand Up @@ -613,6 +635,7 @@ func createFlags(startCmd *cobra.Command) {
startCmd.Flags().String(tlsServeCertPathFlagName, "", tlsServeCertPathFlagUsage)
startCmd.Flags().String(tlsServeKeyPathFlagName, "", tlsServeKeyPathFlagUsage)
startCmd.Flags().String(issuersFlagName, "", issuersFlagUsage)
startCmd.Flags().String(devModeFlagName, "", devModeFlagUsage)
}

func getTLS(cmd *cobra.Command) (*tlsParameters, error) {
Expand Down
16 changes: 16 additions & 0 deletions cmd/vct/startcmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
agentHostFlagName = "api-host"
kmsEndpointFlagName = "kms-endpoint"
logsFlagName = "logs"
devModeFlagName = "dev-mode"
issuersFlagName = "issuers"
datasourceNameFlagName = "dsn"
tlsSystemCertPoolFlagName = "tls-systemcertpool"
Expand Down Expand Up @@ -89,6 +90,21 @@ func TestCmd(t *testing.T) {
require.NoError(t, startCmd.Execute())
})

t.Run("wrong dev mode flag", func(t *testing.T) {
startCmd, err := startcmd.Cmd(&mockServer{})
require.NoError(t, err)

args := []string{
"--" + agentHostFlagName, "",
"--" + logsFlagName, "maple2021:rw@localhost:50051",
"--" + devModeFlagName, "wrong",
}
startCmd.SetArgs(args)
err = startCmd.Execute()
require.Error(t, err)
require.Contains(t, err.Error(), "dev mode is not a bool")
})

t.Run("No logs", func(t *testing.T) {
startCmd, err := startcmd.Cmd(&mockServer{})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ require (
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/hyperledger/aries-framework-go v0.1.7-0.20210603061245-f77269180c6f
github.com/hyperledger/aries-framework-go v0.1.7-0.20210708130136-17663938344d
github.com/hyperledger/aries-framework-go-ext/component/storage/couchdb v0.0.0-20210326155331-14f4ca7d75cb
github.com/hyperledger/aries-framework-go-ext/component/storage/mysql v0.0.0-20210527163239-7c95eede0f1c
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20210520055214-ae429bb89bf7
github.com/hyperledger/aries-framework-go/spi v0.0.0-20210520055214-ae429bb89bf7
github.com/lib/pq v1.10.0
github.com/ory/dockertest/v3 v3.6.3
github.com/piprate/json-gold v0.4.0 // indirect
github.com/piprate/json-gold v0.4.0
github.com/prometheus/client_golang v1.10.0
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
Expand Down
Loading

0 comments on commit ff750b2

Please sign in to comment.