misp 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/misp/server.rb CHANGED
@@ -2,18 +2,26 @@
2
2
 
3
3
  module MISP
4
4
  class Server < Base
5
+ # @return [String]
5
6
  attr_reader :id
7
+ # @return [String]
6
8
  attr_reader :url
9
+ # @return [String]
7
10
  attr_reader :name
8
11
 
9
12
  def initialize(**attributes)
10
- attributes = normalize_attributes(attributes)
13
+ attributes = normalize_attributes(**attributes)
11
14
 
12
- @id = attributes.dig(:id)
13
- @url = attributes.dig(:url)
14
- @name = attributes.dig(:name)
15
+ @id = attributes[:id]
16
+ @url = attributes[:url]
17
+ @name = attributes[:name]
15
18
  end
16
19
 
20
+ #
21
+ # Returns a hash representation of the attribute data.
22
+ #
23
+ # @return [Hash]
24
+ #
17
25
  def to_h
18
26
  {
19
27
  id: id,
@@ -22,16 +30,23 @@ module MISP
22
30
  }.compact
23
31
  end
24
32
 
33
+ #
34
+ # List servers
35
+ #
36
+ # @return [Array<MISP::Server>]
37
+ #
25
38
  def list
26
39
  _get("/servers/") do |servers|
27
40
  servers.map do |server|
28
- Server.new symbolize_keys(server)
41
+ Server.new server
29
42
  end
30
43
  end
31
44
  end
32
45
 
33
- def self.list
34
- new.list
46
+ class << self
47
+ def list
48
+ new.list
49
+ end
35
50
  end
36
51
  end
37
52
  end
@@ -1,44 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MISP
4
- class SharingGroup < Server
4
+ class SharingGroup < Base
5
+ # @return [String]
5
6
  attr_reader :id
7
+ # @return [String]
6
8
  attr_reader :name
9
+ # @return [String]
7
10
  attr_reader :releasability
11
+ # @return [String]
8
12
  attr_reader :description
13
+ # @return [String]
9
14
  attr_reader :uuid
15
+ # @return [String]
10
16
  attr_reader :organisation_uuid
17
+ # @return [String]
11
18
  attr_reader :org_id
19
+ # @return [String]
12
20
  attr_reader :sync_user_id
21
+ # @return [Boolean]
13
22
  attr_reader :active
23
+ # @return [String]
14
24
  attr_reader :created
25
+ # @return [String]
15
26
  attr_reader :modified
27
+ # @return [Boolean]
16
28
  attr_reader :local
29
+ # @return [Boolean]
17
30
  attr_reader :roaming
18
31
 
32
+ # @return [MISP::Org, nil]
33
+ attr_reader :organization
34
+
35
+ # @return [Array<MISP::SharingGroupOrg>]
36
+ attr_reader :sharing_group_orgs
37
+ # @return [Array<MISP::SharingGroupServer>]
38
+ attr_reader :sharing_group_servers
39
+
19
40
  def initialize(**attributes)
20
- attributes = normalize_attributes(attributes)
41
+ attributes = normalize_attributes(**attributes)
21
42
 
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)
43
+ @id = attributes[:id]
44
+ @name = attributes[:name] || "default name"
45
+ @releasability = attributes[:releasability] || "default sharability"
46
+ @description = attributes[:description]
47
+ @uuid = attributes[:uuid]
48
+ @organisation_uuid = attributes[:organisation_uuid]
49
+ @org_id = attributes[:org_id]
50
+ @sync_user_id = attributes[:sync_user_id]
51
+ @active = attributes[:active]
52
+ @created = attributes[:created]
53
+ @modified = attributes[:modified]
54
+ @local = attributes[:local]
55
+ @roaming = attributes[:roaming]
35
56
 
36
- @_organisation = attributes.dig(:Organisation)
57
+ @organisation = build_attribute(item: attributes[:Organization], klass: Org)
37
58
 
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)
59
+ @sharing_group_orgs = build_plural_attribute(items: attributes[:SharingGroupOrg], klass: SharingGroupOrg)
60
+ @sharing_group_servers = build_plural_attribute(items: attributes[:SharingGroupServer], klass: SharingGroupServer)
40
61
  end
41
62
 
63
+ #
64
+ # Returns a hash representation of the attribute data.
65
+ #
66
+ # @return [Hash]
67
+ #
42
68
  def to_h
43
69
  {
44
70
  id: id,
@@ -60,25 +86,39 @@ module MISP
60
86
  }.compact
61
87
  end
62
88
 
89
+ #
90
+ # List sharing groups
91
+ #
92
+ # @return [Array<MISP::SharingGroup>]
93
+ #
63
94
  def list
64
95
  _get("/sharing_groups/") do |res|
65
- sharing_groups = res.dig("response") || []
96
+ sharing_groups = res[:response] || []
66
97
  sharing_groups.map do |sharing_group|
