<commit_before>package util

import (
	"fmt"
	"github.com/hashicorp/terraform/helper/schema"
	"github.com/sky-uk/go-pulse-vtm/api"
	"net/http"
)

//SchemaSSLKey : Returns an SSL Key Schema
func SchemaSSLKey() map[string]*schema.Schema {
	return map[string]*schema.Schema{
		"name": {
			Type:         schema.TypeString,
			Required:     true,
			ForceNew:     true,
			ValidateFunc: NoZeroValues,
		},

		"note": {
			Type:     schema.TypeString,
			Optional: true,
		},

		"private": {
			Type:     schema.TypeString,
			Optional: true,
		},

		"public": {
			Type:     schema.TypeString,
			Optional: true,
		},

		"request": {
			Type:     schema.TypeString,
			Optional: true,
		},
	}
}

//SSLKeyCreate : Creates an SSL Key
func SSLKeyCreate(d *schema.ResourceData, meta interface{}, keyType string) error {

	name := d.Get("name").(string)

	sslKeyPropertiesConfig := make(map[string]interface{})
	sslKeyBasicConfig := make(map[string]interface{})
	sslKeyConfig := make(map[string]interface{})

	if v, ok := d.GetOk("note"); ok {
		sslKeyBasicConfig["note"] = v.(string)
	}
	if v, ok := d.GetOk("private"); ok {
		sslKeyBasicConfig["private"] = v.(string)
	}
	if v, ok := d.GetOk("public"); ok {
		sslKeyBasicConfig["public"] = v.(string)
	}
	if v, ok := d.GetOk("request"); ok {
		sslKeyBasicConfig["request"] = v.(string)
	}
	sslKeyPropertiesConfig["basic"] = sslKeyBasicConfig
	sslKeyConfig["properties"] = sslKeyPropertiesConfig

	config := meta.(map[string]interface{})
	client := config["jsonClient"].(*api.Client)
	err := client.Set(keyType, name, sslKeyConfig, nil)
	if err != nil {
		return fmt.Errorf("[ERROR] PulseVTM %s error whilst creating %s: %v", keyType, name, err)
	}
	d.SetId(name)

	return nil
}

//SSLKeyRead : Reads an SSL Key
func SSLKeyRead(d *schema.ResourceData, meta interface{}, keyType string) error {
	config := meta.(map[string]interface{})
	client := config["jsonClient"].(*api.Client)
	client.WorkWithConfigurationResources()
	sslClientKeyConfig := make(map[string]interface{})
	err := client.GetByName(keyType, d.Id(), &sslClientKeyConfig)
	if client.StatusCode == http.StatusNotFound {
		d.SetId("")
		return nil
	}
	if err != nil {
		return fmt.Errorf("[ERROR] PulseVTM %s error whilst retrieving %s: %v", keyType, d.Id(), err)
	}

	sslClientKeyPropertiesConfig := sslClientKeyConfig["properties"].(map[string]interface{})
	sslClientKeyBasicConfig := sslClientKeyPropertiesConfig["basic"].(map[string]interface{})

	for _, attribute := range []string{"note", "public", "request"} {
		err := d.Set(attribute, sslClientKeyBasicConfig[attribute])
		if err != nil {
			return fmt.Errorf("[ERROR] PulseVTM %s error whilst setting attribute %s: %v", keyType, attribute, err)
		}
	}

	return nil
}

