<commit_before>import { browserHistory } from 'react-router';
import Fetch, { errorHandler } from 'js-fetch';

const API = 'https://docker-api.vibioh.fr/';

function authRedirect(response) {
  if (response.status === 401) {
    browserHistory.push('/login');
  }
  return errorHandler(response);
}

function auth(url) {
  return Fetch.url(url)
    .auth(localStorage.getItem('auth'))
    .error(authRedirect);
}

export default class DockerService {
  static isLogged() {
    return !!localStorage.getItem('auth');
  }

  static login(login, password) {
    const hash = `Basic ${btoa(`${login}:${password}`)}`;

    return Fetch.url(`${API}auth`)
      .auth(hash)
      .get()
      .then(() => {
        localStorage.setItem('auth', hash);
      });
  }

  static containers() {
    return auth(`${API}containers`)
      .get()
      .then(({ results }) => results);
  }


  static infos(containerId) {
    return auth(`${API}containers/${containerId}/`)
      .get();
  }

  static create(name, composeFile) {
    return auth(`${API}containers/${name}/`)
      .post(composeFile);
  }

  static start(containerId) {
    return auth(`${API}containers/${containerId}/start`)
      .post();
  }

  static stop(containerId) {
    return auth(`${API}containers/${containerId}/stop`)
      .post();
  }

  static restart(containerId) {<commit_msg>Adding logout service<commit_after>import { browserHistory } from 'react-router';
import Fetch, { errorHandler } from 'js-fetch';

const API = 'https://docker-api.vibioh.fr/';
const authStorage = 'auth';

function authRedirect(response) {
  if (response.status === 401) {
    browserHistory.push('/login');
  }
  return errorHandler(response);
}

function auth(url) {
  return Fetch.url(url)
    .auth(localStorage.getItem(authStorage))
    .error(authRedirect);
}

export default class DockerService {
  static isLogged() {
    return !!localStorage.getItem(authStorage);
  }

  static login(login, password) {
    const hash = `Basic ${btoa(`${login}:${password}`)}`;

    return Fetch.url(`${API}auth`)
      .auth(hash)
      .get()
      .then(() => {
        localStorage.setItem(authStorage, hash);
      });
  }

  static logout() {
    localStorage.removeItem(authStorage);
  }

  static containers() {
    return auth(`${API}containers`)
      .get()
      .then(({ results }) => results);
  }


  static infos(containerId) {
    return auth(`${API}containers/${containerId}/`)
      .get();
  }

  static create(name, composeFile) {
    return auth(`${API}containers/${name}/`)
      .post(composeFile);
  }

  static start(containerId) {
    return auth(`${API}containers/${containerId}/start`)
      .post();
  }

  static stop(containerId) {
    return auth(`${API}containers/${containerId}/stop`)
      .post();
  }

  static restart(containerId) {
{'fraction_non_alphanumeric': 0.1752136752136752, 'fraction_numerical': 0.002136752136752137, 'mean_word_length': 3.3753894080996885, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '790157', 'n_tokens_mistral': 924, 'n_tokens_neox': 905, 'n_words': 166}