Skip to content

Commit f043058

Browse files
committed
add fetch and update helper functions
Signed-off-by: dimaxgl <[email protected]>
1 parent 9944841 commit f043058

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

internal/osnadmin/update.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package osnadmin
22

33
import (
44
"bytes"
5+
"context"
56
"crypto/tls"
67
"crypto/x509"
78
"fmt"
@@ -10,18 +11,18 @@ import (
1011
)
1112

1213
// Update channel configuration using presented config envelope.
13-
func Update(osnURL, channelID string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate, configEnvelope []byte) (*http.Response, error) {
14+
func Update(ctx context.Context, osnURL, channelID string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate, configEnvelope []byte) (*http.Response, error) {
1415
url := fmt.Sprintf("%s/participation/v1/channels/%s", osnURL, channelID)
1516

16-
req, err := createUpdateRequest(url, configEnvelope)
17+
req, err := createUpdateRequest(ctx, url, configEnvelope)
1718
if err != nil {
1819
return nil, fmt.Errorf("create update request: %w", err)
1920
}
2021

2122
return httpDo(req, caCertPool, tlsClientCert)
2223
}
2324

24-
func createUpdateRequest(url string, configEnvelope []byte) (*http.Request, error) {
25+
func createUpdateRequest(ctx context.Context, url string, configEnvelope []byte) (*http.Request, error) {
2526
joinBody := new(bytes.Buffer)
2627
writer := multipart.NewWriter(joinBody)
2728
part, err := writer.CreateFormFile("config-update-envelope", "config_update.pb")
@@ -37,7 +38,7 @@ func createUpdateRequest(url string, configEnvelope []byte) (*http.Request, erro
3738
return nil, err
3839
}
3940

40-
req, err := http.NewRequest(http.MethodPut, url, joinBody)
41+
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, joinBody)
4142
if err != nil {
4243
return nil, err
4344
}

pkg/channel/channel.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"github.com/hyperledger/fabric-admin-sdk/internal/protoutil"
1414
"github.com/hyperledger/fabric-admin-sdk/pkg/identity"
1515
"github.com/hyperledger/fabric-admin-sdk/pkg/internal/proposal"
16-
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
1716

1817
cb "github.com/hyperledger/fabric-protos-go-apiv2/common"
18+
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
1919
"google.golang.org/grpc"
2020
"google.golang.org/protobuf/proto"
2121
)
@@ -110,3 +110,8 @@ func ListChannelOnPeer(ctx context.Context, connection grpc.ClientConnInterface,
110110
}
111111
return channelQueryResponse.GetChannels(), nil
112112
}
113+
114+
func UpdateChannel(ctx context.Context, osnURL string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate, channelName string, env *cb.Envelope) (*http.Response, error) {
115+
envelopeBytes := protoutil.MarshalOrPanic(env)
116+
return osnadmin.Update(ctx, osnURL, channelName, caCertPool, tlsClientCert, envelopeBytes)
117+
}

0 commit comments

Comments
 (0)