Skip to content

Commit

Permalink
Merge pull request #61 from TIBCOSoftware/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
torresashjian authored Sep 24, 2019
2 parents f964369 + dec14c8 commit 4720dee
Show file tree
Hide file tree
Showing 65 changed files with 5,986 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ _testmain.go
*.test
*.prof
tags
.vscode/symbols.json
.vscode/*
.build-cache
submodules/flogo-cicd/.build-cache
./Dockerfile
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- "1.11"
- "1.12.9"
script:
- make depend
- make
- make install
13 changes: 13 additions & 0 deletions .whitesource
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scanSettings": {
"configMode": "AUTO",
"configExternalURL": "",
"projectToken" : ""
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ depend-noforce:

.PHONY: install
install: depend-noforce
@GO111MODULE=on go install ./...
GO111MODULE=on go build -o $GOPATH/bin github.com/TIBCOSoftware/dovetail-cli/cmd/dovetail

.PHONY: buildtype
buildtype: install
Expand Down
23 changes: 23 additions & 0 deletions commands/corda/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright © 2018. TIBCO Software Inc.
* This file is subject to the license terms contained
* in the license file that is distributed with this file.
*/

// Package dapp is the one containing all the cli commands for dapp operations
package client

import (
"github.com/spf13/cobra"
)

func init() {
ClientCmd.PersistentFlags().StringP("version", "v", "v1.0.0", "client version")
}

// ClientCmd is the command for client app
var ClientCmd = &cobra.Command{
Use: "client",
Short: "Commands for Client Apps",
Long: `Commands for Client Apps`,
}
114 changes: 114 additions & 0 deletions commands/corda/client/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright © 2018. TIBCO Software Inc.
* This file is subject to the license terms contained
* in the license file that is distributed with this file.
*/

// Package contract is the one containing all the cli commands for contract operations
package client

