setApiKey

Check if the string provided is a valid API key and use it
when performing requests to Konduto API.

@param string
967189
public static function setApiKey($key) {
        if (self::isValidKey($key)) {
            self::$key = $key;
            self::$useSSL = $key[0] == 'P';
            return true;
        }
        throw new Exceptions\InvalidAPIKeyException("Invalid API key: $key");
    }
120067
protected function _validateApiSettings($storeId, $apiKey, $hostname)
    {
        $invalidSettings = [];
        if ($storeId === '') {
            $invalidSettings[] = 'Store Id';
        }
        if ($apiKey === '') {
            $invalidSettings[] = 'API Key';
        }
        if ($hostname === '') {
            $invalidSettings[] = 'API Hostname';
        }
        if (!empty($invalidSettings)) {
            throw new Radial_Core_Exception_Api_Configuration(
                $this->_helper->__(self::INVALID_API_SETTINGS_ERROR_MESSAGE, implode(', ', $invalidSettings))
            );
        }
        return $this;
    }
1182408
protected function setCryptoKey($cryptokey): void
    {
        if (! is_string($cryptokey)) {
            throw StrictTypeException::cryptoKeyNotString($cryptokey);
        }
        if (ctype_xdigit($cryptokey)) {
            $len = strlen($cryptokey);
            $cryptokey = sodium_hex2bin($cryptokey);
        }
        // insert check here to make sure is binary integer
        if (! isset($len)) {
            $hex = sodium_bin2hex($cryptokey);
            $len = strlen($hex);
            sodium_memzero($hex);
        }
        if ($len !== 64) {
            throw InvalidArgumentException::wrongByteSizeKey($len);
        }
        if (ctype_print($cryptokey)) {
            throw InvalidArgumentException::secretOnlyPrintable();
        }
        //test that the key supplied works
        $string = 'ABC test 123 test xyz';
        $TEST_NONCE = sodium_hex2bin('74b9e852b172df7f57ff4ab4');
        if ($this->aesgcm) {
            $ciphertext = sodium_crypto_aead_aes256gcm_encrypt($string, $TEST_NONCE, $TEST_NONCE, $cryptokey);
            $test = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $TEST_NONCE, $TEST_NONCE, $cryptokey);
        } else {
            $ciphertext = sodium_crypto_aead_chacha20poly1305_encrypt($string, $TEST_NONCE, $TEST_NONCE, $cryptokey);
            $test = sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, $TEST_NONCE, $TEST_NONCE, $cryptokey);
        }
        if ($string === $test) {
            $this->cryptokey = $cryptokey;
            $this->enabled = true;
            sodium_memzero($cryptokey);
            return;
        }
        return;
    }
667569
@Deprecated
  public JSONObject updateUserKey(String key, JSONObject params) throws AlgoliaException {
    return updateApiKey(key, params);
  }
330891
private static void validateVarValue(String varValue) throws ApiException {
		if (varValue == null) {
			throw new ApiException(ApiException.Type.DOES_NOT_EXIST, PARAM_VAR_KEY);
		}
	}
335203
public void setPayloadProperty(Object data, Object msg, String strKey, Class<?> classKey)
   {
       String name = "set" + strKey;
       try {
           Class<?>[] params = {classKey};
           Method method = msg.getClass().getMethod(name, params);
           if (method != null)
           {
               Object[] datas = new Object[1];
               if (data != null)
                   if (!classKey.isAssignableFrom(data.getClass()))
                   {
                       data = this.convertObjectToDatatype(data, classKey);
                   }
               datas[0] = data;
               method.invoke(msg, datas);
           }
       } catch (SecurityException e) {
           e.printStackTrace();
       } catch (NoSuchMethodException e) {
           // Ignore this one
       } catch (InvocationTargetException e) {
           e.printStackTrace();
       } catch (IllegalAccessException e) {
           e.printStackTrace();
       }
       
   }