67
- SharingGroup.new symbolize_keys(sharing_group)
98
+ SharingGroup.new(**sharing_group)
68
99
  end
69
100
  end
70
101
  end
71
102
 
72
- def self.list
73
- new.list
74
- end
75
-
103
+ #
104
+ # Create a sharing group
105
+ #
106
+ # @param [Hash] **attributes attributes
107
+ #
108
+ # @return [MISP::SharingGroup]
109
+ #
76
110
  def create(**attributes)
77
- _post("/sharing_groups/add", wrap(attributes)) { |sharing_group| SharingGroup.new symbolize_keys(sharing_group) }
111
+ _post("/sharing_groups/add", wrap(attributes)) { |sharing_group| SharingGroup.new sharing_group }
78
112
  end
79
113
 
80
- def self.create(attributes)
81
- new.create attributes
114
+ class << self
115
+ def list
116
+ new.list
117
+ end
118
+
119
+ def create(**attributes)
120
+ new.create attributes
121
+ end
82
122
  end
83
123
  end
84
124
  end
@@ -1,25 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MISP
4
- class SharingGroupOrg < Server
4
+ class SharingGroupOrg < Base
5
+ # @return [String]
5
6
  attr_reader :id
7
+ # @return [String]
6
8
  attr_reader :sharing_group_id
9
+ # @return [String]
7
10
  attr_reader :org_id
11
+ # @return [String]
8
12
  attr_reader :extend
9
13
 
14
+ # @return [MISP::Organization, nil]
10
15
  attr_reader :organization
11
16
 
12
17
  def initialize(**attributes)
13
- attributes = normalize_attributes(attributes)
18
+ attributes = normalize_attributes(**attributes)
14
19
 
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)
20
+ @id = attributes[:id]
21
+ @sharing_group_id = attributes[:sharing_group_id]
22
+ @org_id = attributes[:org_id]
23
+ @extend = attributes[:extend]
19
24
 
20
- @organization = build_attribute(item: attributes.dig(:Organization), klass: Org)
25
+ @organization = build_attribute(item: attributes[:Organization], klass: Org)
21
26
  end
22
27
 
28
+ #
29
+ # Returns a hash representation of the attribute data.
30
+ #
31
+ # @return [Hash]
32
+ #
23
33
  def to_h
24
34
  {
25
35
  erver: erver,
@@ -1,25 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MISP
4
- class SharingGroupServer < Server
4
+ class SharingGroupServer < Base
5
+ # @return [String]
5
6
  attr_reader :id
7
+ # @return [String]
6
8
  attr_reader :sharing_group_id
9
+ # @return [String]
7
10
  attr_reader :server_id
11
+ # @return [Boolean]
8
12
  attr_reader :all_orgs
9
13
 
14
+ # @return [Array<MISP::Server>]
10
15
  attr_reader :servers
11
16
 
12
17
  def initialize(**attributes)
13
- attributes = normalize_attributes(attributes)
18
+ attributes = normalize_attributes(**attributes)
14
19
 
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)
20
+ @id = attributes[:id]
21
+ @sharing_group_id = attributes[:sharing_group_id]
22
+ @server_id = attributes[:server_id]
23
+ @all_orgs = attributes[:all_orgs]
19
24
 
20
- @servers = build_plural_attribute(items: attributes.dig(:Server), klass: Server)
25
+ @servers = build_plural_attribute(items: attributes[:Server], klass: Server)
21
26
  end
22
27
 
28
+ #
29
+ # Returns a hash representation of the attribute data.
30
+ #
31
+ # @return [Hash]
32
+ #
23
33
  def to_h
