<commit_before>'use strict';

let cli    = require('heroku-cli-util');
let co     = require('co');
let printf = require('printf');
let _      = require('lodash');
let _table  = require('../lib/table');

let dim = cli.color.dim;
let colorize = {
    app:        cli.color.cyan,
    attachment: cli.color.green,
    addon:      cli.color.magenta,
};

function table(data, options) {
    return _table(data, _.merge(options, {
        printLine: cli.log
    }));
}

// Gets *all* attachments and add-ons and filters locally because the API
// returns *owned* items not associated items.
function* addonGetter(api, app) {
    let attachments, addons;

    if(app) { // don't disploy attachments globally
        let sudoHeaders = JSON.parse(process.env.HEROKU_HEADERS);
        if(sudoHeaders['X-Heroku-Sudo'] && !sudoHeaders['X-Heroku-Sudo-User']) {
            // because the root /addon-attachments endpoint won't include relevant
            // attachments when sudo-ing for another app, we will use the more
            // specific API call and sacrifice listing foreign attachments.
            addons = api.request({
                method:  'GET',
                path:    `/apps/${app}/addons`,
                headers: {'Accept-Expansion': 'addon_service,plan'},
            });

            attachments = api.request({
                method:  'GET',
                path:    `/apps/${app}/addon-attachments`,<commit_msg>Fix case when HEROKU_HEADERS isn't present in env<commit_after>'use strict';

let cli    = require('heroku-cli-util');
let co     = require('co');
let printf = require('printf');
let _      = require('lodash');
let _table  = require('../lib/table');

let dim = cli.color.dim;
let colorize = {
    app:        cli.color.cyan,
    attachment: cli.color.green,
    addon:      cli.color.magenta,
};

function table(data, options) {
    return _table(data, _.merge(options, {
        printLine: cli.log
    }));
}

// Gets *all* attachments and add-ons and filters locally because the API
// returns *owned* items not associated items.
function* addonGetter(api, app) {
    let attachments, addons;

    if(app) { // don't disploy attachments globally
        let sudoHeaders = JSON.parse(process.env.HEROKU_HEADERS || '{}');
        if(sudoHeaders['X-Heroku-Sudo'] && !sudoHeaders['X-Heroku-Sudo-User']) {
            // because the root /addon-attachments endpoint won't include relevant
            // attachments when sudo-ing for another app, we will use the more
            // specific API call and sacrifice listing foreign attachments.
            addons = api.request({
                method:  'GET',
                path:    `/apps/${app}/addons`,
                headers: {'Accept-Expansion': 'addon_service,plan'},
            });

            attachments = api.request({
                method:  'GET',
                path:    `/apps/${app}/addon-attachments`,
{'fraction_non_alphanumeric': 0.13413793103448277, 'fraction_numerical': 0.0, 'mean_word_length': 2.3192219679633865, 'pattern_counts': {'":': 0, '<': 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': '2757745', 'n_tokens_mistral': 879, 'n_tokens_neox': 840, 'n_words': 226}