import (
"fmt"
"os"
"path/filepath"

cordac "github.com/TIBCOSoftware/dovetail-cli/corda/client"
"github.com/TIBCOSoftware/dovetail-cli/model"
"github.com/TIBCOSoftware/dovetail-cli/pkg/contract"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var (
namespace string
target string
caversion string
modelfile string
)

func init() {
ClientCmd.AddCommand(generateCmd)
generateCmd.PersistentFlags().StringP("target", "t", ".", "Destination path for generated artifacts, if a filename is given (With extension) the generated artifacts will compressed as a zip file with the file name provided")
generateCmd.Flags().StringP("namespace", "", "", "CorDapp namespace to generate generic client")
generateCmd.Flags().StringVarP(&modelfile, "modelfile", "m", "", "DApp flow model file to generate generic client")

generateCmd.MarkFlagRequired("target")
generateCmd.MarkFlagRequired("namespace")
generateCmd.MarkFlagRequired("modelfile")
}

var generateCmd = &cobra.Command{
Use: "generate",
Short: "Commands for generating dapp artifacts",
Long: `Commands for generating dapp artifacts`,
Run: func(cmd *cobra.Command, args []string) {

smversion, err := ClientCmd.PersistentFlags().GetString("version")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
caversion = smversion

if modelfile != "" {
err = validateModelFile(modelfile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
namespace, err = cmd.Flags().GetString("namespace")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}

target, err = cmd.Flags().GetString("target")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if target == "" {
target = "./target"
}

target, err = filepath.Abs(target)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

generator, err := createCordaClientGenerator()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

if err := generator.Generate(); err != nil {
fmt.Printf("Error generating the contract: '%s'", err)
os.Exit(1)
}
},
}

func createCordaClientGenerator() (contract.Generator, error) {
if modelfile != "" && namespace == "" {
return nil, fmt.Errorf("namespace is required")
}
options := cordac.NewOptions(modelfile, caversion, target, namespace)
cordaGen := cordac.NewGenerator(options)
return cordaGen, nil
}

func validateModelFile(modelfile string) error {
appConfig, err := model.ParseApp(modelfile)
if err != nil {
return errors.Wrapf(err, "Failed to parse model file %s", modelfile)
}

if len(appConfig.Triggers) == 0 {
return fmt.Errorf("There must be at least one trigger defined in dapp application")
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@
package contract

import (
"fmt"
"strings"

"github.com/TIBCOSoftware/dovetail-cli/config"
"github.com/spf13/cobra"
)

func init() {
ContractCmd.PersistentFlags().StringP("blockchain", "b", config.HYPERLEDGER_FABRIC, fmt.Sprintf("Target blockchain to deploy to (%s)", strings.Join(config.Blockchains(), "|")))
ContractCmd.PersistentFlags().StringP("version", "v", "v1.0.0", "Smart contract version")
ContractCmd.PersistentFlags().StringP("version", "v", "v1.0.0", "Contract version")
}

// ContractCmd is the command for smart contracts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* in the license file that is distributed with this file.
*/

// Package contract is the one containing all the cli commands for contract operations
package contract

import (
Expand All @@ -13,68 +12,54 @@ import (
"path/filepath"
"strings"

"github.com/TIBCOSoftware/dovetail-cli/config"
corda "github.com/TIBCOSoftware/dovetail-cli/corda/contract"
fabric "github.com/TIBCOSoftware/dovetail-cli/hyperledger-fabric/contract"
"github.com/TIBCOSoftware/dovetail-cli/model"
"github.com/TIBCOSoftware/dovetail-cli/pkg/contract"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var (
cordaState string
cordaCommands string
cordaNS string
target string
blockchain string
smversion string
modelfile string
enableTxnSecurity bool
cordaState string
cordaCommands string
cordaNS string
target string
cversion string
modelfile string
)

func init() {
ContractCmd.AddCommand(generateCmd)
generateCmd.PersistentFlags().StringP("target", "t", ".", "Destination path for generated artifacts, if a filename is given (With extension) the generated artifacts will compressed as a zip file with the file name provided")
generateCmd.Flags().StringP("state", "", "", "Corda only, optional, specify asset name to generate contract state, default to all assets in the specified namespace")
generateCmd.Flags().StringP("commands", "", "", "Corda only, optional, comma delimited list of transactions(commands) allowed for the selected state txn1,txn2,..., default to all transactions")
generateCmd.Flags().StringP("namespace", "", "", "Corda only, required, composer model namespace")
generateCmd.Flags().BoolP("enableTransactionSecurity", "", false, "true to enable transaction level security for the targetd blockchain if supported")
generateCmd.Flags().StringP("state", "", "", "Optional, specify asset name to generate contract state, default to all assets in the specified namespace")
generateCmd.Flags().StringP("commands", "", "", "Optional, comma delimited list of transactions(commands) allowed for the selected state txn1,txn2,..., default to all transactions")
generateCmd.Flags().StringP("namespace", "", "", "Required, composer model namespace")
generateCmd.Flags().StringVarP(&modelfile, "modelfile", "m", "", "Smart contract flow model file")

generateCmd.MarkFlagRequired("target")
generateCmd.MarkFlagRequired("modelfile")
generateCmd.MarkFlagRequired("namespace")
}

var generateCmd = &cobra.Command{
Use: "generate",
Short: "Commands for generating smart contract artifacts",
Long: `Commands for generating smart contract artifacts`,
Short: "Commands for generating contract artifacts",
Long: `Commands for generating contract artifacts`,
Run: func(cmd *cobra.Command, args []string) {
blockchain, err := ContractCmd.PersistentFlags().GetString("blockchain")
if err != nil {
fmt.Println(err)
os.Exit(1)
}

smversion, err = ContractCmd.PersistentFlags().GetString("version")
smversion, err := ContractCmd.PersistentFlags().GetString("version")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
cversion = smversion

err = validateModelFile(modelfile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

enableTxnSecurity, err = cmd.Flags().GetBool("enableTransactionSecurity")
if err != nil {
fmt.Println(err)
os.Exit(1)
}

cordaState, err = cmd.Flags().GetString("state")
if err != nil {
fmt.Println(err)
Expand All @@ -97,15 +82,16 @@ var generateCmd = &cobra.Command{
os.Exit(1)
}
if target == "" {
target = "./dovetail_generated"
target = "./target"
}

target, err = filepath.Abs(target)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

generator, err := GetGenerator(blockchain)
generator, err := createCordaGenerator()
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -117,25 +103,6 @@ var generateCmd = &cobra.Command{
},
}

// GetGenerator chooses the right generator
func GetGenerator(blockchain string) (contract.Generator, error) {
switch strings.ToUpper(blockchain) {
case strings.ToUpper(config.HYPERLEDGER_FABRIC):
return createFabricGenerator()
case strings.ToUpper(config.CORDA):
return createCordaGenerator()
default:
return nil, fmt.Errorf("Unsupported blockchain to deploy '%s'", blockchain)
}
}

func createFabricGenerator() (contract.Generator, error) {
options := fabric.NewGenOptions(target, modelfile, smversion, enableTxnSecurity)

fabricGen := fabric.NewGenerator(options)
return fabricGen, nil
}

func createCordaGenerator() (contract.Generator, error) {
if cordaNS == "" {
return nil, fmt.Errorf("namespace is required")
Expand All @@ -148,7 +115,7 @@ func createCordaGenerator() (contract.Generator, error) {
}
}

options := corda.NewOptions(modelfile, smversion, cordaState, cmds, target, cordaNS)
options := corda.NewOptions(modelfile, cversion, cordaState, cmds, target, cordaNS)
cordaGen := corda.NewGenerator(options)
return cordaGen, nil
}
Expand All @@ -159,8 +126,8 @@ func validateModelFile(modelfile string) error {
return errors.Wrapf(err, "Failed to parse model file %s", modelfile)
}

if len(appConfig.Triggers) == 0 || len(appConfig.Triggers) > 1 {
return fmt.Errorf("There must be one and only one trigger defined in smart contract application")
if len(appConfig.Triggers) == 0 {
return fmt.Errorf("There must be at least one trigger defined in smart contract application")
}

return nil
Expand Down
29 changes: 29 additions & 0 deletions commands/corda/corda.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright © 2018. TIBCO Software Inc.
* This file is subject to the license terms contained
* in the license file that is distributed with this file.
*/

// Package corda is the one containing all the cli commands for corda operations
package corda

import (
"github.com/spf13/cobra"

"github.com/TIBCOSoftware/dovetail-cli/commands/corda/client"
"github.com/TIBCOSoftware/dovetail-cli/commands/corda/contract"
"github.com/TIBCOSoftware/dovetail-cli/commands/corda/dapp"
)

func init() {
CordaCmd.AddCommand(client.ClientCmd)
CordaCmd.AddCommand(contract.ContractCmd)
CordaCmd.AddCommand(dapp.DAppCmd)
}

// CordaCmd is the command for smart contracts
var CordaCmd = &cobra.Command{
Use: "corda",
Short: "Commands for Corda apps",
Long: `Commands for Corda apps`,
}
Loading

0 comments on commit 4720dee

Please sign in to comment.