Skip to content

Commit 82ca843

Browse files
committed
INFOPLAT-2962 Add deprecation warning for NewStaticAuthHeaderProvider
Adjust return type Small refactor
1 parent 9ef66d9 commit 82ca843

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

pkg/beholder/auth.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"time"
1111

12+
"github.com/smartcontractkit/chainlink-common/pkg/chipingress"
1213
"google.golang.org/grpc"
1314
"google.golang.org/grpc/credentials"
1415
)
@@ -58,10 +59,15 @@ func (p *staticAuth) RequireTransportSecurity() bool {
5859
return p.requireTransportSecurity
5960
}
6061

61-
func NewStaticAuth(headers map[string]string, requireTransportSecurity bool) HeaderProvider {
62+
func NewStaticAuth(headers map[string]string, requireTransportSecurity bool) Auth {
6263
return &staticAuth{headers, requireTransportSecurity}
6364
}
6465

66+
// Deprecated: use NewStaticAuth instead
67+
func NewStaticAuthHeaderProvider(headers map[string]string) chipingress.HeaderProvider {
68+
return &staticAuth{headers: headers}
69+
}
70+
6571
type rotatingAuth struct {
6672
csaPubKey ed25519.PublicKey
6773
signer Signer
@@ -85,18 +91,18 @@ func NewRotatingAuth(csaPubKey ed25519.PublicKey, signer Signer, ttl time.Durati
8591
func (r *rotatingAuth) Headers(ctx context.Context) (map[string]string, error) {
8692
if time.Since(r.lastUpdated) > r.ttl {
8793
// Append timestamp bytes to the public key bytes
88-
timestamp := time.Now().UnixMilli()
89-
timestampBytes := make([]byte, 8)
90-
binary.BigEndian.PutUint64(timestampBytes, uint64(timestamp))
91-
messageBytes := append(r.csaPubKey, timestampBytes...)
94+
ts := time.Now()
95+
tsBytes := make([]byte, 8)
96+
binary.BigEndian.PutUint64(tsBytes, uint64(ts.UnixMilli()))
97+
messageBytes := append(r.csaPubKey, tsBytes...)
9298
// Sign(public key bytes + timestamp bytes)
9399
signature, err := r.signer.Sign(ctx, r.csaPubKey, messageBytes)
94100
if err != nil {
95101
return nil, fmt.Errorf("beholder: failed to sign auth header: %w", err)
96102
}
97103

98-
r.headers[authHeaderKey] = fmt.Sprintf("%s:%x:%d:%x", authHeaderV2, r.csaPubKey, timestamp, signature)
99-
r.lastUpdated = time.Now()
104+
r.headers[authHeaderKey] = fmt.Sprintf("%s:%x:%d:%x", authHeaderV2, r.csaPubKey, ts.UnixMilli(), signature)
105+
r.lastUpdated = ts
100106
}
101107
return r.headers, nil
102108
}

0 commit comments

Comments
 (0)