xanthus 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66257493ff2d3fe1d22a7ca0706fdf65ee3bb61d7546ed5d63372dab6b5e603a
4
- data.tar.gz: fd7b4332a60cb729740443a33edbfc199ac971d5b928ae67d500b85bcbb34e51
3
+ metadata.gz: 2b041aa460e8d8de1945b504ee7527a776d0cb338fe16ab594a3462cece5ef85
4
+ data.tar.gz: 167816e4a9725fe18b7b989a21a56adc8b22bab1d50d9032566a28c12027ea0f
5
5
  SHA512:
6
- metadata.gz: a1d94ad4ee1548a22e23106d0fc3728d6595794f1f7e05ad86a831aa97547921a08c33be44e9d95688dbae5d234cd0a936f1ed65e5ed8f1e173fb7b41a03d05c
7
- data.tar.gz: 4437c5b2b627079279b1c08655b22ec6009dd7b3d96300e2bccd38161873d0fe8d37547cf90e2f635ca6f788e0475ff360214c9d706263a7003126dc05ba405e
6
+ metadata.gz: 7132c95f0535f042b0ebd54df8e1d09076e951fda8903e6cd0e1d447817a7c93b893f2eb15aa736a49b5cd12560b19b951c1d450f4ef53a1ac479578099747e5
7
+ data.tar.gz: 46ee72461803cf16f538b7d1625e847dd02023dd1fc42f476c7f37d99779685ecaff9c0f33b80d456cb7da4cc96c5cb0d1042c95734d5c79b62384f7f3ea1475
data/lib/xanthus.rb CHANGED
@@ -4,7 +4,9 @@ require "xanthus/script"
4
4
  require "xanthus/virtual_machine"
5
5
  require "xanthus/job"
6
6
  require "xanthus/default"
7
+ require "xanthus/repository"
7
8
  require "xanthus/github"
9
+ require "xanthus/dataverse"
8
10
  require "xanthus/configuration"
9
11
 
10
12
  module Xanthus
@@ -2,6 +2,8 @@ module Xanthus
2
2
  class Configuration
3
3
  attr_accessor :name
4
4
  attr_accessor :authors
5
+ attr_accessor :affiliation
6
+ attr_accessor :email
5
7
  attr_accessor :description
6
8
  attr_accessor :seed
7
9
  attr_accessor :params
@@ -9,6 +11,7 @@ module Xanthus
9
11
  attr_accessor :scripts
10
12
  attr_accessor :jobs
11
13
  attr_accessor :github_conf
14
+ attr_accessor :dataverse_conf
12
15
 
13
16
  def initialize
14
17
  @params = Hash.new
@@ -41,13 +44,21 @@ module Xanthus
41
44
  @github_conf = github
42
45
  end
43
46
 
47
+ def dataverse
48
+ dataverse = Dataverse.new
49
+ yield(dataverse)
50
+ @dataverse_conf = dataverse
51
+ end
52
+
44
53
  def to_readme_md