24
34
  {
25
35
  id: id,
data/lib/misp/tag.rb CHANGED
@@ -2,22 +2,32 @@
2
2
 
3
3
  module MISP
4
4
  class Tag < Base
5
+ # @return [String]
5
6
  attr_accessor :id
7
+ # @return [String]
6
8
  attr_accessor :name
9
+ # @return [String]
7
10
  attr_accessor :colour
11
+ # @return [Boolean]
8
12
  attr_accessor :exportable
13
+ # @return [Boolean]
9
14
  attr_accessor :hide_tag
10
15
 
11
16
  def initialize(**attributes)
12
- attributes = normalize_attributes(attributes)
17
+ attributes = normalize_attributes(**attributes)
13
18
 
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
+ @id = attributes[:id]
20
+ @name = attributes[:name]
21
+ @colour = attributes[:colour]
22
+ @exportable = attributes[:exportable]
23
+ @hide_tag = attributes[:hide_tag]
19
24
  end
20
25
 
26
+ #
27
+ # Returns a hash representation of the attribute data.
28
+ #
29
+ # @return [Hash]
30
+ #
21
31
  def to_h
22
32
  {
23
33
  id: id,
@@ -28,42 +38,75 @@ module MISP
28
38
  }.compact
29
39
  end
30
40
 
31
- def get(id)
32
- _get("/tags/view/#{id}") { |json| Tag.new symbolize_keys(json) }
41
+ #
42
+ # Get a tag
43
+ #
44
+ # @return [MISP::Tag]
45
+ #
46
+ def get
47
+ _get("/tags/view/#{id}") { |json| Tag.new(**json) }
33
48
  end
34
49
 
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
50
+ #
51
+ # Create a tag
52
+ #
53
+ # @param [Hash] **attributes attributes
54
+ #
55
+ # @return [MISP::Tag]
56
+ #
57
+ def create(**attributes)
58
+ _post("/tags/add", wrap(attributes)) { |json| Tag.new(**json) }
45
59
  end
46
60
 
61
+ #
62
+ # Delete a tag
63
+ #
64
+ # @return [Hash]
65
+ #
47
66
  def delete
48
67
  _post("/tags/delete/#{id}") { |json| json }
49
68
  end
50
69
 
51
- def self.delete(id)
52
- Tag.new(id: id).delete
53
- end
54
-
70
+ #
71
+ # Update a tag
72
+ #
73
+ # @param [Hash] **attributes attributes
74
+ #
75
+ # @return [MISP::Tag]
76
+ #
55
77
  def update(**attributes)
56
78
  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
79
+ _post("/tags/edit/#{id}", wrap(payload)) { |json| Tag.new(**json) }
62
80
  end
63
81
 
82
+ #
83
+ # Search for tags
84
+ #
85
+ # @param [Hash] **params parameters
86
+ #
87
+ # @return [MISP::Tag]
88
+ #
64
89
  def search(**params)
65
90
  _post("/tags/search", params) do |tags|
66
- tags.map { |tag| Tag.new symbolize_keys(tag) }
91
+ tags.map { |tag| Tag.new tag }
92
+ end
93
+ end
94
+
95
+ class << self
96
+ def get(id)
97
+ new(id: id).get
98
+ end
99
+
100
+ def create(**attributes)
101
+ new.create(**attributes)
102
+ end
103
+
104
+ def delete(id)
105
+ Tag.new(id: id).delete
106
+ end
107
+
108
+ def update(id, **attributes)
109
+ Tag.new(id: id).update(**attributes)
67
110
  end
68
111
  end
69
112
  end
data/lib/misp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MISP
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.4"
5
5
  end
data/misp.gemspec CHANGED
@@ -24,10 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
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"
27
+ spec.add_development_dependency "bundler", "~> 2.3"
28
+ spec.add_development_dependency "coveralls_reborn", "~> 0.23"
29
+ spec.add_development_dependency "rake", "~> 13.0"
30
+ spec.add_development_dependency "rspec", "~> 3.10"
31
+ spec.add_development_dependency "vcr", "~> 6.0"
32
+ spec.add_development_dependency "webmock", "~> 3.14"
33
33
  end
data/renovate.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": [
3
+ "config:base"
4
+ ]
5
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: misp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-22 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,84 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '2.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: coveralls
28
+ name: coveralls_reborn
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.8'
33
+ version: '0.23'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.8'
40
+ version: '0.23'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12.3'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '12.3'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.8'
61
+ version: '3.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.8'
68
+ version: '3.10'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '5.0'
75
+ version: '6.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '5.0'
82
+ version: '6.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.6'
89
+ version: '3.14'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.6'
96
+ version: '3.14'
97
97
  description: A dead simple MISP API wrapper for Ruby
98
98
  email:
99
99
  - manabu.niseki@gmail.com
@@ -101,9 +101,9 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".github/workflows/test.yaml"
104
105
  - ".gitignore"
105
106
  - ".rspec"
106
- - ".travis.yml"
107
107
  - Gemfile
108
108
  - LICENSE
109
109
  - README.md
@@ -125,11 +125,12 @@ files:
125
125
  - lib/misp/tag.rb
126
126
  - lib/misp/version.rb
127
127
  - misp.gemspec
128
+ - renovate.json
128
129
  homepage: https://github.com/ninoseki/misp-rb
129
130
  licenses:
130
131
  - MIT
131
132
  metadata: {}
132
- post_install_message:
133
+ post_install_message:
133
134
  rdoc_options: []
134
135
  require_paths:
135
136
  - lib
@@ -144,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  - !ruby/object:Gem::Version
145
146
  version: '0'
146
147
  requirements: []
147
- rubygems_version: 3.0.4
148
- signing_key:
148
+ rubygems_version: 3.2.14
149
+ signing_key:
149
150
  specification_version: 4
150
151
  summary: A dead simple MISP API wrapper for Ruby
151
152
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6
7
- before_install: gem install bundler -v 2.0.2