<commit_before>module.exports = {
  platformName: 'digital_ocean',
  baseUrl: 'https://api.digitalocean.com/v2',
  actions: {
    list_all_servers: function(req) {
      req.options = {
        method: 'GET',  
        uri: `${module.exports.baseUrl}/droplets`
      };
    },
    list_all_images: function(req) {
      req.options = {
        method: 'GET',  
        uri: `${module.exports.baseUrl}/images`
      };
    },
    delete_server: function(req) {
      if (!req.body) { throw new Error('Request body not present') }
      if (!req.body.server_id) { throw new Error('No target ID specified on req.body to be deleted') }
      req.options = {
        method: 'DELETE',  
        uri: `${module.exports.baseUrl}/droplets`, 
        body: {id: req.body.server_id},
        json: true
      };
    },
    create_server: function(req) {
      if (!req.body) { throw new Error('Request body not present') }
      if (!(req.body.name && req.body.region && req.body.size && req.body.image_id)) { 
        throw new Error('Name, region, size, or image not specified in req.body for the new server to be created.') 
      }
      req.options = {
        method: 'POST',
        uri: `${module.exports.baseUrl}/droplets`, 
        body: {
          name: req.body.name, 
          region: req.body.region, 
          size: req.body.size, 
          image: req.body.image_id
        },
        json: true
      };
    },
    reboot_server: function(req) {
      req.options = {
        method: 'POST', 
        uri: `${module.exports.baseUrl}/droplets/${req.body.server_id}/actions`, 
        body: {'type': 'reboot'},
        json: true
      };
    },
    power_on_server: function(req) {
      req.options = {
        method: 'POST', 
        uri: `${module.exports.baseUrl}/droplets/${req.body.server_id}/actions`, 
        body: {'type': 'power_on'},
        json: true
      };
    },
    power_off_server: function(req) {
      req.options = {
        method: 'POST', 
        uri: `${module.exports.baseUrl}/droplets/${req.body.server_id}/actions`, 
        body: {'type': 'power_off'},
        json: true
      };
    },
    shutdown_server: function(req) {
      req.options = {
        method: 'POST', 
        uri: `${module.exports.baseUrl}/droplets/${req.body.server_id}/actions`, 
        body: {'type': 'shutdown'},
        json: true
      };
    }
  },

  parsers: {
    list_all_servers: function (res) {
      var parsedData = {
        servers: []
      };

      var resJSON = JSON.parse(res);
      
      if (!resJSON || !resJSON.droplets) {
        return parsedData;
      }
      
      for (var idx = 0; idx < resJSON.droplets.length; idx++) {
        var droplet = resJSON.droplets[idx];
        var server = {
          name: droplet.name,
          /* assume it's the first ipv4 address */
          ip: droplet.networks.v4[0].ip_address,
          server_id: droplet.id,
          platform: 'digital_ocean',
          platformSpecific: {
            imageID: droplet.image.id,
            region: droplet.region.slug,
            size: droplet.size.slug,
            status: droplet.status
          }
        };
        parsedData.servers.push(server);
      }
      return parsedData;
    },
    list_all_images: function (res) {
      //something
    },
  },

  authorize: function(req) {
    req.options.headers = (function(username, server_id) {
      // TODO: get the token based on username and server_id / token join table
      var token = '3d378deef838cafa1647d6572d99efb50522395a692a33e59bbb8249ae202e50'
      //
      return {'Authorization': 'Bearer ' + token};
    })();
  }
}
<commit_msg>fix api url to get all digitalocean images<commit_after>module.exports = {
  platformName: 'digital_ocean',
  baseUrl: 'https://api.digitalocean.com/v2',
  actions: {
    list_all_servers: function(req) {
      req.options = {
        method: 'GET',  
        uri: `${module.exports.baseUrl}/droplets`
      };
    },
    list_all_images: function(req) {
      req.options = {
        method: 'GET',  
        uri: `${module.exports.baseUrl}/images?private=true`
      };
    },
    delete_server: function(req) {
      if (!req.body) { throw new Error('Request body not present') }
      if (!req.body.server_id) { throw new Error('No target ID specified on req.body to be deleted') }
      req.options = {
        method: 'DELETE',  
        uri: `${module.exports.baseUrl}/droplets`, 
        body: {id: req.body.server_id},
        json: true
      };
    },
    create_server: function(req) {
      if (!req.body) { throw new Error('Request body not present') }
      if (!(req.body.name && req.body.region && req.body.size && req.body.image_id)) { 
        throw new Error('Name, region, size, or image not specified in req.body for the new server to be created.') 
      }
      req.options = {
        method: 'POST',
        uri: `${module.exports.baseUrl}/droplets`, 
        body: {
          name: req.body.name, 
          region: req.body.region, 
          size: req.body.size, 
          image: req.body.image_id
        },
        json: true
      };
    },
    reboot_server: function(req) {
      req.options = {
        method: 'POST', 
        uri: `${module.exports.baseUrl}/droplets/${req.body.server_id}/actions`, 
        body: {'type': 'reboot'},
        json: true
      };
    },
    power_on_server: function(req) {
      req.options = {
        method: 'POST', 
        uri: `${module.exports.baseUrl}/droplets/${req.body.server_id}/actions`, 
        body: {'type': 'power_on'},
        json: true
      };
    },
    power_off_server: function(req) {
      req.options = {
        method: 'POST', 
        uri: `${module.exports.baseUrl}/droplets/${req.body.server_id}/actions`, 
        body: {'type': 'power_off'},
        json: true
      };
    },
    shutdown_server: function(req) {
      req.options = {
        method: 'POST', 
        uri: `${module.exports.baseUrl}/droplets/${req.body.server_id}/actions`, 
        body: {'type': 'shutdown'},
        json: true
      };
    }
  },

  parsers: {
    list_all_servers: function (res) {
      var parsedData = {
        servers: []
      };

      var resJSON = JSON.parse(res);
      
      if (!resJSON || !resJSON.droplets) {
        return parsedData;
      }
      
      for (var idx = 0; idx < resJSON.droplets.length; idx++) {
        var droplet = resJSON.droplets[idx];
        var server = {
          name: droplet.name,
          /* assume it's the first ipv4 address */
          ip: droplet.networks.v4[0].ip_address,
          server_id: droplet.id,
          platform: 'digital_ocean',
          platformSpecific: {
            imageID: droplet.image.id,
            region: droplet.region.slug,
            size: droplet.size.slug,
            status: droplet.status
          }
        };
        parsedData.servers.push(server);
      }
      return parsedData;
    },
    list_all_images: function (res) {
      //something
    },
  },

  authorize: function(req) {
    req.options.headers = (function(username, server_id) {
      // TODO: get the token based on username and server_id / token join table
      var token = '3d378deef838cafa1647d6572d99efb50522395a692a33e59bbb8249ae202e50'
      //
      return {'Authorization': 'Bearer ' + token};
    })();
  }
}

{'fraction_non_alphanumeric': 0.1430133989608969, 'fraction_numerical': 0.012578616352201259, 'mean_word_length': 1.971161657189277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7480147', 'n_tokens_mistral': 2402, 'n_tokens_neox': 2305, 'n_words': 469}