Skip to content

Commit

Permalink
Add env when calling custom code logging update list get delete (#2933)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjuyin authored Nov 14, 2024
1 parent 756ae7b commit 8d1f41a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 34 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/confluentinc/ccloud-sdk-go-v2/apikeys v0.4.0
github.com/confluentinc/ccloud-sdk-go-v2/billing v0.3.0
github.com/confluentinc/ccloud-sdk-go-v2/byok v0.0.2
github.com/confluentinc/ccloud-sdk-go-v2/ccl v0.2.0
github.com/confluentinc/ccloud-sdk-go-v2/ccl v0.4.0
github.com/confluentinc/ccloud-sdk-go-v2/cdx v0.0.5
github.com/confluentinc/ccloud-sdk-go-v2/certificate-authority v0.0.0-20240921001517-750d06dd7c27
github.com/confluentinc/ccloud-sdk-go-v2/cli v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ github.com/confluentinc/ccloud-sdk-go-v2/billing v0.3.0 h1:a2EaPzwLEYkgil7rlsqRU
github.com/confluentinc/ccloud-sdk-go-v2/billing v0.3.0/go.mod h1:c7nUjQ5pQCqz4LagF1qatcj5NX4icoiSTaCxfdxAwsY=
github.com/confluentinc/ccloud-sdk-go-v2/byok v0.0.2 h1:BV/dPTFVovJPylrcr9lcSmukCVxBxyUeHBr6hp7zUNk=
github.com/confluentinc/ccloud-sdk-go-v2/byok v0.0.2/go.mod h1:MMtRTfg1g32bQrRwfqvGpe+grS5pQzeq9V+L5GKydV4=
github.com/confluentinc/ccloud-sdk-go-v2/ccl v0.2.0 h1:DQAD0SCIA8iYSjGc2lQLhfSDAXBa4XdswGQnfIRlPR4=
github.com/confluentinc/ccloud-sdk-go-v2/ccl v0.2.0/go.mod h1:UEXs5OUsWq9P0PBLlrtxPOX4H6nP3FaWFvnG8JrscAM=
github.com/confluentinc/ccloud-sdk-go-v2/ccl v0.4.0 h1:dUFB7PM/eQbI/AhRHyMh4Pd7xsDDlhonE3/+kwvXVnY=
github.com/confluentinc/ccloud-sdk-go-v2/ccl v0.4.0/go.mod h1:SJdOAgzigkv8NbZo6+8N1isiZ/HXTg+TOtQg1o1PhKY=
github.com/confluentinc/ccloud-sdk-go-v2/cdx v0.0.5 h1:w0Z2hFxg8ng8gycWKRZFdus1R+q8D/I5AmN06NZso5s=
github.com/confluentinc/ccloud-sdk-go-v2/cdx v0.0.5/go.mod h1:L8U9xs2duASJnjIYkwGrSbZNpApsbh+vlxsJlZMHJPA=
github.com/confluentinc/ccloud-sdk-go-v2/certificate-authority v0.0.0-20240921001517-750d06dd7c27 h1:prbOJKQGZ6VgBFRDN3mzE942apQnlS5d68L7HyA2Gz8=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,29 @@ func (c *customCodeLoggingCommand) newDeleteCommand() *cobra.Command {
Args: cobra.MinimumNArgs(1),
RunE: c.delete,
}

pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
pcmd.AddForceFlag(cmd)
pcmd.AddContextFlag(cmd, c.CLICommand)
return cmd
}

func (c *customCodeLoggingCommand) delete(cmd *cobra.Command, args []string) error {
environment, err := c.Context.EnvironmentId()
if err != nil {
return err
}

existenceFunc := func(id string) bool {
_, err := c.V2Client.DescribeCustomCodeLogging(id)
_, err := c.V2Client.DescribeCustomCodeLogging(id, environment)
return err == nil
}

if err := deletion.ValidateAndConfirm(cmd, args, existenceFunc, resource.CustomCodeLogging); err != nil {
return err
}
deleteFunc := func(id string) error {
return c.V2Client.DeleteCustomCodeLogging(id)
return c.V2Client.DeleteCustomCodeLogging(id, environment)
}
_, err := deletion.Delete(args, deleteFunc, resource.CustomCodeLogging)
_, err = deletion.Delete(args, deleteFunc, resource.CustomCodeLogging)
return err
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ func (c *customCodeLoggingCommand) newDescribeCommand() *cobra.Command {
Example: examples.BuildExampleString(
examples.Example{
Text: "Describe custom code logging.",
Code: "confluent custom-code-logging describe ccl-123456",
Code: "confluent custom-code-logging describe ccl-123456 --environment env-000000",
},
),
}

pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
pcmd.AddContextFlag(cmd, c.CLICommand)
pcmd.AddOutputFlag(cmd)
return cmd
}

