Skip to content

Commit

Permalink
Merge pull request hyperledger#69 from kaleido-io/namespace-path
Browse files Browse the repository at this point in the history
Provide a config field for namespace base path
  • Loading branch information
nguyer authored Oct 13, 2023
2 parents b1614c1 + 0dd132f commit b571460
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 41 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
name: build
name: Build

on:
push:
branches:
- "main"
tags:
- "v*"
pull_request:

permissions:
contents: write

jobs:
goreleaser:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -24,11 +22,3 @@ jobs:
with:
go-version: "1.20"
check-latest: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

on:
push:
tags:
- "v*"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 12 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@ builds:
ldflags:
- "-s -w -X 'github.com/hyperledger/firefly-perf-cli/internal/version.Version={{.Version}}' -X 'github.com/hyperledger/firefly-perf-cli/internal/version.Commit={{.Commit}}' -X 'github.com/hyperledger/firefly-perf-cli/internal/version.Date={{.Date}}'"
archives:
- replacements:
darwin: Darwin
linux: Linux
amd64: x86_64
- name_template: >-
{{ .ProjectName }}_{{ .Version }}_
{{- if eq .Os "darwin" }}macOS
{{- else if eq .Os "linux" }}Linux
{{- else }}{{ .Os }}{{ end }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"
release:
prerelease: auto
17 changes: 17 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"path"
"time"

Expand Down Expand Up @@ -212,6 +213,13 @@ func generateRunnerConfigFromInstance(instance *conf.InstanceConfig, perfConfig
runnerConfig.DelinquentAction = deliquentAction
runnerConfig.FFNamespace = instance.FFNamespace
runnerConfig.APIPrefix = instance.APIPrefix
if instance.FFNamespaceBasePath != "" {
basePath, err := url.JoinPath(instance.APIPrefix, instance.FFNamespaceBasePath)
if err != nil {
return nil, err
}
runnerConfig.FFNamespacePath = basePath
}
runnerConfig.MaxTimePerAction = instance.MaxTimePerAction
runnerConfig.MaxActions = instance.MaxActions
runnerConfig.RampLength = instance.RampLength
Expand All @@ -235,6 +243,15 @@ func setDefaults(runnerConfig *conf.RunnerConfig) {
if runnerConfig.FFNamespace == "" {
runnerConfig.FFNamespace = "default"
}

if runnerConfig.FFNamespacePath == "" {
basePath, err := url.JoinPath(runnerConfig.APIPrefix, "api/v1/namespaces", runnerConfig.FFNamespace)
if err != nil {
log.Error(err.Error())
}
runnerConfig.FFNamespacePath = basePath
}

if runnerConfig.TokenOptions.TokenPoolConnectorName == "" {
runnerConfig.TokenOptions.TokenPoolConnectorName = "erc20_erc721"
}
Expand Down
4 changes: 3 additions & 1 deletion internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ type RunnerConfig struct {
Daemon bool
LogEvents bool
SenderURL string
FFNamespace string
APIPrefix string
FFNamespace string
FFNamespacePath string
MaxTimePerAction time.Duration
MaxActions int64
RampLength time.Duration
Expand Down Expand Up @@ -76,6 +77,7 @@ type InstanceConfig struct {
ContractOptions ContractOptions `json:"contractOptions,omitempty" yaml:"contractOptions,omitempty"`
APIPrefix string `json:"apiPrefix,omitempty" yaml:"apiPrefix,omitempty"`
FFNamespace string `json:"fireflyNamespace,omitempty" yaml:"fireflyNamespace,omitempty"`
FFNamespaceBasePath string `json:"namespaceBasePath,omitempty" yaml:"namespaceBasePath,omitempty"`
MaxTimePerAction time.Duration `json:"maxTimePerAction,omitempty" yaml:"maxTimePerAction,omitempty"`
MaxActions int64 `json:"maxActions,omitempty" yaml:"maxActions,omitempty"`
RampLength time.Duration `json:"rampLength,omitempty" yaml:"rampLength,omitempty"`
Expand Down
7 changes: 6 additions & 1 deletion internal/perf/blob_broadcast_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package perf
import (
"fmt"
"math/big"
"net/url"

"github.com/hyperledger/firefly-perf-cli/internal/conf"
"github.com/hyperledger/firefly/pkg/core"
Expand Down Expand Up @@ -52,6 +53,10 @@ func (tc *blobBroadcast) RunOnce() (string, error) {
}`, dataID, fmt.Sprintf("blob_%s_%d", tc.pr.tagPrefix, tc.workerID))
var resMessage core.Message
var resError fftypes.RESTError
fullPath, err := url.JoinPath(tc.pr.client.BaseURL, tc.pr.cfg.FFNamespacePath, "messages/broadcast")
if err != nil {
return "", err
}
res, err := tc.pr.client.R().
SetHeaders(map[string]string{
"Accept": "application/json",
Expand All @@ -60,7 +65,7 @@ func (tc *blobBroadcast) RunOnce() (string, error) {
SetBody([]byte(payload)).
SetResult(&resMessage).
SetError(&resError).
Post(fmt.Sprintf("%s/%sapi/v1/namespaces/%s/messages/broadcast", tc.pr.client.BaseURL, tc.pr.cfg.APIPrefix, tc.pr.cfg.FFNamespace))
Post(fullPath)
if err != nil || res.IsError() {
return "", fmt.Errorf("Error sending broadcast message with blob attachment [%d]: %s (%+v)", resStatus(res), err, &resError)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/perf/blob_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package perf
import (
"fmt"
"math/big"
"net/url"

"github.com/hyperledger/firefly-perf-cli/internal/conf"
"github.com/hyperledger/firefly/pkg/core"
Expand Down Expand Up @@ -59,6 +60,10 @@ func (tc *blobPrivate) RunOnce() (string, error) {
}`, dataID, tc.pr.cfg.RecipientOrg, fmt.Sprintf("blob_%s_%d", tc.pr.tagPrefix, tc.workerID))
var resMessage core.Message
var resError fftypes.RESTError
fullPath, err := url.JoinPath(tc.pr.client.BaseURL, tc.pr.cfg.FFNamespacePath, "messages/private")
if err != nil {
return "", err
}
res, err := tc.pr.client.R().
SetHeaders(map[string]string{
"Accept": "application/json",
Expand All @@ -67,7 +72,7 @@ func (tc *blobPrivate) RunOnce() (string, error) {
SetBody([]byte(payload)).
SetResult(&resMessage).
SetError(&resError).
Post(fmt.Sprintf("%s/%sapi/v1/namespaces/%s/messages/private", tc.pr.client.BaseURL, tc.pr.cfg.APIPrefix, tc.pr.cfg.FFNamespace))
Post(fullPath)
if err != nil || res.IsError() {
return "", fmt.Errorf("Error sending private message with blob attachment [%d]: %s (%+v)", resStatus(res), err, &resError)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/perf/broadcast_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package perf

import (
"fmt"
"net/url"

"github.com/hyperledger/firefly-perf-cli/internal/conf"
"github.com/hyperledger/firefly/pkg/core"
Expand Down Expand Up @@ -47,6 +48,10 @@ func (tc *broadcast) RunOnce() (string, error) {
}`, tc.getMessageString(tc.pr.cfg.MessageOptions.LongMessage), fmt.Sprintf("%s_%d", tc.pr.tagPrefix, tc.workerID))
var resMessage core.Message
var resError fftypes.RESTError
fullPath, err := url.JoinPath(tc.pr.client.BaseURL, tc.pr.cfg.FFNamespacePath, "messages/broadcast")
if err != nil {
return "", err
}
res, err := tc.pr.client.R().
SetHeaders(map[string]string{
"Accept": "application/json",
Expand All @@ -55,7 +60,7 @@ func (tc *broadcast) RunOnce() (string, error) {
SetBody([]byte(payload)).
SetResult(&resMessage).
SetError(&resError).
Post(fmt.Sprintf("%s/%sapi/v1/namespaces/%s/messages/broadcast", tc.pr.client.BaseURL, tc.pr.cfg.APIPrefix, tc.pr.cfg.FFNamespace))
Post(fullPath)
if err != nil || res.IsError() {
return "", fmt.Errorf("Error sending broadcast message [%d]: %s (%+v)", resStatus(res), err, &resError)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/perf/custom_ethereum_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package perf
import (
"encoding/json"
"fmt"
"net/url"
"strconv"

"github.com/hyperledger/firefly-perf-cli/internal/conf"
Expand Down Expand Up @@ -85,6 +86,10 @@ func (tc *customEthereum) RunOnce() (string, error) {
}`, tc.pr.cfg.ContractOptions.Address, tc.workerID, idempotencyKey, invokeOptionsJSON)
var resContractCall map[string]interface{}
var resError fftypes.RESTError
fullPath, err := url.JoinPath(tc.pr.client.BaseURL, tc.pr.cfg.FFNamespacePath, "contracts/invoke")
if err != nil {
return "", err
}
res, err := tc.pr.client.R().
SetHeaders(map[string]string{
"Accept": "application/json",
Expand All @@ -93,7 +98,7 @@ func (tc *customEthereum) RunOnce() (string, error) {
SetBody([]byte(payload)).
SetResult(&resContractCall).
SetError(&resError).
Post(fmt.Sprintf("%s/%sapi/v1/namespaces/%s/contracts/invoke", tc.pr.client.BaseURL, tc.pr.cfg.APIPrefix, tc.pr.cfg.FFNamespace))
Post(fullPath)
if err != nil || res.IsError() {
if res.StatusCode() == 409 {
log.Warnf("Request already received by FireFly: %+v", &resError)
Expand Down
7 changes: 6 additions & 1 deletion internal/perf/custom_fabric_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package perf
import (
"encoding/json"
"fmt"
"net/url"
"strconv"

"github.com/hyperledger/firefly-perf-cli/internal/conf"
Expand Down Expand Up @@ -126,6 +127,10 @@ func (tc *customFabric) RunOnce() (string, error) {
}`, tc.pr.cfg.ContractOptions.Channel, tc.pr.cfg.ContractOptions.Chaincode, idempotencyKey, tc.workerID, tc.pr.cfg.SigningKey, idempotencyKey, invokeOptionsJSON)
var resContractCall map[string]interface{}
var resError fftypes.RESTError
fullPath, err := url.JoinPath(tc.pr.client.BaseURL, tc.pr.cfg.FFNamespacePath, "contracts/invoke")
if err != nil {
return "", err
}
res, err := tc.pr.client.R().
SetHeaders(map[string]string{
"Accept": "application/json",
Expand All @@ -134,7 +139,7 @@ func (tc *customFabric) RunOnce() (string, error) {
SetBody([]byte(payload)).
SetResult(&resContractCall).
SetError(&resError).
Post(fmt.Sprintf("%s/%sapi/v1/namespaces/%s/contracts/invoke", tc.pr.client.BaseURL, tc.pr.cfg.APIPrefix, tc.pr.cfg.FFNamespace))
Post(fullPath)
if err != nil || res.IsError() {
return "", fmt.Errorf("Error invoking contract [%d]: %s (%+v)", resStatus(res), err, &resError)
}
Expand Down
16 changes: 8 additions & 8 deletions internal/perf/perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ func (pr *perfRunner) createMsgConfirmSub(nodeURL, name, tag string) (subID stri
},
Transport: TRANSPORT_TYPE,
}
fullPath, err := url.JoinPath(nodeURL, pr.cfg.APIPrefix, "api/v1/namespaces", pr.cfg.FFNamespace, "subscriptions")
fullPath, err := url.JoinPath(nodeURL, pr.cfg.FFNamespacePath, "subscriptions")
if err != nil {
return "", "", err
}
Expand Down Expand Up @@ -1045,7 +1045,7 @@ func (pr *perfRunner) createEthereumContractListener(nodeURL string) (string, er

var errResponse fftypes.RESTError
var responseBody map[string]interface{}
fullPath, err := url.JoinPath(nodeURL, pr.cfg.APIPrefix, "api/v1/namespaces", pr.cfg.FFNamespace, "contracts/listeners")
fullPath, err := url.JoinPath(nodeURL, pr.cfg.FFNamespacePath, "contracts/listeners")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -1085,7 +1085,7 @@ func (pr *perfRunner) createFabricContractListener(nodeURL string) (string, erro

var errResponse fftypes.RESTError
var responseBody map[string]interface{}
fullPath, err := url.JoinPath(nodeURL, pr.cfg.APIPrefix, "api/v1/namespaces", pr.cfg.FFNamespace, "contracts/listeners")
fullPath, err := url.JoinPath(nodeURL, pr.cfg.FFNamespacePath, "contracts/listeners")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -1116,7 +1116,7 @@ func (pr *perfRunner) createFabricContractListener(nodeURL string) (string, erro
}

func (pr *perfRunner) deleteSubscription(nodeURL string, subscriptionID string) error {
fullPath, err := url.JoinPath(nodeURL, pr.cfg.APIPrefix, "api/v1/namespaces", pr.cfg.FFNamespace, "subscriptions", subscriptionID)
fullPath, err := url.JoinPath(nodeURL, pr.cfg.FFNamespacePath, "subscriptions", subscriptionID)
if err != nil {
return err
}
Expand All @@ -1129,7 +1129,7 @@ func (pr *perfRunner) deleteSubscription(nodeURL string, subscriptionID string)
}

func (pr *perfRunner) deleteContractListener(nodeURL string, listenerID string) error {
fullPath, err := url.JoinPath(nodeURL, pr.cfg.APIPrefix, "api/v1/namespaces", pr.cfg.FFNamespace, "contracts/listeners", listenerID)
fullPath, err := url.JoinPath(nodeURL, pr.cfg.FFNamespacePath, "contracts/listeners", listenerID)
_, err = pr.client.R().
SetHeaders(map[string]string{
"Accept": "application/json",
Expand Down Expand Up @@ -1162,7 +1162,7 @@ func (pr *perfRunner) createContractsSub(nodeURL, listenerID string) (subID stri
},
Transport: TRANSPORT_TYPE,
}
fullPath, err := url.JoinPath(nodeURL, pr.cfg.APIPrefix, "api/v1/namespaces", pr.cfg.FFNamespace, "subscriptions")
fullPath, err := url.JoinPath(nodeURL, pr.cfg.FFNamespacePath, "subscriptions")
if err != nil {
return "", "", err
}
Expand Down Expand Up @@ -1206,7 +1206,7 @@ func (pr *perfRunner) createTokenMintSub(nodeURL string) (subID string, subName
},
Transport: TRANSPORT_TYPE,
}
fullPath, err := url.JoinPath(nodeURL, pr.cfg.APIPrefix, "api/v1/namespaces", pr.cfg.FFNamespace, "subscriptions")
fullPath, err := url.JoinPath(nodeURL, pr.cfg.FFNamespacePath, "subscriptions")
if err != nil {
return "", "", err
}
Expand Down Expand Up @@ -1238,7 +1238,7 @@ func (pr *perfRunner) getMintRecipientBalance() (int, error) {

var response PaginatedResponse
var resError fftypes.RESTError
fullPath, err := url.JoinPath(pr.client.BaseURL, pr.cfg.APIPrefix, "api/v1/namespaces", pr.cfg.FFNamespace, "tokens/balances")
fullPath, err := url.JoinPath(pr.client.BaseURL, pr.cfg.FFNamespacePath, "tokens/balances")
if err != nil {
return 0, nil
}
Expand Down
7 changes: 6 additions & 1 deletion internal/perf/private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package perf

import (
"fmt"
"net/url"

"github.com/hyperledger/firefly-perf-cli/internal/conf"
"github.com/hyperledger/firefly/pkg/core"
Expand Down Expand Up @@ -54,6 +55,10 @@ func (tc *private) RunOnce() (string, error) {
}`, tc.getMessageString(tc.pr.cfg.MessageOptions.LongMessage), tc.pr.cfg.RecipientOrg, fmt.Sprintf("%s_%d", tc.pr.tagPrefix, tc.workerID))
var resMessage core.Message
var resError fftypes.RESTError
fullPath, err := url.JoinPath(tc.pr.client.BaseURL, tc.pr.cfg.FFNamespacePath, "messages/private")
if err != nil {
return "", err
}
res, err := tc.pr.client.R().
SetHeaders(map[string]string{
"Accept": "application/json",
Expand All @@ -62,7 +67,7 @@ func (tc *private) RunOnce() (string, error) {
SetBody([]byte(payload)).
SetResult(&resMessage).
SetError(&resError).
Post(fmt.Sprintf("%s/%sapi/v1/namespaces/%s/messages/private", tc.pr.client.BaseURL, tc.pr.cfg.APIPrefix, tc.pr.cfg.FFNamespace))
Post(fullPath)
if err != nil || res.IsError() {
return "", fmt.Errorf("Error sending private message [%d]: %s (%+v)", resStatus(res), err, &resError)
}
Expand Down
Loading

0 comments on commit b571460

Please sign in to comment.