<commit_before><?php

namespace Nails\Cdn\Driver\Aws\Settings;

use Nails\Common\Helper\Form;
use Nails\Common\Interfaces;
use Nails\Common\Service\FormValidation;
use Nails\Components\Setting;
use Nails\Factory;

/**
 * Class Aws
 *
 * @package Nails\Cdn\Driver\Aws\Settings
 */
class Aws implements Interfaces\Component\Settings
{
    const KEY_ACCESS_KEY         = 'access_key';
    const KEY_ACCESS_SECRET      = 'access_secret';
    const KEY_BUCKETS            = 'buckets';
    const KEY_URL_SERVE          = 'uri_serve';
    const KEY_URL_SERVE_SECURE   = 'uri_serve_secure';
    const KEY_URL_PROCESS        = 'uri_process';
    const KEY_URL_PROCESS_SECURE = 'uri_process_secure';

    // --------------------------------------------------------------------------

    /**
     * @inheritDoc
     */
    public function getLabel(): string
    {
        return 'CDN: AWS S3';
    }

    // --------------------------------------------------------------------------

    /**
     * @inheritDoc
     */
    public function get(): array
    {
        /** @var Setting $oAccessKey */
        $oAccessKey = Factory::factory('ComponentSetting');
        $oAccessKey
            ->setKey(static::KEY_ACCESS_KEY)
            ->setLabel('Access Key')
            ->setEncrypted(true)
            ->setFieldset('Credentials')
            ->setValidation([
                FormValidation::RULE_REQUIRED,
            ]);

        /** @var Setting $oAccessSecret */
        $oAccessSecret = Factory::factory('ComponentSetting');
        $oAccessSecret
            ->setKey(static::KEY_ACCESS_SECRET)
            ->setLabel('Access Secret')
            ->setEncrypted(true)
            ->setFieldset('Credentials')
            ->setValidation([
                FormValidation::RULE_REQUIRED,
            ]);

        /** @var Setting $oBuckets */
        $oBuckets = Factory::factory('ComponentSetting');
        $oBuckets
            ->setKey(static::KEY_BUCKETS)
            ->setType(Form::FIELD_TEXTAREA)
            ->setLabel('Buckets')
            ->setFieldset('Buckets')
            ->setInfo('Buckets should be specified as a JSON object with the environment as the key, and the region and bucket as the value. e.g. <code>{"PRODUCTION":"eu-west-1:my-bucket"}</code>')
            ->setValidation([
                FormValidation::RULE_REQUIRED,
            ]);

        /** @var Setting $oUrlServe */
        $oUrlServe = Factory::factory('ComponentSetting');
        $oUrlServe
            ->setKey(static::KEY_URL_SERVE)
            ->setLabel('Serving URL')
            ->setFieldset('URLs')
            ->setDefault('https://{{bucket}}.s3.amazonaws.com')
            ->setInfo('Value will be passed into <code>siteUrl()</code>')
            ->setValidation([<commit_msg>Access secret should be a password field<commit_after><?php

namespace Nails\Cdn\Driver\Aws\Settings;

use Nails\Common\Helper\Form;
use Nails\Common\Interfaces;
use Nails\Common\Service\FormValidation;
use Nails\Components\Setting;
use Nails\Factory;

/**
 * Class Aws
 *
 * @package Nails\Cdn\Driver\Aws\Settings
 */
class Aws implements Interfaces\Component\Settings
{
    const KEY_ACCESS_KEY         = 'access_key';
    const KEY_ACCESS_SECRET      = 'access_secret';
    const KEY_BUCKETS            = 'buckets';
    const KEY_URL_SERVE          = 'uri_serve';
    const KEY_URL_SERVE_SECURE   = 'uri_serve_secure';
    const KEY_URL_PROCESS        = 'uri_process';
    const KEY_URL_PROCESS_SECURE = 'uri_process_secure';

    // --------------------------------------------------------------------------

    /**
     * @inheritDoc
     */
    public function getLabel(): string
    {
        return 'CDN: AWS S3';
    }

    // --------------------------------------------------------------------------

    /**
     * @inheritDoc
     */
    public function get(): array
    {
        /** @var Setting $oAccessKey */
        $oAccessKey = Factory::factory('ComponentSetting');
        $oAccessKey
            ->setKey(static::KEY_ACCESS_KEY)
            ->setLabel('Access Key')
            ->setEncrypted(true)
            ->setFieldset('Credentials')
            ->setValidation([
                FormValidation::RULE_REQUIRED,
            ]);

        /** @var Setting $oAccessSecret */
        $oAccessSecret = Factory::factory('ComponentSetting');
        $oAccessSecret
            ->setKey(static::KEY_ACCESS_SECRET)
            ->setType(Form::FIELD_PASSWORD)
            ->setLabel('Access Secret')
            ->setEncrypted(true)
            ->setFieldset('Credentials')
            ->setValidation([
                FormValidation::RULE_REQUIRED,
            ]);

        /** @var Setting $oBuckets */
        $oBuckets = Factory::factory('ComponentSetting');
        $oBuckets
            ->setKey(static::KEY_BUCKETS)
            ->setType(Form::FIELD_TEXTAREA)
            ->setLabel('Buckets')
            ->setFieldset('Buckets')
            ->setInfo('Buckets should be specified as a JSON object with the environment as the key, and the region and bucket as the value. e.g. <code>{"PRODUCTION":"eu-west-1:my-bucket"}</code>')
            ->setValidation([
                FormValidation::RULE_REQUIRED,
            ]);

        /** @var Setting $oUrlServe */
        $oUrlServe = Factory::factory('ComponentSetting');
        $oUrlServe
            ->setKey(static::KEY_URL_SERVE)
            ->setLabel('Serving URL')
            ->setFieldset('URLs')
            ->setDefault('https://{{bucket}}.s3.amazonaws.com')
            ->setInfo('Value will be passed into <code>siteUrl()</code>')
            ->setValidation([
{'fraction_non_alphanumeric': 0.17593744446419052, 'fraction_numerical': 0.0010662875422072153, 'mean_word_length': 1.8125937031484258, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 56, 'https://': 2, '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': '1040810', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1543, 'n_words': 278}