45
54
  %Q{
46
55
  # #{@name}
47
56
 
48
- Authors: #{@authors}
57
+ authors: #{@authors}
58
+ affiliation: #{@affiliation}
59
+ email: #{@email}
49
60
 
50
- Seed: #{@seed}
61
+ seed: #{@seed}
51
62
 
52
63
  ## Description
53
64
 
@@ -64,12 +75,19 @@ Seed: #{@seed}
64
75
  config.vms.each do |k, v|
65
76
  v.generate_box config
66
77
  end
78
+
79
+ # initializing storage backends
67
80
  config.github_conf.init(config) unless config.github_conf.nil?
81
+ config.dataverse_conf.init(config) unless config.dataverse_conf.nil?
82
+
83
+ # executing jobs
68
84
  config.jobs.each do |name,job|
69
85
  for i in 0..(job.iterations-1) do
70
86
  job.execute config, i
71
87
  end
72
88
  end
89
+
90
+ # finalizing storage backends
73
91
  config.github_conf.tag unless config.github_conf.nil?
74
92
  config.github_conf.clean unless config.github_conf.nil?
75
93
  end
@@ -0,0 +1,179 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+
4
+ module Xanthus
5
+ class Dataverse < Repository
6
+ attr_accessor :server
7
+ attr_accessor :repo
8
+ attr_accessor :token
9
+ attr_accessor :dataset_name
10
+ attr_accessor :author
11
+ attr_accessor :affiliation
12
+ attr_accessor :email
13
+ attr_accessor :description
14
+ attr_accessor :subject
15
+ attr_accessor :doi
16
+
17
+ def initialize
18
+ super
19
+ @server = 'default_server'
20
+ @repo = 'default_repo'
21
+ @token = 'default_token'
22
+ @dataset_name = 'default_name'
23
+ @author = 'default_author'
24
+ @affiliation = 'default_affiliation'
25
+ @email = 'default_email'
26
+ @description = 'default_description'
27
+ @subject = 'default_subject'
28
+ @doi = 'not_set'
29
+ end
30
+
31
+ def dataset_json
32
+ json = %Q{
33
+ {
34
+ "datasetVersion": {
35
+ "metadataBlocks": {
36
+ "citation": {
37
+ "fields": [
38
+ {
39
+ "value": "#{@dataset_name}",
40
+ "typeClass": "primitive",
41
+ "multiple": false,
42
+ "typeName": "title"
43
+ },
44
+ {
45
+ "value": [
46
+ {
47
+ "authorName": {
48
+ "value": "#{@author}",
49
+ "typeClass": "primitive",
50
+ "multiple": false,
51
+ "typeName": "authorName"
52
+ },
53
+ "authorAffiliation": {
54
+ "value": "#{@affiliation}",
55
+ "typeClass": "primitive",
56
+ "multiple": false,
57
+ "typeName": "authorAffiliation"
58
+ }
59
+ }
60
+ ],
61
+ "typeClass": "compound",
62
+ "multiple": true,
63
+ "typeName": "author"
64
+ },
65
+ {
66
+ "value": [
67
+ { "datasetContactEmail" : {
68
+ "typeClass": "primitive",
69
+ "multiple": false,
70
+ "typeName": "datasetContactEmail",
71
+ "value" : "#{@email}"
72
+ },
73
+ "datasetContactName" : {
74
+ "typeClass": "primitive",
75
+ "multiple": false,
76
+ "typeName": "datasetContactName",
77
+ "value": "#{@author}"
78
+ }
79
+ }],
80
+ "typeClass": "compound",
81
+ "multiple": true,
82
+ "typeName": "datasetContact"
83
+ },
84
+ {
85
+ "value": [ {
86
+ "dsDescriptionValue":{
87
+ "value": "#{@description.gsub(/\r/," ").gsub(/\n/," ")}",
88
+ "multiple":false,
89
+ "typeClass": "primitive",
90
+ "typeName": "dsDescriptionValue"
91
+ }}],
92
+ "typeClass": "compound",
93
+ "multiple": true,
94
+ "typeName": "dsDescription"
95
+ },
96
+ {
97
+ "value": [
98
+ "#{@subject}"
99
+ ],
100
+ "typeClass": "controlledVocabulary",
101
+ "multiple": true,
102
+ "typeName": "subject"
103
+ }
104
+ ],
105
+ "displayName": "Citation Metadata"
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ return json
112
+ end
113
+
114
+ def create_dataset
115
+ Dir.chdir 'dataverse_dataset' do
116
+ File.open('dataset.json', 'w+') do |f|
117
+ f.write(self.dataset_json)
118
+ end
119
+ puts "Creating dataverse #{@dataset_name} in #{@repo} at #{@server}..."
120
+ output = `curl -H X-Dataverse-key:#{@token} -X POST #{@server}/api/dataverses/#{@repo}/datasets --upload-file dataset.json`
121
+ puts output # needed to escape curl output
122
+ parsed = JSON.parse(output)
123
+ @doi = parsed['data']['persistentId']
124
+ puts "Dataverse #{@doi} created."
125
+ end
126
+ end
127
+
128
+ def init config
129
+ # initialize with config information
130
+ @author = config.authors
131
+ @affiliation = config.affiliation
132
+ @email = config.email
133
+ @description = config.description
134
+ @dataset_name = config.name+'-'+Time.now.strftime("%Y-%m-%d_%H-%M")
135
+
136
+ FileUtils.mkdir_p 'dataverse_dataset'
137
+ self.create_dataset
138
+ Dir.chdir 'dataverse_dataset' do
139
+ FileUtils.mkdir_p 'repo'
140
+ Dir.chdir 'repo' do
141
+ self.xanthus_file
142
+ self.readme_file config
143
+ self.inputs_file config
144
+ end
145
+ end
146
+ end
147
+
148
+ def add_file_to_dataverse name, description, folder
149
+ output = `curl -H X-Dataverse-key:#{@token} -X POST -F "file=@#{name}" -F 'jsonData={"description":"#{description}","directoryLabel":"#{folder}","categories":["Data"], "restrict":"false"}' "#{@server}/api/datasets/:persistentId/add?persistentId=#{@doi}"`
150
+ puts output
151
+ end
152
+
153
+ def xanthus_file
154
+ self.prepare_xanthus_file
155
+ self.add_file_to_dataverse '.xanthus', 'xanthus file used to generate the data.', 'metadata'
156
+ end
157
+
158
+ def readme_file config
159
+ self.prepare_readme_file config
160
+ self.add_file_to_dataverse 'README.md', 'readme describing the dataset.', 'metadata'
161
+ end
162
+
163
+ def inputs_file config
164
+ config.jobs.each do |name,job|
165
+ job.inputs.each do |k, files|
166
+ files.each do |file|
167
+ system('cp', '-f', "../../#{file}", "#{file}")
168
+ self.add_file_to_dataverse file, 'Job input file.', 'metadata'
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ def add content
175
+ self.add_file_to_dataverse content, "#{content} is a Xanthus generated file (check metadata for description)", 'data'
176
+ end
177
+
178
+ end
179
+ end
@@ -1,12 +1,13 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module Xanthus
4
- class GitHub
4
+ class GitHub < Repository
5
5
  attr_accessor :repo
6
6
  attr_accessor :token
7
7
  attr_accessor :folder
8
8
 
9
9
  def initialize
10
+ super
10
11
  @repo = ''
11
12
  @token = ''
12
13
  @folder = Time.now.strftime("%Y-%m-%d_%H-%M")
@@ -20,23 +21,14 @@ module Xanthus
20
21
  end
21
22
 
22
23
  def xanthus_file
23
- script = ''
24
- File.readlines('../../.xanthus').each do |line|
25
- script += line unless line.include? 'github.token'
26
- script += "\t\tgithub.token = 'REMOVED'\n" unless !line.include? 'github.token'
27
- end
28
- File.open('.xanthus', 'w+') do |f|
29
- f.write(script)
30
- end
24
+ self.prepare_xanthus_file
31
25
  system('git', 'add', '.xanthus')
32
26
  system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/.xanthus :horse:")
33
27
  system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
34
28
  end
35
29
 
36
30
  def readme_file config
37
- File.open('README.md', 'w+') do |f|
38
- f.write(config.to_readme_md)
39
- end
31
+ self.prepare_readme_file config
40
32
  system('git', 'add', 'README.md')
41
33
  system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/README.md :horse:")
42
34
  system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
data/lib/xanthus/init.rb CHANGED
@@ -17,6 +17,8 @@ module Xanthus
17
17
  Xanthus.configure do |config|
18
18
  config.name = '#{@@name}'
19
19
  config.authors = 'John Doe'
20
+ config.affiliation = 'Somewhere University'
21
+ config.email = 'john.doe@somewhere.edu'
20
22
  config.description = %q{
21
23
  Describe my super experiment.
22
24
 
@@ -119,10 +121,17 @@ It is very cool and interesting!
119
121
  job.outputs = {spade: {trace: '/tmp/audit_cdm.avro'}}
120
122
  end
121
123
 
122
- config.github do |github|
123
- github.repo = '<ADD GITHUB REPO user/name>'
124
- github.token = '<ADD GITHUB TOKEN>'
124
+ config.dataverse do |dataverse|
125
+ dataverse.server = <ADD DATAVERSE BASE URL>
126
+ dataverse.repo = <PROVIDE DATAVERSE NAME>
127
+ dataverse.token = <PROVIDE DATAVERSE TOKEN>
128
+ dataverse.subject = <PROVIDE DATAVERSE SUBJECT (e.g. engineering)>
125
129
  end
130
+
131
+ # config.github do |github|
132
+ # github.repo = '<ADD GITHUB REPO user/name>'
133
+ # github.token = '<ADD GITHUB TOKEN>'
134
+ # end
126
135
  end
127
136
  }
128
137
  file.write(script)
data/lib/xanthus/job.rb CHANGED
@@ -19,10 +19,10 @@ module Xanthus
19
19
  @post_instructions = nil
20
20
  end
21
21
 
22
- def output_script outputs
23
- script = ''
22
+ def output_script machine, outputs
23
+ script = "vagrant plugin install vagrant-scp\n"
24
24
  outputs.each do |name, path|
25
- script += "cp -f #{path} /vagrant/output/#{name}.data\n"
25
+ script += "vagrant scp :#{path} output/#{name}.data\n"
26
26
  end
27
27
  return script
28
28
  end
@@ -45,10 +45,11 @@ module Xanthus
45
45
  File.open('provision.sh', 'w+') do |f|
46
46
  f.write(script)
47
47
  end
48
- script = self.output_script(@outputs[machine]) unless @outputs[machine].nil?
48
+ script = self.output_script(machine, @outputs[machine]) unless @outputs[machine].nil?
49
49
  File.open('before_halt.sh', 'w+') do |f|
50
50
  f.write(script)
51
51
  end
52
+ system('chmod', '+x', 'before_halt.sh')
52
53
  end
53
54
  end
54
55
 
@@ -123,6 +124,7 @@ module Xanthus
123
124
  system('rm', '-rf', "#{name.to_s}-#{iteration.to_s}")
124
125
  config.github_conf.add("#{name.to_s}-#{iteration.to_s}.tar.gz") unless config.github_conf.nil?
125
126
  config.github_conf.push unless config.github_conf.nil?
127
+ config.dataverse_conf.add("#{name.to_s}-#{iteration.to_s}.tar.gz") unless config.dataverse_conf.nil?
126
128
  puts "Job #{name.to_s}-#{iteration.to_s} done."
127
129
  end
128
130
  end
@@ -0,0 +1,28 @@
1
+ module Xanthus
2
+ class Repository
3
+
4
+ def initialize
5
+ end
6
+
7
+ def prepare_xanthus_file
8
+ script = ''
9
+ File.readlines('../../.xanthus').each do |line|
10
+ script += line unless line.include?('github.token') || line.include?('dataverse.token')
11
+
12
+ # remove github token
13
+ script += "\t\t# github.token = 'REMOVED'\n" unless !line.include? 'github.token'
14
+ # remove dataverse token
15
+ script += "\t\t# dataverse.token = 'REMOVED'\n" unless !line.include? 'dataverse.token'
16
+ end
17
+ File.open('.xanthus', 'w+') do |f|
18
+ f.write(script)
19
+ end
20
+ end
21
+
22
+ def prepare_readme_file config
23
+ File.open('README.md', 'w+') do |f|
24
+ f.write(config.to_readme_md)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module Xanthus
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
 
4
4
  def self.version
5
5
  puts VERSION
@@ -11,6 +11,14 @@ module Xanthus
11
11
  attr_accessor :boxing
12
12
  attr_accessor :ssh_username
13
13
  attr_accessor :ssh_key_path
14
+ attr_accessor :on_aws
15
+ attr_accessor :aws_env_key_id
16
+ attr_accessor :aws_env_key_secret
17
+ attr_accessor :aws_key_pair_name
18
+ attr_accessor :aws_region
19
+ attr_accessor :aws_ami
20
+ attr_accessor :aws_instance_type
21
+ attr_accessor :aws_security_group
14
22
 
15
23
  def initialize
16
24
  @name = :default
@@ -33,6 +41,9 @@ Vagrant.configure(2) do |config|
33
41
  config.vm.box_version = "#{@version}"
34
42
  config.vm.network "private_network", ip: "#{@ip}"
35
43
  }
44
+ script += %Q{
45
+ config.vm.synced_folder ".", "/vagrant", disabled: false, type: 'rsync'
46
+ } unless !@on_aws
36
47
  script += %Q{
37
48
  config.ssh.username = "#{@ssh_username}"
38
49
  } unless ssh_username.nil?
@@ -40,18 +51,30 @@ script += %Q{
40
51
  config.ssh.private_key_path = "#{@ssh_key_path}"
41
52
  } unless ssh_key_path.nil?
42
53
  script += %Q{
43
- config.vm.provider "virtualbox" do |vb|
54
+ config.vm.provider "virtualbox" do |vb, override|
44
55
  vb.gui = #{@gui}
45
56
  vb.memory = #{@memory}
46
57
  vb.customize ["modifyvm", :id, "--cpuexecutioncap", "#{@cpu_cap}"]
47
58
  vb.cpus = #{@cpus}
48
59
  vb.name = "#{@name}"
49
60
  end
50
- config.vm.provision "shell", path: "provision.sh"
61
+ } unless @on_aws
62
+ script += %Q{
63
+ config.vm.provider "aws" do |aws, override|
64
+ aws.access_key_id = ENV['#{@aws_env_key_id}']
65
+ aws.secret_access_key = ENV['#{@aws_env_key_secret}']
66
+ aws.keypair_name = '#{@aws_key_pair_name}'
67
+ aws.region = '#{@aws_region}'
68
+ aws.ami = '#{@aws_ami}'
69
+ aws.instance_type = '#{@aws_instance_type}'
70
+ aws.security_groups = ['#{@aws_security_group}']
71
+ end
72
+ } unless !@on_aws
73
+ script += %Q{ config.vm.provision "shell", path: "provision.sh"
51
74
 
52
75
  config.trigger.before :halt do |trigger|
53
76
  trigger.info = "Retrieving data before halt..."
54
- trigger.run_remote = {path: "before_halt.sh"}
77
+ trigger.run = {path: "before_halt.sh"}
55
78
  end
56
79
  end
57
80
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xanthus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Pasquier
@@ -9,34 +9,48 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-31 00:00:00.000000000 Z
12
+ date: 2020-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.3'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.3'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: bundler
16
30
  requirement: !ruby/object:Gem::Requirement
17
31
  requirements:
18
- - - ">="
32
+ - - "~>"
19
33
  - !ruby/object:Gem::Version
20
34
  version: '2.0'
21
35
  type: :development
22
36
  prerelease: false
23
37
  version_requirements: !ruby/object:Gem::Requirement
24
38
  requirements:
25
- - - ">="
39
+ - - "~>"
26
40
  - !ruby/object:Gem::Version
27
41
  version: '2.0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: rake
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
- - - ">="
46
+ - - "~>"
33
47
  - !ruby/object:Gem::Version
34
48
  version: '10.0'
35
49
  type: :development
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
- - - ">="
53
+ - - "~>"
40
54
  - !ruby/object:Gem::Version
41
55
  version: '10.0'
42
56
  description: Automated intrusion detection dataset generation framework.
@@ -52,10 +66,12 @@ files:
52
66
  - bin/xanthus
53
67
  - lib/xanthus.rb
54
68
  - lib/xanthus/configuration.rb
69
+ - lib/xanthus/dataverse.rb
55
70
  - lib/xanthus/default.rb
56
71
  - lib/xanthus/github.rb
57
72
  - lib/xanthus/init.rb
58
73
  - lib/xanthus/job.rb
74
+ - lib/xanthus/repository.rb
59
75
  - lib/xanthus/script.rb
60
76
  - lib/xanthus/version.rb
61
77
  - lib/xanthus/virtual_machine.rb
@@ -79,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
95
  version: '0'
80
96
  requirements: []
81
97
  rubyforge_project:
82
- rubygems_version: 2.7.6
98
+ rubygems_version: 2.7.6.2
83
99
  signing_key:
84
100
  specification_version: 4
85
101
  summary: Automated intrusion detection dataset generation framework.