func (c *customCodeLoggingCommand) describe(cmd *cobra.Command, args []string) error {
customCodeLogging, err := c.V2Client.DescribeCustomCodeLogging(args[0])
environment, err := c.Context.EnvironmentId()
if err != nil {
return err
}
customCodeLogging, err := c.V2Client.DescribeCustomCodeLogging(args[0], environment)
if err != nil {
return err
}
Expand Down
15 changes: 13 additions & 2 deletions internal/custom-code-logging/command_custom_code_logging_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
"github.com/confluentinc/cli/v4/pkg/errors"
"github.com/confluentinc/cli/v4/pkg/examples"
"github.com/confluentinc/cli/v4/pkg/output"
"github.com/confluentinc/cli/v4/pkg/resource"
"github.com/confluentinc/cli/v4/pkg/utils"
Expand All @@ -20,15 +21,25 @@ func (c *customCodeLoggingCommand) newUpdateCommand() *cobra.Command {
Short: "Update a custom code logging.",
Args: cobra.ExactArgs(1),
RunE: c.update,
Example: examples.BuildExampleString(
examples.Example{
Text: "Describe custom code logging.",
Code: "confluent custom-code-logging update ccl-123456 --log-level DEBUG --environment env-000000",
},
),
}

pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
cmd.Flags().String("log-level", "INFO", fmt.Sprintf("Specify the Custom Code Logging Log Level as %s.", utils.ArrayToCommaDelimitedString(allowedLogLevels, "or")))
cmd.MarkFlagsOneRequired("log-level")
pcmd.AddContextFlag(cmd, c.CLICommand)
return cmd
}

func (c *customCodeLoggingCommand) update(cmd *cobra.Command, args []string) error {
environment, err := c.Context.EnvironmentId()
if err != nil {
return err
}
id := args[0]
updateCustomPluginRequest := cclv1.CclV1CustomCodeLoggingUpdate{}

Expand All @@ -44,7 +55,7 @@ func (c *customCodeLoggingCommand) update(cmd *cobra.Command, args []string) err
}
}

