Skip to content

Commit

Permalink
ftp: make changes addressing prior PR review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Colton J. McCurdy <cmccurdy@fastly.com>
  • Loading branch information
mccurdyc committed Jun 10, 2020
1 parent c1f0412 commit 5fd09e6
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions fastly/block_fastly_service_v1_logging_ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var ftpSchema = &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The unique name of the FTP logging endpoint",
Description: "The unique name of the FTP logging endpoint.",
},

"address": {
Expand Down Expand Up @@ -57,27 +57,27 @@ var ftpSchema = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 3600,
Description: "How frequently the logs should be transferred, in seconds (Default 3600)",
Description: "How frequently the logs should be transferred, in seconds (Default 3600).",
},

"public_key": {
Type: schema.TypeString,
Optional: true,
Description: "The PGP public key that Fastly will use to encrypt your log files before writing them to disk",
Description: "The PGP public key that Fastly will use to encrypt your log files before writing them to disk.",
},

"gzip_level": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "Gzip Compression level",
Description: "Gzip Compression level.",
},

"timestamp_format": {
Type: schema.TypeString,
Optional: true,
Default: "%Y-%m-%dT%H:%M:%S.000",
Description: "specified timestamp formatting (default `%Y-%m-%dT%H:%M:%S.000`)",
Description: "specified timestamp formatting (default `%Y-%m-%dT%H:%M:%S.000`).",
},

"format": {
Expand All @@ -90,21 +90,21 @@ var ftpSchema = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 2,
Description: "The version of the custom logging format used for the configured endpoint. Can be either 1 or 2. (default: 2)",
Description: "The version of the custom logging format used for the configured endpoint. Can be either 1 or 2. (default: 2).",
ValidateFunc: validateLoggingFormatVersion(),
},

"placement": {
Type: schema.TypeString,
Optional: true,
Description: "Where in the generated VCL the logging call should be placed",
Description: "Where in the generated VCL the logging call should be placed.",
ValidateFunc: validateLoggingPlacement(),
},

"response_condition": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the condition to apply",
Description: "The name of the condition to apply.",
},
},
},
Expand All @@ -127,7 +127,7 @@ func processFTP(d *schema.ResourceData, conn *fst.Client, latestVersion int) err
removeFTPLogging := ofs.Difference(nfs).List()
addFTPLogging := nfs.Difference(ofs).List()

// DELETE old FTP logging endpoints
// DELETE old FTP logging endpoints.
for _, oRaw := range removeFTPLogging {
of := oRaw.(map[string]interface{})
opts := buildDeleteFTP(of, serviceID, latestVersion)
Expand All @@ -139,7 +139,7 @@ func processFTP(d *schema.ResourceData, conn *fst.Client, latestVersion int) err
}
}

// POST new/updated FTP logging endpoints
// POST new/updated FTP logging endpoints.
for _, nRaw := range addFTPLogging {
ef := nRaw.(map[string]interface{})
opts := buildCreateFTP(ef, serviceID, latestVersion)
Expand All @@ -155,7 +155,7 @@ func processFTP(d *schema.ResourceData, conn *fst.Client, latestVersion int) err
}

func readFTP(conn *fst.Client, d *schema.ResourceData, s *fst.ServiceDetail) error {
// refresh FTP
// Refresh FTP.
log.Printf("[DEBUG] Refreshing FTP logging endpoints for (%s)", d.Id())
ftpList, err := conn.ListFTPs(&fst.ListFTPsInput{
Service: d.Id(),
Expand All @@ -177,10 +177,7 @@ func readFTP(conn *fst.Client, d *schema.ResourceData, s *fst.ServiceDetail) err

func createFTP(conn *fst.Client, i *fst.CreateFTPInput) error {
_, err := conn.CreateFTP(i)
if err != nil {
return err
}
return nil
return err
}

func deleteFTP(conn *fst.Client, i *fst.DeleteFTPInput) error {
Expand Down Expand Up @@ -218,7 +215,7 @@ func flattenFTP(ftpList []*fst.FTP) []map[string]interface{} {
"response_condition": fl.ResponseCondition,
}

// prune any empty values that come from the default string value in structs
// Prune any empty values that come from the default string value in structs.
for k, v := range nfl {
if v == "" {
delete(nfl, k)
Expand All @@ -233,7 +230,8 @@ func flattenFTP(ftpList []*fst.FTP) []map[string]interface{} {

func buildCreateFTP(ftpMap interface{}, serviceID string, serviceVersion int) *fst.CreateFTPInput {
df := ftpMap.(map[string]interface{})
opts := fst.CreateFTPInput{

return &fst.CreateFTPInput{
Service: serviceID,
Version: serviceVersion,
Name: df["name"].(string),
Expand All @@ -251,18 +249,14 @@ func buildCreateFTP(ftpMap interface{}, serviceID string, serviceVersion int) *f
Placement: df["placement"].(string),
ResponseCondition: df["response_condition"].(string),
}

return &opts
}

func buildDeleteFTP(ftpMap interface{}, serviceID string, serviceVersion int) *fst.DeleteFTPInput {
df := ftpMap.(map[string]interface{})

opts := fst.DeleteFTPInput{
return &fst.DeleteFTPInput{
Service: serviceID,
Version: serviceVersion,
Name: df["name"].(string),
}

return &opts
}

0 comments on commit 5fd09e6

Please sign in to comment.