misp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MISP
4
+ class Orgc < Base
5
+ attr_reader :id
6
+ attr_reader :name
7
+ attr_reader :uuid
8
+
9
+ def initialize(**attributes)
10
+ attributes = normalize_attributes(attributes)
11
+
12
+ @id = attributes.dig(:id)
13
+ @name = attributes.dig(:name)
14
+ @uuid = attributes.dig(:uuid)
15
+ end
16
+
17
+ def to_h
18
+ {
19
+ id: id,
20
+ name: name,
21
+ uuid: uuid,
22
+ }.compact
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MISP
4
+ class Server < Base
5
+ attr_reader :id
6
+ attr_reader :url
7
+ attr_reader :name
8
+
9
+ def initialize(**attributes)
10
+ attributes = normalize_attributes(attributes)
11
+
12
+ @id = attributes.dig(:id)
13
+ @url = attributes.dig(:url)
14
+ @name = attributes.dig(:name)
15
+ end
16
+
17
+ def to_h
18
+ {
19
+ id: id,
20
+ url: url,
21
+ name: name,
22
+ }.compact
23
+ end
24
+
25
+ def list
26
+ _get("/servers/") do |servers|
27
+ servers.map do |server|
28
+ Server.new symbolize_keys(server)
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.list
34
+ new.list
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MISP
4
+ class SharingGroup < Server
5
+ attr_reader :id
6
+ attr_reader :name
7
+ attr_reader :releasability
8
+ attr_reader :description
9
+ attr_reader :uuid
10
+ attr_reader :organisation_uuid
11
+ attr_reader :org_id
12
+ attr_reader :sync_user_id
13
+ attr_reader :active
14
+ attr_reader :created
15
+ attr_reader :modified
16
+ attr_reader :local
17
+ attr_reader :roaming
18
+
19
+ def initialize(**attributes)
20
+ attributes = normalize_attributes(attributes)
21
+
22
+ @id = attributes.dig(:id)
23
+ @name = attributes.dig(:name) || "default name"
24
+ @releasability = attributes.dig(:releasability) || "default sharability"
25
+ @description = attributes.dig(:description)
26
+ @uuid = attributes.dig(:uuid)
27
+ @organisation_uuid = attributes.dig(:organisation_uuid)
28
+ @org_id = attributes.dig(:org_id)
29
+ @sync_user_id = attributes.dig(:sync_user_id)
30
+ @active = attributes.dig(:active)
31
+ @created = attributes.dig(:created)
32
+ @modified = attributes.dig(:modified)
33
+ @local = attributes.dig(:local)
34
+ @roaming = attributes.dig(:roaming)
35
+
36
+ @_organisation = attributes.dig(:Organisation)
37
+
38
+ @sharing_group_orgs = build_plural_attribute(items: attributes.dig(:SharingGroupOrg), klass: SharingGroupOrg)
39
+ @sharing_group_servers = build_plural_attribute(items: attributes.dig(:SharingGroupServer), klass: SharingGroupServer)
40
+ end
41
+
42
+ def to_h
43
+ {
44
+ id: id,
45
+ name: name,
46
+ releasability: releasability,
47
+ description: description,
48
+ uuid: uuid,
49
+ organisation_uuid: organisation_uuid,
50
+ org_id: org_id,
51
+ sync_user_id: sync_user_id,
52
+ active: active,
53
+ created: created,
54
+ modified: modified,
55
+ local: local,
56
+ roaming: roaming,
57
+ Organisation: organisation.to_h,
58
+ SharingGroupOrg: sharing_group_orgs.map(&:to_h),
59
+ SharingGroupServer: sharing_group_servers.map(&:to_h)
60
+ }.compact
61
+ end
62
+
63
+ def list
64
+ _get("/sharing_groups/") do |res|
65
+ sharing_groups = res.dig("response") || []
66
+ sharing_groups.map do |sharing_group|
67
+ SharingGroup.new symbolize_keys(sharing_group)
68
+ end
69
+ end
70
+ end
71
+
72
+ def self.list
73
+ new.list
74
+ end
75
+
76
+ def create(**attributes)
77
+ _post("/sharing_groups/add", wrap(attributes)) { |sharing_group| SharingGroup.new symbolize_keys(sharing_group) }
78
+ end
79
+
80
+ def self.create(attributes)
81
+ new.create attributes
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MISP
4
+ class SharingGroupOrg < Server
5
+ attr_reader :id
6
+ attr_reader :sharing_group_id
7
+ attr_reader :org_id
8
+ attr_reader :extend
9
+
10
+ attr_reader :organization
11
+
12
+ def initialize(**attributes)
13
+ attributes = normalize_attributes(attributes)
14
+
15
+ @id = attributes.dig(:id)
16
+ @sharing_group_id = attributes.dig(:sharing_group_id)
17
+ @org_id = attributes.dig(:org_id)
18
+ @extend = attributes.dig(:extend)
19
+
20
+ @organization = build_attribute(item: attributes.dig(:Organization), klass: Org)
21
+ end
22
+
23
+ def to_h
24
+ {
25
+ erver: erver,
26
+ id: id,
27
+ sharing_group_id: sharing_group_id,
28
+ org_id: org_id,
29
+ extend: @extend,
30
+ Organization: organization.to_h
31
+ }.compact
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MISP
4
+ class SharingGroupServer < Server
5
+ attr_reader :id
6
+ attr_reader :sharing_group_id
7
+ attr_reader :server_id
8
+ attr_reader :all_orgs
9
+
10
+ attr_reader :servers
11
+
12
+ def initialize(**attributes)
13
+ attributes = normalize_attributes(attributes)
14
+
15
+ @id = attributes.dig(:id)
16
+ @sharing_group_id = attributes.dig(:sharing_group_id)
17
+ @server_id = attributes.dig(:server_id)
18
+ @all_orgs = attributes.dig(:all_orgs)
19
+
20
+ @servers = build_plural_attribute(items: attributes.dig(:Server), klass: Server)
21
+ end
22
+
23
+ def to_h
24
+ {
25
+ id: id,
26
+ sharing_group_id: sharing_group_id,
27
+ server_id: server_id,
28
+ all_orgs: all_orgs,
29
+ Server: servers.map(&:to_h)
30
+ }.compact
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MISP
4
+ class Tag < Base
5
+ attr_accessor :id
6
+ attr_accessor :name
7
+ attr_accessor :colour
8
+ attr_accessor :exportable
9
+ attr_accessor :hide_tag
10
+
11
+ def initialize(**attributes)
12
+ attributes = normalize_attributes(attributes)
13
+
14
+ @id = attributes.dig(:id)
15
+ @name = attributes.dig(:name)
16
+ @colour = attributes.dig(:colour)
17
+ @exportable = attributes.dig(:exportable)
18
+ @hide_tag = attributes.dig(:hide_tag)
19
+ end
20
+
21
+ def to_h
22
+ {
23
+ id: id,
24
+ name: name,
25
+ colour: colour,
26
+ exportable: exportable,
27
+ hide_tag: hide_tag,
28
+ }.compact
29
+ end
30
+
31
+ def get(id)
32
+ _get("/tags/view/#{id}") { |json| Tag.new symbolize_keys(json) }
33
+ end
34
+
35
+ def self.get(id)
36
+ new.get id
37
+ end
38
+
39
+ def create(attributes)
40
+ _post("/tags/add", wrap(attributes)) { |json| Tag.new symbolize_keys(json) }
41
+ end
42
+
43
+ def self.create(attributes)
44
+ new.create attributes
45
+ end
46
+
47
+ def delete
48
+ _post("/tags/delete/#{id}") { |json| json }
49
+ end
50
+
51
+ def self.delete(id)
52
+ Tag.new(id: id).delete
53
+ end
54
+
55
+ def update(**attributes)
56
+ payload = to_h.merge(attributes)
57
+ _post("/tags/edit/#{id}", wrap(payload)) { |json| Tag.new symbolize_keys(json) }
58
+ end
59
+
60
+ def self.update(id, **attributes)
61
+ Tag.new(id: id).update attributes
62
+ end
63
+
64
+ def search(**params)
65
+ _post("/tags/search", params) do |tags|
66
+ tags.map { |tag| Tag.new symbolize_keys(tag) }
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MISP
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "misp/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "misp"
9
+ spec.version = MISP::VERSION
10
+ spec.authors = ["Manabu Niseki"]
11
+ spec.email = ["manabu.niseki@gmail.com"]
12
+
13
+ spec.summary = "A dead simple MISP API wrapper for Ruby"
14
+ spec.description = "A dead simple MISP API wrapper for Ruby"
15
+ spec.homepage = "https://github.com/ninoseki/misp-rb"
16
+ spec.license = "MIT"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "coveralls", "~> 0.8"
29
+ spec.add_development_dependency "rake", "~> 12.3"
30
+ spec.add_development_dependency "rspec", "~> 3.8"
31
+ spec.add_development_dependency "vcr", "~> 5.0"
32
+ spec.add_development_dependency "webmock", "~> 3.6"
33
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: misp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manabu Niseki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
97
+ description: A dead simple MISP API wrapper for Ruby
98
+ email:
99
+ - manabu.niseki@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - lib/misp.rb
112
+ - lib/misp/attribute.rb
113
+ - lib/misp/base.rb
114
+ - lib/misp/configuration.rb
115
+ - lib/misp/event.rb
116
+ - lib/misp/feed.rb
117
+ - lib/misp/galaxy.rb
118
+ - lib/misp/galaxy_cluster.rb
119
+ - lib/misp/org.rb
120
+ - lib/misp/orgc.rb
121
+ - lib/misp/server.rb
122
+ - lib/misp/sharing_group.rb
123
+ - lib/misp/sharing_group_org.rb
124
+ - lib/misp/sharing_group_server.rb
125
+ - lib/misp/tag.rb
126
+ - lib/misp/version.rb
127
+ - misp.gemspec
128
+ homepage: https://github.com/ninoseki/misp-rb
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubygems_version: 3.0.4
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: A dead simple MISP API wrapper for Ruby
151
+ test_files: []