github.com/outbrain/consul@v1.4.5/ui-v2/app/services/settings.js (about)

     1  import Service from '@ember/service';
     2  import { Promise } from 'rsvp';
     3  import { get } from '@ember/object';
     4  import getStorage from 'consul-ui/utils/storage/local-storage';
     5  const SCHEME = 'consul';
     6  const storage = getStorage(SCHEME);
     7  export default Service.extend({
     8    storage: storage,
     9    findHeaders: function() {
    10      // TODO: if possible this should be a promise
    11      // TODO: Actually this has nothing to do with settings it should be in the adapter,
    12      // which probably can't work with a promise based interface :(
    13      const token = get(this, 'storage').getValue('token');
    14      // TODO: The old UI always sent ?token=
    15      // replicate the old functionality here
    16      // but remove this to be cleaner if its not necessary
    17      return {
    18        'X-Consul-Token': typeof token.SecretID === 'undefined' ? '' : token.SecretID,
    19      };
    20    },
    21    findAll: function(key) {
    22      return Promise.resolve(get(this, 'storage').all());
    23    },
    24    findBySlug: function(slug) {
    25      return Promise.resolve(get(this, 'storage').getValue(slug));
    26    },
    27    persist: function(obj) {
    28      const storage = get(this, 'storage');
    29      Object.keys(obj).forEach((item, i) => {
    30        storage.setValue(item, obj[item]);
    31      });
    32      return Promise.resolve(obj);
    33    },
    34    delete: function(obj) {
    35      // TODO: Loop through and delete the specified keys
    36      if (!Array.isArray(obj)) {
    37        obj = [obj];
    38      }
    39      const storage = get(this, 'storage');
    40      const item = obj.reduce(function(prev, item, i, arr) {
    41        storage.removeValue(item);
    42        return prev;
    43      }, {});
    44      return Promise.resolve(item);
    45    },
    46  });