Skip to content

Commit dd9db10

Browse files
authored
Impl metadata methods 7x (#5565)
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
1 parent 9bfc827 commit dd9db10

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

pkg/plugin/pipedsdk/client.go

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@
1414

1515
package pipedsdk
1616

17-
import "github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
17+
import (
18+
"context"
19+
20+
"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
21+
"github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
22+
)
1823

1924
// Client is a toolkit for interacting with the piped service.
2025
// It provides methods to call the piped service APIs.
2126
// It's a wrapper around the raw piped service client.
2227
type Client struct {
2328
base *pipedapi.PipedServiceClient
2429

30+
// pluginName is used to identify which plugin sends requests to piped.
31+
pluginName string
32+
2533
// applicationID is used to identify the application that the client is working with.
2634
applicationID string
2735
// deploymentID is used to identify the deployment that the client is working with.
@@ -31,3 +39,78 @@ type Client struct {
3139
// This field exists only when the client is working with a specific stage; for example, when this client is passed as the ExecuteStage method's argument.
3240
stageID string
3341
}
42+
43+
// GetStageMetadata gets the metadata of the current stage.
44+
func (c *Client) GetStageMetadata(ctx context.Context, key string) (string, error) {
45+
resp, err := c.base.GetStageMetadata(ctx, &pipedservice.GetStageMetadataRequest{
46+
DeploymentId: c.deploymentID,
47+
StageId: c.stageID,
48+
Key: key,
49+
})
50+
if err != nil {
51+
return "", err
52+
}
53+
return resp.Value, nil
54+
}
55+
56+
// PutStageMetadata stores the metadata of the current stage.
57+
func (c *Client) PutStageMetadata(ctx context.Context, key, value string) error {
58+
_, err := c.base.PutStageMetadata(ctx, &pipedservice.PutStageMetadataRequest{
59+
DeploymentId: c.deploymentID,
60+
StageId: c.stageID,
61+
Key: key,
62+
Value: value,
63+
})
64+
return err
65+
}
66+
67+
// PutStageMetadataMulti stores the multiple metadata of the current stage.
68+
func (c *Client) PutStageMetadataMulti(ctx context.Context, metadata map[string]string) error {
69+
_, err := c.base.PutStageMetadataMulti(ctx, &pipedservice.PutStageMetadataMultiRequest{
70+
DeploymentId: c.deploymentID,
71+
StageId: c.stageID,
72+
Metadata: metadata,
73+
})
74+
return err
75+
}
76+
77+
// GetDeploymentPluginMetadata gets the metadata of the current deployment and plugin.
78+
func (c *Client) GetDeploymentPluginMetadata(ctx context.Context, key string) (string, error) {
79+
resp, err := c.base.GetDeploymentPluginMetadata(ctx, &pipedservice.GetDeploymentPluginMetadataRequest{
80+
DeploymentId: c.deploymentID,
81+
PluginName: c.pluginName,
82+
Key: key,
83+
})
84+
return resp.Value, err
85+
}
86+
87+
// PutDeploymentPluginMetadata stores the metadata of the current deployment and plugin.
88+
func (c *Client) PutDeploymentPluginMetadata(ctx context.Context, key, value string) error {
89+
_, err := c.base.PutDeploymentPluginMetadata(ctx, &pipedservice.PutDeploymentPluginMetadataRequest{
90+
DeploymentId: c.deploymentID,
91+
PluginName: c.pluginName,
92+
Key: key,
93+
Value: value,
94+
})
95+
return err
96+
}
97+
98+
// PutDeploymentPluginMetadataMulti stores the multiple metadata of the current deployment and plugin.
99+
func (c *Client) PutDeploymentPluginMetadataMulti(ctx context.Context, metadata map[string]string) error {
100+
_, err := c.base.PutDeploymentPluginMetadataMulti(ctx, &pipedservice.PutDeploymentPluginMetadataMultiRequest{
101+
DeploymentId: c.deploymentID,
102+
PluginName: c.pluginName,
103+
Metadata: metadata,
104+
})
105+
return err
106+
}
107+
108+
// GetDeploymentSharedMetadata gets the metadata of the current deployment
109+
// which is shared among piped and plugins.
110+
func (c *Client) GetDeploymentSharedMetadata(ctx context.Context, key string) (string, error) {
111+
resp, err := c.base.GetDeploymentSharedMetadata(ctx, &pipedservice.GetDeploymentSharedMetadataRequest{
112+
DeploymentId: c.deploymentID,
113+
Key: key,
114+
})
115+
return resp.Value, err
116+
}

0 commit comments

Comments
 (0)