425449
public void setApi(String api) {
        api = api.trim();
        if ("liberty".equalsIgnoreCase(api)) {
            this.api = "liberty";
        } else if ("websphere".equalsIgnoreCase(api)) {
            this.api = "tr";
        } else if ("tr".equalsIgnoreCase(api)) {
            this.api = "tr";
        } else if ("jsr47".equalsIgnoreCase(api)) {
            this.api = "java-logging";
        } else if ("java".equalsIgnoreCase(api)) {
            this.api = "java-logging";
        } else if ("java.logging".equalsIgnoreCase(api)) {
            this.api = "java-logging";
        } else if ("java-logging".equalsIgnoreCase(api)) {
            this.api = "java-logging";
        } else {
            log("Invalid trace type " + api, Project.MSG_ERR);
        }
    }
1236263
private function checkValidationQueueErrors(string $paramName): void
    {
        if ($this->getValidationErrors()->count() > 0) {
            foreach ($this->getValidationErrors()->get() as $error) {
                $this->getJsonErrors()->addValidationQueryError($paramName, $error);
            }

            throw new JsonApiException($this->getJsonErrors());
        }
    }
193588
private function validateRequiredKey(array $item, string $key) : void
    {
        if (!isset($item[$key])) {
            throw new JsonRpcInvalidRequestException(
                $item,
                sprintf('"%s" is a required key', $key)
            );
        }
    }
58973
@Override
    public TDClient withApiKey(String newApiKey)
    {
        return new TDClient(config, httpClient, Optional.of(newApiKey));
    }
113138
public function checkOperationality()
    {
        // First check for curl requirements
        parent::checkOperationality();

        $apiKey = $this->getKey();

        if ($apiKey === false) {
            throw new InvalidApiKeyException('Missing API key.');
        }

        if (strlen($apiKey) < 20) {
            throw new InvalidApiKeyException(
                'Key is invalid. Keys are supposed to be 32 characters long - your key is much shorter'
            );
        }

        $keyStatus = self::getKeyStatus($apiKey);
        switch ($keyStatus) {
            case 'great':
                break;
            case 'exceeded':
                throw new ConverterNotOperationalException('quota has exceeded');
                break;
            case 'invalid':
                throw new InvalidApiKeyException('key is invalid');
                break;
        }
    }
1344401
protected function setApiClient()
    {
        $apiDomain = "https://{$this->domain}";

        $client = new ApiClient(
            [
                'domain' => $apiDomain,
                'basePath' => '/',
                'guzzleOptions' => $this->guzzleOptions
            ]
        );

        $this->apiClient = $client;
    }
1078004
protected function validateKey(/*# string */ &$key)
    {
        // validate key
        if (is_string($key)) {
            $key = trim($key);
            return;
        }

        // throw exception
        throw new InvalidArgumentException(
            Message::get(Message::CACHE_INVALID_KEY, $key),
            Message::CACHE_INVALID_KEY
        );
    }
1207330
public void setRequestProperty(String key, Object value) {
		if (value != null) {
			if (requestProperties == null) {
				requestProperties = new HashMap<>();
			}
			requestProperties.put(key, value);
		}
	}
432936
private function assertKeysArrayValid($keys = null)
    {
        if ((!$keys) ||
            (!is_array($keys)) ||
            (!isset($keys['auth'])) || 
            (!is_array($keys['auth'])) ||
            (!isset($keys['auth']['req'])) || 
            (!is_array($keys['auth']['req'])) ||
            (!isset($keys['auth']['opt'])) || 
            (!is_array($keys['auth']['opt'])) ||
            (!isset($keys['args'])) || 
            (!is_array($keys['args'])) ||
            (!isset($keys['args']['req'])) || 
            (!is_array($keys['auth']['req'])) ||
            (!isset($keys['args']['opt'])) || 
            (!is_array($keys['auth']['opt']))
        ) {
            $msg = 'Invalid API keys provided. (HINT: Each '
                 . 'API class must define a $keys array with '
                 . 'specific key requirements. (HINT: View an /Api/[file] '
                 . 'for an example.)';
            throw new ApiException($msg);
        }
    }
1115182
public function setUserAgent( $string )
	{
		if( empty( $string ) )
			throw new InvaligArgumentException( 'Must be set' );
		$this->curl->setOption( CURLOPT_USERAGENT, $string );
	}
829330
public void setBytes(String key, byte[] bytes) {
		String encoded = new String(Base64.encodeBase64(bytes));
		setStringInternal(key, encoded);
	}