if _, err := c.V2Client.UpdateCustomCodeLogging(id, updateCustomPluginRequest); err != nil {
if _, err := c.V2Client.UpdateCustomCodeLogging(id, environment, updateCustomPluginRequest); err != nil {
return err
}

Expand Down
23 changes: 10 additions & 13 deletions pkg/ccloudv2/custom_code_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func (c *Client) CreateCustomCodeLogging(createCustomCodeLoggingRequest cclv1.Cc
return resp, errors.CatchCCloudV2Error(err, httpResp)
}

func (c *Client) ListCustomCodeLoggings(environment string) ([]cclv1.CclV1CustomCodeLogging, error) {
func (c *Client) ListCustomCodeLoggings(env string) ([]cclv1.CclV1CustomCodeLogging, error) {
var list []cclv1.CclV1CustomCodeLogging

done := false
pageToken := ""
for !done {
page, httpResp, err := c.executeListCustomCodeLoggings(pageToken, environment)
page, httpResp, err := c.executeListCustomCodeLoggings(pageToken, env)
if err != nil {
return nil, errors.CatchCCloudV2Error(err, httpResp)
}
Expand All @@ -48,28 +48,25 @@ func (c *Client) ListCustomCodeLoggings(environment string) ([]cclv1.CclV1Custom
return list, nil
}

func (c *Client) DescribeCustomCodeLogging(id string) (cclv1.CclV1CustomCodeLogging, error) {
resp, httpResp, err := c.Cclv1Client.CustomCodeLoggingsCclV1Api.GetCclV1CustomCodeLogging(c.connectCustomCodeLoggingApiContext(), id).Execute()
func (c *Client) DescribeCustomCodeLogging(id string, env string) (cclv1.CclV1CustomCodeLogging, error) {
resp, httpResp, err := c.Cclv1Client.CustomCodeLoggingsCclV1Api.GetCclV1CustomCodeLogging(c.connectCustomCodeLoggingApiContext(), id).Environment(env).Execute()
return resp, errors.CatchCCloudV2Error(err, httpResp)
}

func (c *Client) DeleteCustomCodeLogging(id string) error {
httpResp, err := c.Cclv1Client.CustomCodeLoggingsCclV1Api.DeleteCclV1CustomCodeLogging(c.connectCustomCodeLoggingApiContext(), id).Execute()
func (c *Client) DeleteCustomCodeLogging(id string, env string) error {
httpResp, err := c.Cclv1Client.CustomCodeLoggingsCclV1Api.DeleteCclV1CustomCodeLogging(c.connectCustomCodeLoggingApiContext(), id).Environment(env).Execute()
return errors.CatchCCloudV2Error(err, httpResp)
}

func (c *Client) UpdateCustomCodeLogging(id string, updateCustomCodeLoggingRequest cclv1.CclV1CustomCodeLoggingUpdate) (cclv1.CclV1CustomCodeLogging, error) {
resp, httpResp, err := c.Cclv1Client.CustomCodeLoggingsCclV1Api.UpdateCclV1CustomCodeLogging(c.connectCustomCodeLoggingApiContext(), id).CclV1CustomCodeLoggingUpdate(updateCustomCodeLoggingRequest).Execute()
func (c *Client) UpdateCustomCodeLogging(id string, env string, updateCustomCodeLoggingRequest cclv1.CclV1CustomCodeLoggingUpdate) (cclv1.CclV1CustomCodeLogging, error) {
resp, httpResp, err := c.Cclv1Client.CustomCodeLoggingsCclV1Api.UpdateCclV1CustomCodeLogging(c.connectCustomCodeLoggingApiContext(), id).CclV1CustomCodeLoggingUpdate(updateCustomCodeLoggingRequest).Environment(env).Execute()
return resp, errors.CatchCCloudV2Error(err, httpResp)
}

func (c *Client) executeListCustomCodeLoggings(pageToken string, environment string) (cclv1.CclV1CustomCodeLoggingList, *http.Response, error) {
req := c.Cclv1Client.CustomCodeLoggingsCclV1Api.ListCclV1CustomCodeLoggings(c.connectCustomCodeLoggingApiContext()).PageSize(ccloudV2ListPageSize)
func (c *Client) executeListCustomCodeLoggings(pageToken string, env string) (cclv1.CclV1CustomCodeLoggingList, *http.Response, error) {
req := c.Cclv1Client.CustomCodeLoggingsCclV1Api.ListCclV1CustomCodeLoggings(c.connectCustomCodeLoggingApiContext()).Environment(env).PageSize(ccloudV2ListPageSize)
if pageToken != "" {
req = req.PageToken(pageToken)
}
if environment != "" {
req = req.Environment(environment)
}
return req.Execute()
}
5 changes: 3 additions & 2 deletions test/fixtures/output/custom-code-logging/delete-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Usage:
confluent custom-code-logging delete <id-1> [id-2] ... [id-n] [flags]

Flags:
--force Skip the deletion confirmation prompt.
--context string CLI context name.
--environment string Environment ID.
--force Skip the deletion confirmation prompt.
--context string CLI context name.

Global Flags:
-h, --help Show help for this command.
Expand Down
7 changes: 4 additions & 3 deletions test/fixtures/output/custom-code-logging/describe-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Usage:
Examples:
Describe custom code logging.

$ confluent custom-code-logging describe ccl-123456
$ confluent custom-code-logging describe ccl-123456 --environment env-000000

Flags:
--context string CLI context name.
-o, --output string Specify the output format as "human", "json", or "yaml". (default "human")
--environment string Environment ID.
--context string CLI context name.
-o, --output string Specify the output format as "human", "json", or "yaml". (default "human")

Global Flags:
-h, --help Show help for this command.
Expand Down
10 changes: 8 additions & 2 deletions test/fixtures/output/custom-code-logging/update-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ Update a custom code logging.
Usage:
confluent custom-code-logging update <id> [flags]

Examples:
Describe custom code logging.

$ confluent custom-code-logging update ccl-123456 --log-level DEBUG --environment env-000000

Flags:
--log-level string Specify the Custom Code Logging Log Level as "INFO", "DEBUG", "ERROR", or "WARN". (default "INFO")
--context string CLI context name.
--environment string Environment ID.
--log-level string Specify the Custom Code Logging Log Level as "INFO", "DEBUG", "ERROR", or "WARN". (default "INFO")
--context string CLI context name.

Global Flags:
-h, --help Show help for this command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ Error: at least one of the flags in the group [log-level] is required
Usage:
confluent custom-code-logging update <id> [flags]

Examples:
Describe custom code logging.

$ confluent custom-code-logging update ccl-123456 --log-level DEBUG --environment env-000000

Flags:
--log-level string Specify the Custom Code Logging Log Level as "INFO", "DEBUG", "ERROR", or "WARN". (default "INFO")
--context string CLI context name.
--environment string Environment ID.
--log-level string Specify the Custom Code Logging Log Level as "INFO", "DEBUG", "ERROR", or "WARN". (default "INFO")
--context string CLI context name.

Global Flags:
-h, --help Show help for this command.
Expand Down

0 comments on commit 8d1f41a

Please sign in to comment.