-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Patryk Strusiewicz-Surmacki <[email protected]>
- Loading branch information
1 parent
2516887
commit 2b2e29c
Showing
3 changed files
with
73 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package clients | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/telekom/das-schiff-network-operator/api/v1alpha1" | ||
"github.com/telekom/das-schiff-network-operator/pkg/agent" | ||
agentpb "github.com/telekom/das-schiff-network-operator/pkg/agent/pb" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
const defaultTimeout = 30 * time.Second | ||
|
||
type Client struct { | ||
agentpb.AgentClient | ||
} | ||
|
||
func NewClient(address string) (agent.Client, error) { | ||
var grpcOpts []grpc.DialOption | ||
grpcOpts = append(grpcOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
conn, err := grpc.NewClient(address, grpcOpts...) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to create gRPC connection: %w", err) | ||
} | ||
|
||
vrfigbpClient := Client{agentpb.NewAgentClient(conn)} | ||
|
||
return &vrfigbpClient, nil | ||
} | ||
|
||
func (c *Client) SendConfig(ctx context.Context, nodeConfig *v1alpha1.NodeConfig) error { | ||
timeoutCtx, cancel := context.WithTimeout(ctx, defaultTimeout) | ||
defer cancel() | ||
|
||
nc := agentpb.NetworkConfiguration{ | ||
Data: []byte{}, | ||
} | ||
data, err := json.Marshal(*nodeConfig) | ||
if err != nil { | ||
return fmt.Errorf("error marshaling NodeConfig: %w", err) | ||
} | ||
|
||
nc.Data = data | ||
|
||
if _, err = c.SetConfiguration(timeoutCtx, &nc); err != nil { | ||
return fmt.Errorf("error setting configuration: %w", err) | ||
} | ||
|
||
return nil | ||
} |