Skip to content

[sdk] Add 7 metadataStore methods to Client #5565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 84 additions & 1 deletion pkg/plugin/pipedsdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@

package pipedsdk

import "github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
import (
"context"

"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
"github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
)

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

// pluginName is used to identify which plugin sends requests to piped.
pluginName string

// applicationID is used to identify the application that the client is working with.
applicationID string
// deploymentID is used to identify the deployment that the client is working with.
Expand All @@ -31,3 +39,78 @@
// 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.
stageID string
}

// GetStageMetadata gets the metadata of the current stage.
func (c *Client) GetStageMetadata(ctx context.Context, key string) (string, error) {
resp, err := c.base.GetStageMetadata(ctx, &pipedservice.GetStageMetadataRequest{
DeploymentId: c.deploymentID,
StageId: c.stageID,
Key: key,
})
if err != nil {
return "", err
}
return resp.Value, nil

Check warning on line 53 in pkg/plugin/pipedsdk/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/pipedsdk/client.go#L44-L53

Added lines #L44 - L53 were not covered by tests
}

// PutStageMetadata stores the metadata of the current stage.
func (c *Client) PutStageMetadata(ctx context.Context, key, value string) error {
_, err := c.base.PutStageMetadata(ctx, &pipedservice.PutStageMetadataRequest{
DeploymentId: c.deploymentID,
StageId: c.stageID,
Key: key,
Value: value,
})
return err

Check warning on line 64 in pkg/plugin/pipedsdk/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/pipedsdk/client.go#L57-L64

Added lines #L57 - L64 were not covered by tests
}

// PutStageMetadataMulti stores the multiple metadata of the current stage.
func (c *Client) PutStageMetadataMulti(ctx context.Context, metadata map[string]string) error {
_, err := c.base.PutStageMetadataMulti(ctx, &pipedservice.PutStageMetadataMultiRequest{
DeploymentId: c.deploymentID,
StageId: c.stageID,
Metadata: metadata,
})
return err

Check warning on line 74 in pkg/plugin/pipedsdk/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/pipedsdk/client.go#L68-L74

Added lines #L68 - L74 were not covered by tests
}

// GetDeploymentPluginMetadata gets the metadata of the current deployment and plugin.
func (c *Client) GetDeploymentPluginMetadata(ctx context.Context, key string) (string, error) {
resp, err := c.base.GetDeploymentPluginMetadata(ctx, &pipedservice.GetDeploymentPluginMetadataRequest{
DeploymentId: c.deploymentID,
PluginName: c.pluginName,
Key: key,
})
return resp.Value, err

Check warning on line 84 in pkg/plugin/pipedsdk/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/pipedsdk/client.go#L78-L84

Added lines #L78 - L84 were not covered by tests
}

// PutDeploymentPluginMetadata stores the metadata of the current deployment and plugin.
func (c *Client) PutDeploymentPluginMetadata(ctx context.Context, key, value string) error {
_, err := c.base.PutDeploymentPluginMetadata(ctx, &pipedservice.PutDeploymentPluginMetadataRequest{
DeploymentId: c.deploymentID,
PluginName: c.pluginName,
Key: key,
Value: value,
})
return err

Check warning on line 95 in pkg/plugin/pipedsdk/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/pipedsdk/client.go#L88-L95

Added lines #L88 - L95 were not covered by tests
}

// PutDeploymentPluginMetadataMulti stores the multiple metadata of the current deployment and plugin.
func (c *Client) PutDeploymentPluginMetadataMulti(ctx context.Context, metadata map[string]string) error {
_, err := c.base.PutDeploymentPluginMetadataMulti(ctx, &pipedservice.PutDeploymentPluginMetadataMultiRequest{
DeploymentId: c.deploymentID,
PluginName: c.pluginName,
Metadata: metadata,
})
return err

Check warning on line 105 in pkg/plugin/pipedsdk/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/pipedsdk/client.go#L99-L105

Added lines #L99 - L105 were not covered by tests
}

// GetDeploymentSharedMetadata gets the metadata of the current deployment
// which is shared among piped and plugins.
func (c *Client) GetDeploymentSharedMetadata(ctx context.Context, key string) (string, error) {
resp, err := c.base.GetDeploymentSharedMetadata(ctx, &pipedservice.GetDeploymentSharedMetadataRequest{
DeploymentId: c.deploymentID,
Key: key,
})
return resp.Value, err

Check warning on line 115 in pkg/plugin/pipedsdk/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/pipedsdk/client.go#L110-L115

Added lines #L110 - L115 were not covered by tests
}