Skip to content

Commit 753bfb8

Browse files
authored
[CDTOOL-1195] Correct 'tls-custom activation enable' command parameters to reflect expected input from API (#1562)
### Change summary This fixes #1329. This PR correctly maps the required fields for creating a TLS Activation. Previously we were inputting a unclear `id` field and not intaking the required `tls_domain` api field. The input flags have been updated to require the following flags instead: ``` --cert-id=CERT-ID Alphanumeric string identifying a TLS certificate --tls-config-id=TLS-CONFIG-ID Alphanumeric string identifying a TLS configuration --tls-domain=TLS-DOMAIN The domain name associated with the TLS activation ``` All Submissions: * [x] Have you followed the guidelines in our Contributing document? * [x] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change? <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### New Feature Submissions: * [x] Does your submission pass tests? ### Changes to Core Features: * [x] Have you written new tests for your core changes, as applicable? * [x] Have you successfully run tests with your changes locally? ### User Impact Users may now use the CLI for creating new TLS activations. ### Are there any considerations that need to be addressed for release? This is a breaking change as we are modifying command parameters.
1 parent f8b5b9a commit 753bfb8

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
### Breaking:
6+
- breaking(tls-custom): correct 'tls-custom activation enable' command parameters to reflect expected input from API ([#1562](https://github.com/fastly/cli/pull/1562))
67

78
### Enhancements:
89
- build(dockerfile-rust): add wasm tools to the rust docker container ([#1552](https://github.com/fastly/cli/pull/1552))

pkg/commands/tls/custom/activation/activation_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
const (
1717
mockResponseID = "123"
1818
mockResponseCertID = "456"
19+
mockResponseConfigID = "789"
20+
mockResponseDomain = "tls.example.com"
1921
validateAPIError = "validate API error"
2022
validateAPISuccess = "validate API success"
2123
validateMissingIDFlag = "validate missing --id flag"
@@ -24,14 +26,19 @@ const (
2426
func TestTLSCustomActivationEnable(t *testing.T) {
2527
scenarios := []testutil.CLIScenario{
2628
{
27-
Name: validateMissingIDFlag,
28-
Args: "--cert-id example",
29-
WantError: "required flag --id not provided",
29+
Name: "validate missing CertID flag",
30+
Args: fmt.Sprintf("--tls-config-id %s --tls-domain %s", mockResponseConfigID, mockResponseDomain),
31+
WantError: "required flag --cert-id not provided",
3032
},
3133
{
32-
Name: validateMissingIDFlag,
33-
Args: "--id example",
34-
WantError: "required flag --cert-id not provided",
34+
Name: "validate missing ConfigID flag",
35+
Args: fmt.Sprintf("--cert-id %s --tls-domain %s", mockResponseCertID, mockResponseDomain),
36+
WantError: "required flag --tls-config-id not provided",
37+
},
38+
{
39+
Name: "validate missing Domain Flag",
40+
Args: fmt.Sprintf("--cert-id %s --tls-config-id %s", mockResponseCertID, mockResponseConfigID),
41+
WantError: "required flag --tls-domain not provided",
3542
},
3643
{
3744
Name: validateAPIError,
@@ -40,7 +47,7 @@ func TestTLSCustomActivationEnable(t *testing.T) {
4047
return nil, testutil.Err
4148
},
4249
},
43-
Args: "--cert-id example --id example",
50+
Args: fmt.Sprintf("--cert-id %s --tls-config-id %s --tls-domain %s", mockResponseCertID, mockResponseConfigID, mockResponseDomain),
4451
WantError: testutil.Err.Error(),
4552
},
4653
{
@@ -49,14 +56,11 @@ func TestTLSCustomActivationEnable(t *testing.T) {
4956
CreateTLSActivationFn: func(_ context.Context, _ *fastly.CreateTLSActivationInput) (*fastly.TLSActivation, error) {
5057
return &fastly.TLSActivation{
5158
ID: mockResponseID,
52-
Certificate: &fastly.CustomTLSCertificate{
53-
ID: mockResponseCertID,
54-
},
5559
}, nil
5660
},
5761
},
58-
Args: "--cert-id example --id example",
59-
WantOutput: fmt.Sprintf("Enabled TLS Activation '%s' (Certificate '%s')", mockResponseID, mockResponseCertID),
62+
Args: fmt.Sprintf("--cert-id %s --tls-config-id %s --tls-domain %s", mockResponseCertID, mockResponseConfigID, mockResponseDomain),
63+
WantOutput: fmt.Sprintf("SUCCESS: Enabled TLS Activation '%s' (Certificate '%s', Configuration '%s')", mockResponseID, mockResponseCertID, mockResponseConfigID),
6064
},
6165
}
6266

pkg/commands/tls/custom/activation/create.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
1919

2020
// Required.
2121
c.CmdClause.Flag("cert-id", "Alphanumeric string identifying a TLS certificate").Required().StringVar(&c.certID)
22-
c.CmdClause.Flag("id", "Alphanumeric string identifying a TLS activation").Required().StringVar(&c.id)
22+
c.CmdClause.Flag("tls-config-id", "Alphanumeric string identifying a TLS configuration").Required().StringVar(&c.tlsConfigID)
23+
c.CmdClause.Flag("tls-domain", "The domain name associated with the TLS certificate").Required().StringVar(&c.tlsDomain)
2324

2425
return &c
2526
}
@@ -28,8 +29,9 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
2829
type CreateCommand struct {
2930
argparser.Base
3031

31-
certID string
32-
id string
32+
certID string
33+
tlsConfigID string
34+
tlsDomain string
3335
}
3436

3537
// Exec invokes the application logic for the command.
@@ -39,22 +41,24 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
3941
r, err := c.Globals.APIClient.CreateTLSActivation(context.TODO(), input)
4042
if err != nil {
4143
c.Globals.ErrLog.AddWithContext(err, map[string]any{
42-
"TLS Activation ID": c.id,
44+
"TLS Configuration ID": c.tlsConfigID,
4345
"TLS Activation Certificate ID": c.certID,
46+
"TLS Domain": c.tlsDomain,
4447
})
4548
return err
4649
}
4750

48-
text.Success(out, "Enabled TLS Activation '%s' (Certificate '%s')", r.ID, r.Certificate.ID)
51+
text.Success(out, "Enabled TLS Activation '%s' (Certificate '%s', Configuration '%s')", r.ID, c.certID, c.tlsConfigID)
4952
return nil
5053
}
5154

5255
// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
5356
func (c *CreateCommand) constructInput() *fastly.CreateTLSActivationInput {
5457
var input fastly.CreateTLSActivationInput
5558

56-
input.ID = c.id
59+
input.Configuration = &fastly.TLSConfiguration{ID: c.tlsConfigID}
5760
input.Certificate = &fastly.CustomTLSCertificate{ID: c.certID}
61+
input.Domain = &fastly.TLSDomain{ID: c.tlsDomain}
5862

5963
return &input
6064
}

0 commit comments

Comments
 (0)