<commit_before>package hpcloud

import (
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
)

func (a Access) ActivateCDNContainer(container string) error {
	client := &http.Client{}
	path := fmt.Sprintf("%s%s/%s", CDN_URL, a.TenantID, container)
	req, err := http.NewRequest("PUT", path, nil)
	if err != nil {
		return err
	}
	req.Header.Add("X-Auth-Token", a.AuthToken())
	req.Header.Add("Accept", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusCreated {
		return nil
	}
	return errors.New(fmt.Sprintf("Non-201 status code: %d", resp.StatusCode))
}

func (a Access) ListCDNEnabledContainers(enabled_only bool) (*CDNContainers, error) {
	client := &http.Client{}
	qstring := "?format=json"
	if enabled_only {
		qstring = qstring + "&enabled_only=true"
	}
	path := fmt.Sprintf("%s%s%s", CDN_URL, a.TenantID, qstring)
	req, err := http.NewRequest("GET", path, nil)
	if err != nil {
		return nil, err
	}
	req.Header.Add("X-Auth-Token", a.AuthToken())
	req.Header.Add("Accept", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode == http.StatusOK {
		c := &CDNContainers{}
		err = json.Unmarshal(b, c)
		if err != nil {
			return nil, err
		}
		return c, nil
	}
	return nil, errors.New(fmt.Sprintf("Non-200 status code: %d", resp.StatusCode))
}

func (a Access) UpdateCDNEnabledContainerMetadata(container string, data map[string]string) error {
	client := &http.Client{}
	path := fmt.Sprintf("%s%s/%s", CDN_URL, a.TenantID, container)
	req, err := http.NewRequest("POST", path, nil)
	if err != nil {
		return err
	}
	req.Header.Add("X-Auth-Token", a.AuthToken())
	for key, value := range data {
		req.Header.Add(key, value)
	}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusAccepted {
		return nil
	}
	return errors.New(fmt.Sprintf("Non-202 status code: %d", resp.StatusCode))

}

func (a Access) RetrieveCDNEnabledContainerMetadata(container string) (*http.Header, error) {
	client := &http.Client{}
	path := fmt.Sprintf("%s%s/%s", CDN_URL, a.TenantID, container)
	req, err := http.NewRequest("HEAD", path, nil)
	if err != nil {
		return nil, err
	}
	req.Header.Add("X-Auth-Token", a.AuthToken())
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusNoContent {
		return &resp.Header, nil
	}
	return nil, errors.New(fmt.Sprintf("Non-205 status code: %d", resp.StatusCode))
}

func (a Access) DisableCDNEnabledContainer(container string) {

}

func (a Access) DeleteCDNEnabledContainer(container string) {

}

type CDNContainers []CDNContainer
type CDNContainer struct {
	Name         string `json:"name"`
	CDNEnabled   bool   `json:"cdn_enabled"`
	TTL          int64  `json:"ttl"`
	CDNUri       string `json:"x-cdn-uri"`
	SSLCDNUri    string `json:"x-cdn-ssl-uri"`
	LogRetention bool   `json:"log_retention"`
}<commit_msg>Added the Disabling of CDN containers.<commit_after>package hpcloud

import (
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
)

func (a Access) baseCDNRequest(method, container string, StatusCode int) error {
	client := &http.Client{}
	path := fmt.Sprintf("%s%s/%s", CDN_URL, a.TenantID, container)
	req, err := http.NewRequest(method, path, nil)
	if err != nil {
		return err
	}
	req.Header.Add("X-Auth-Token", a.AuthToken())
	req.Header.Add("Accept", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode == StatusCode {
		return nil
	}
	return errors.New(fmt.Sprintf("Non-%d status code: %d", StatusCode, resp.StatusCode))

}

func (a Access) ActivateCDNContainer(container string) error {
	return a.baseCDNRequest("PUT", container, http.StatusCreated)
}

func (a Access) ListCDNEnabledContainers(enabled_only bool) (*CDNContainers, error) {
	client := &http.Client{}
	qstring := "?format=json"
	if enabled_only {
		qstring = qstring + "&enabled_only=true"
	}
	path := fmt.Sprintf("%s%s%s", CDN_URL, a.TenantID, qstring)
	req, err := http.NewRequest("GET", path, nil)
	if err != nil {
		return nil, err
	}
	req.Header.Add("X-Auth-Token", a.AuthToken())
	req.Header.Add("Accept", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode == http.StatusOK {
		c := &CDNContainers{}
		err = json.Unmarshal(b, c)
		if err != nil {
			return nil, err
		}
		return c, nil
	}
	return nil, errors.New(fmt.Sprintf("Non-200 status code: %d", resp.StatusCode))
}

func (a Access) UpdateCDNEnabledContainerMetadata(container string, data map[string]string) error {
	client := &http.Client{}
	path := fmt.Sprintf("%s%s/%s", CDN_URL, a.TenantID, container)
	req, err := http.NewRequest("POST", path, nil)
	if err != nil {
		return err
	}
	req.Header.Add("X-Auth-Token", a.AuthToken())
	for key, value := range data {
		req.Header.Add(key, value)
	}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusAccepted {
		return nil
	}
	return errors.New(fmt.Sprintf("Non-202 status code: %d", resp.StatusCode))

}

func (a Access) RetrieveCDNEnabledContainerMetadata(container string) (*http.Header, error) {
	client := &http.Client{}
	path := fmt.Sprintf("%s%s/%s", CDN_URL, a.TenantID, container)
	req, err := http.NewRequest("HEAD", path, nil)
	if err != nil {
		return nil, err
	}
	req.Header.Add("X-Auth-Token", a.AuthToken())
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusNoContent {
		return &resp.Header, nil
	}
	return nil, errors.New(fmt.Sprintf("Non-205 status code: %d", resp.StatusCode))
}

func (a Access) DisableCDNEnabledContainer(container string) error {
	return a.UpdateCDNEnabledContainerMetadata(container, map[string]string{
		"X-CDN-Enabled": "False",
	})
}

func (a Access) DeleteCDNEnabledContainer(container string) {

}

type CDNContainers []CDNContainer
type CDNContainer struct {
	Name         string `json:"name"`
	CDNEnabled   bool   `json:"cdn_enabled"`
	TTL          int64  `json:"ttl"`
	CDNUri       string `json:"x-cdn-uri"`
	SSLCDNUri    string `json:"x-cdn-ssl-uri"`
	LogRetention bool   `json:"log_retention"`
}
{'fraction_non_alphanumeric': 0.15932721712538225, 'fraction_numerical': 0.00382262996941896, 'mean_word_length': 4.158517350157728, 'pattern_counts': {'":': 1, '<': 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': '837712', 'n_tokens_mistral': 2455, 'n_tokens_neox': 2402, 'n_words': 577}