//SSLKeyUpdate : Updates an SSL Key
func SSLKeyUpdate(d *schema.ResourceData, meta interface{}, keyType string) error {

	sslKeyPropertiesConfig := make(map[string]interface{})
	sslKeyBasicConfig := make(map[string]interface{})
	sslKeyConfig := make(map[string]interface{})

	if d.HasChange("note") {
		sslKeyBasicConfig["note"] = d.Get("note").(string)
	}
	if d.HasChange("private") {
		sslKeyBasicConfig["private"] = d.Get("private").(string)
	}
	if d.HasChange("public") {
		sslKeyBasicConfig["public"] = d.Get("public").(string)
	}
	if d.HasChange("request") {
		sslKeyBasicConfig["request"] = d.Get("request").(string)
	}

	sslKeyPropertiesConfig["basic"] = sslKeyBasicConfig
	sslKeyConfig["properties"] = sslKeyPropertiesConfig

	config := meta.(map[string]interface{})
	client := config["jsonClient"].(*api.Client)
	err := client.Set(keyType, d.Id(), sslKeyConfig, nil)
	if err != nil {
		return fmt.Errorf("[ERROR] PulseVTM %s error whilst updating %s: %v", keyType, d.Id(), err)
	}
	return nil
}
<commit_msg>Made the 'private' field of SSL keys sensitive (#129)<commit_after>package util

import (
	"fmt"
	"github.com/hashicorp/terraform/helper/schema"
	"github.com/sky-uk/go-pulse-vtm/api"
	"net/http"
)

//SchemaSSLKey : Returns an SSL Key Schema
func SchemaSSLKey() map[string]*schema.Schema {
	return map[string]*schema.Schema{
		"name": {
			Type:         schema.TypeString,
			Required:     true,
			ForceNew:     true,
			ValidateFunc: NoZeroValues,
		},

		"note": {
			Type:     schema.TypeString,
			Optional: true,
		},

		"private": {
			Type:      schema.TypeString,
			Optional:  true,
			Sensitive: true,
		},

		"public": {
			Type:     schema.TypeString,
			Optional: true,
		},

		"request": {
			Type:     schema.TypeString,
			Optional: true,
		},
	}
}

//SSLKeyCreate : Creates an SSL Key
func SSLKeyCreate(d *schema.ResourceData, meta interface{}, keyType string) error {

	name := d.Get("name").(string)

	sslKeyPropertiesConfig := make(map[string]interface{})
	sslKeyBasicConfig := make(map[string]interface{})
	sslKeyConfig := make(map[string]interface{})

	if v, ok := d.GetOk("note"); ok {
		sslKeyBasicConfig["note"] = v.(string)
	}
	if v, ok := d.GetOk("private"); ok {
		sslKeyBasicConfig["private"] = v.(string)
	}
	if v, ok := d.GetOk("public"); ok {
		sslKeyBasicConfig["public"] = v.(string)
	}
	if v, ok := d.GetOk("request"); ok {
		sslKeyBasicConfig["request"] = v.(string)
	}
	sslKeyPropertiesConfig["basic"] = sslKeyBasicConfig
	sslKeyConfig["properties"] = sslKeyPropertiesConfig

	config := meta.(map[string]interface{})
	client := config["jsonClient"].(*api.Client)
	err := client.Set(keyType, name, sslKeyConfig, nil)
	if err != nil {
		return fmt.Errorf("[ERROR] PulseVTM %s error whilst creating %s: %v", keyType, name, err)
	}
	d.SetId(name)

	return nil
}

//SSLKeyRead : Reads an SSL Key
func SSLKeyRead(d *schema.ResourceData, meta interface{}, keyType string) error {
	config := meta.(map[string]interface{})
	client := config["jsonClient"].(*api.Client)
	client.WorkWithConfigurationResources()
	sslClientKeyConfig := make(map[string]interface{})
	err := client.GetByName(keyType, d.Id(), &sslClientKeyConfig)
	if client.StatusCode == http.StatusNotFound {
		d.SetId("")
		return nil
	}
	if err != nil {
		return fmt.Errorf("[ERROR] PulseVTM %s error whilst retrieving %s: %v", keyType, d.Id(), err)
	}

	sslClientKeyPropertiesConfig := sslClientKeyConfig["properties"].(map[string]interface{})
	sslClientKeyBasicConfig := sslClientKeyPropertiesConfig["basic"].(map[string]interface{})

	for _, attribute := range []string{"note", "public", "request"} {
		err := d.Set(attribute, sslClientKeyBasicConfig[attribute])
		if err != nil {
			return fmt.Errorf("[ERROR] PulseVTM %s error whilst setting attribute %s: %v", keyType, attribute, err)
		}
	}

	return nil
}

//SSLKeyUpdate : Updates an SSL Key
func SSLKeyUpdate(d *schema.ResourceData, meta interface{}, keyType string) error {

	sslKeyPropertiesConfig := make(map[string]interface{})
	sslKeyBasicConfig := make(map[string]interface{})
	sslKeyConfig := make(map[string]interface{})

	if d.HasChange("note") {
		sslKeyBasicConfig["note"] = d.Get("note").(string)
	}
	if d.HasChange("private") {
		sslKeyBasicConfig["private"] = d.Get("private").(string)
	}
	if d.HasChange("public") {
		sslKeyBasicConfig["public"] = d.Get("public").(string)
	}
	if d.HasChange("request") {
		sslKeyBasicConfig["request"] = d.Get("request").(string)
	}

	sslKeyPropertiesConfig["basic"] = sslKeyBasicConfig
	sslKeyConfig["properties"] = sslKeyPropertiesConfig

	config := meta.(map[string]interface{})
	client := config["jsonClient"].(*api.Client)
	err := client.Set(keyType, d.Id(), sslKeyConfig, nil)
	if err != nil {
		return fmt.Errorf("[ERROR] PulseVTM %s error whilst updating %s: %v", keyType, d.Id(), err)
	}
	return nil
}

{'fraction_non_alphanumeric': 0.16463898439566252, 'fraction_numerical': 0.00039672044432689763, 'mean_word_length': 4.755707762557078, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5808371', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2541, 'n_words': 546}