<commit_before>//  Copyright 2014 Rackspace, Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing,
//  software distributed under the License is distributed on an "AS
//  IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
//  express or implied. See the License for the specific language
//  governing permissions and limitations under the License.

/*
 *  ZeroVM on Swift (Zwift) client.
 */
function ZwiftClient(swiftUrl) {
    this._swiftUrl = swiftUrl;
    this._token = null;
}

/*
 * Authenticate to Keystone. Call this before calling other methods
 * that talk with Swift, if you're not already authenticated.
 *
 * If Keystone and Swift are served from differnet domains, you must
 * install a CORS (Cross-Origin Resource Sharing) middleware in Swift.
 * Otherwise the authentication requests made by this function wont be
 * allowed by the browser.
 */
ZwiftClient.prototype.auth = function (opts, success) {
    var defaults = {'version': 2, 'success': $.noop};
    var args = {'success': success};
    var merged = $.extend(defaults, opts, args);
    if (merged.version == 1) {
        this._auth1(merged);
     } else {
        this._auth2(merged);
    }
}

/*
 * Swift v1 authentication.
 */
ZwiftClient.prototype._auth1 = function (opts) {
    var self = this;
    $.ajax({
        'type': 'GET',
        'url': opts.authUrl,
        'cache': false,
        'headers': {
            'X-Auth-User': opts.username,
            'X-Auth-Key': opts.password
        },
        'success': function (data, status, xhr) {
            self._token = xhr.getResponseHeader('X-Auth-Token');
            self._swiftUrl = xhr.getResponseHeader('X-Storage-Url');
            opts.success();
        }
    });
}

/*
 * Swift v2 authentication. This will login to Keystone and obtain an
 * authentication token.
 */<commit_msg>templates/zebra: document opts keys needed for auth methods<commit_after>//  Copyright 2014 Rackspace, Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing,
//  software distributed under the License is distributed on an "AS
//  IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
//  express or implied. See the License for the specific language
//  governing permissions and limitations under the License.

/*
 *  ZeroVM on Swift (Zwift) client.
 */
function ZwiftClient(swiftUrl) {
    this._swiftUrl = swiftUrl;
    this._token = null;
}

/*
 * Authenticate to Keystone. Call this before calling other methods
 * that talk with Swift, if you're not already authenticated.
 *
 * If Keystone and Swift are served from differnet domains, you must
 * install a CORS (Cross-Origin Resource Sharing) middleware in Swift.
 * Otherwise the authentication requests made by this function wont be
 * allowed by the browser.
 */
ZwiftClient.prototype.auth = function (opts, success) {
    var defaults = {'version': 2, 'success': $.noop};
    var args = {'success': success};
    var merged = $.extend(defaults, opts, args);
    if (merged.version == 1) {
        this._auth1(merged);
     } else {
        this._auth2(merged);
    }
}

/*
 * Swift v1 authentication.
 *
 * The opts argument is a plain object with these keys:
 *
 * - authURL
 * - username
 * - password
 */
ZwiftClient.prototype._auth1 = function (opts) {
    var self = this;
    $.ajax({
        'type': 'GET',
        'url': opts.authUrl,
        'cache': false,
        'headers': {
            'X-Auth-User': opts.username,
            'X-Auth-Key': opts.password
        },
        'success': function (data, status, xhr) {
            self._token = xhr.getResponseHeader('X-Auth-Token');
            self._swiftUrl = xhr.getResponseHeader('X-Storage-Url');
            opts.success();
        }
    });
}

/*
 * Swift v2 authentication. This will login to Keystone and obtain an
 * authentication token.
 *
 * The opts argument is a plain object with these keys:
 *
 * - authURL
 * - username
 * - password
 * - tenant
 */
{'fraction_non_alphanumeric': 0.11510791366906475, 'fraction_numerical': 0.006744604316546762, 'mean_word_length': 2.68294701986755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '209215', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1257, 'n_words': 464}