oscal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c6c9dffa10602fbcd753774bb2705bfa2e16f2ff29bbed89e7a2283a6b0d7391
4
+ data.tar.gz: dd31b313d847beb37d506adfedf853a588b977e06c49eb4fd973b064ffd2bcb6
5
+ SHA512:
6
+ metadata.gz: a8f32ccd54e26dbc258dd8d2523379b62e4cddb04283ac473abf1553b27c66d87cb68ce465ae1841afb37adcad9b67d537388f3b0f0abd7795767ee0bdbec072
7
+ data.tar.gz: a963912423d5de00406411403949bb010309a07721e6b6de7d6362f30324d281ae05701cb8ca9f17c830d393210a4a1e0a649d77e86aabb25d58699316c592dd
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ronald.tse@ribose.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in oscal.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/README.adoc ADDED
@@ -0,0 +1,49 @@
1
+ = OSCAL in Ruby
2
+
3
+ == Installation
4
+
5
+ Install the gem:
6
+
7
+ [source,console]
8
+ ----
9
+ [sudo] gem install oscal
10
+ ----
11
+
12
+ or add it to your `Gemfile`:
13
+
14
+ [source,ruby]
15
+ ----
16
+ gem 'oscal'
17
+ ----
18
+
19
+ == Command-line usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ == Ruby library usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ == Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
30
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
31
+ prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To
34
+ release a new version, update the version number in `version.rb`, and then run
35
+ `bundle exec rake release`, which will create a git tag for the version, push
36
+ git commits and the created tag, and push the `.gem` file to
37
+ https://rubygems.org.
38
+
39
+ == Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/metanorma/oscal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the https://github.com/metanorma/oscal/blob/main/CODE_OF_CONDUCT.md[code of conduct].
42
+
43
+ == Code of Conduct
44
+
45
+ Everyone interacting in the Oscal project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the https://github.com/metanorma/oscal/blob/main/CODE_OF_CONDUCT.md[code of conduct].
46
+
47
+ == LICENSE
48
+
49
+ Copyright Ribose. The OSCAL schema is published by NIST.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,22 @@
1
+ module Oscal
2
+ class Catalog
3
+ attr_accessor :uuid, :metadata, :groups
4
+
5
+ def initialize(metadata, groups)
6
+ @metadata = MetadataBlock.new(metadata)
7
+ @groups = Group.wrap(groups)
8
+ end
9
+
10
+ def self.load_from_yaml(path)
11
+ yaml_data = YAML.load_file(path, permitted_classes: [Time, Date, DateTime])
12
+
13
+ yaml_catalog = yaml_data['catalog']
14
+
15
+ metadata = yaml_catalog['metadata']
16
+ group_data = yaml_catalog['groups']
17
+
18
+ Catalog.new(metadata, group_data)
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,14 @@
1
+ module Oscal
2
+ class Component
3
+ attr_accessor :id, :name, :type, :description, :properties
4
+
5
+ def initialize(id, name, type, description, properties)
6
+ @id = id
7
+ @name = name
8
+ @type = type
9
+ @description = description
10
+ @properties = properties
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,38 @@
1
+ module Oscal
2
+ class Control
3
+ KEY = %i(id title params props parts)
4
+ attr_accessor *KEY
5
+
6
+ def self.wrap(obj)
7
+ return obj if obj.is_a? Control
8
+ return Control.new(obj) unless obj.is_a? Array
9
+
10
+ obj.map do |x|
11
+ Control.wrap(x)
12
+ end
13
+ end
14
+
15
+ def initialize(options={})
16
+ options.each_pair.each do |key,val|
17
+ key_name = key.gsub('-','_')
18
+
19
+ unless KEY.include?(key_name.to_sym)
20
+ raise UnknownAttributeError.new("Unknown key `#{key}` in Control")
21
+ end
22
+
23
+ val = case key_name
24
+ when 'params'
25
+ Parameter.wrap(val)
26
+ when 'props'
27
+ Property.wrap(val)
28
+ when 'parts'
29
+ Part.wrap(val)
30
+ else
31
+ val
32
+ end
33
+
34
+ self.send("#{key_name}=", val)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ module Oscal
2
+ class Group
3
+ KEYS = %i(id class title controls props parts groups)
4
+ attr_accessor *KEYS
5
+
6
+ def self.wrap(obj)
7
+ return obj if obj.is_a? Group
8
+ return Group.new(obj) unless obj.is_a? Array
9
+
10
+ obj.map do |x|
11
+ Group.wrap(x)
12
+ end
13
+ end
14
+
15
+ def initialize(options={})
16
+ options.each_pair.each do |key,val|
17
+ key_name = key.gsub('-','_')
18
+
19
+ unless KEYS.include?(key_name.to_sym)
20
+ raise UnknownAttributeError.new("Unknown key `#{key}` in Group")
21
+ end
22
+
23
+ val = case key_name
24
+ when 'groups'
25
+ Group.wrap(val)
26
+ when 'params'
27
+ Parameter.wrap(val)
28
+ when 'props'
29
+ Property.wrap(val)
30
+ when 'parts'
31
+ Part.wrap(val)
32
+ else
33
+ val
34
+ end
35
+
36
+ self.send("#{key_name}=", val)
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ module Oscal
2
+ class MetadataBlock
3
+
4
+ METADATA_VALUES = %i(title published last_modified version
5
+ oscal_version remarks)
6
+
7
+ attr_accessor *METADATA_VALUES
8
+
9
+ def initialize(options={})
10
+ options.each_pair.each do |key,val|
11
+ key_name = key.gsub('-','_')
12
+
13
+ unless METADATA_VALUES.include?(key_name.to_sym)
14
+ raise UnknownAttributeError.new("Unknown key `#{key}` in MetadataBlock")
15
+ end
16
+ self.send("#{key_name}=", val)
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ module Oscal
2
+ class Parameter
3
+
4
+ KEY = %i(id label select)
5
+ attr_accessor *KEY
6
+
7
+ def self.wrap(obj)
8
+ return obj if obj.is_a? Parameter
9
+ return Parameter.new(obj) unless obj.is_a? Array
10
+
11
+ obj.map do |x|
12
+ Parameter.wrap(x)
13
+ end
14
+ end
15
+
16
+ def initialize(options={})
17
+ options.each_pair.each do |key,val|
18
+ key_name = key.gsub('-','_')
19
+
20
+ unless KEY.include?(key_name.to_sym)
21
+ raise UnknownAttributeError.new("Unknown key `#{key}` in Parameter")
22
+ end
23
+
24
+ self.send("#{key_name}=", val)
25
+ end
26
+ end
27
+ end
28
+ end
data/lib/oscal/part.rb ADDED
@@ -0,0 +1,32 @@
1
+ require_relative "serializer"
2
+
3
+ module Oscal
4
+ class Part
5
+ include Serializer
6
+
7
+ KEY = %i(id name prose)
8
+ attr_accessor *KEY
9
+ attr_serializable *KEY
10
+
11
+ def self.wrap(obj)
12
+ return obj if obj.is_a? Part
13
+ return Part.new(obj) unless obj.is_a? Array
14
+
15
+ obj.map do |x|
16
+ Part.wrap(x)
17
+ end
18
+ end
19
+
20
+ def initialize(options={})
21
+ options.each_pair.each do |key,val|
22
+ key_name = key.gsub('-','_')
23
+
24
+ unless KEY.include?(key_name.to_sym)
25
+ raise UnknownAttributeError.new("Unknown key `#{key}` in Part")
26
+ end
27
+
28
+ self.send("#{key_name}=", val)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module Oscal
2
+ class Profile
3
+ attr_accessor :metadata, :imports, :controls
4
+
5
+ def initialize(metadata, imports, controls)
6
+ @metadata = metadata
7
+ @imports = imports
8
+ @controls = controls
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "serializer"
2
+
3
+ module Oscal
4
+ class Property
5
+ include Serializer
6
+
7
+ KEY = %i(name value)
8
+ attr_accessor *KEY
9
+ attr_serializable *KEY
10
+
11
+ def self.wrap(obj)
12
+ return obj if obj.is_a? Property
13
+ return Property.new(obj) unless obj.is_a? Array
14
+
15
+ obj.map do |x|
16
+ Property.wrap(x)
17
+ end
18
+ end
19
+
20
+ def initialize(options={})
21
+ options.each_pair.each do |key,val|
22
+ key_name = key.gsub('-','_')
23
+
24
+ unless KEY.include?(key_name.to_sym)
25
+ raise UnknownAttributeError.new("Unknown key `#{key}` in Property")
26
+ end
27
+
28
+ self.send("#{key_name}=", val)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "serializer"
2
+
3
+ module Oscal
4
+ class Prose
5
+ include Serializer
6
+
7
+ attr_serializable :value, :media_type
8
+
9
+ def to_xml(builder)
10
+ builder.prose(value, {'media-type' => media_type})
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,62 @@
1
+ require 'yaml'
2
+
3
+ module Oscal
4
+ module Serializer
5
+ def to_h
6
+ instance_variables.each_with_object({}) do |var, hash|
7
+ var_name = var.to_s.delete('@')
8
+ hash[var_name] = instance_variable_get(var)
9
+ end
10
+ end
11
+
12
+ def to_json(*args)
13
+ to_h.to_json(*args)
14
+ end
15
+
16
+ def to_yaml
17
+ to_h.to_yaml
18
+ end
19
+
20
+ def to_xml(builder)
21
+ raise NotImplementedError, "#{self.class}#to_xml not implemented!"
22
+ end
23
+
24
+ def self.included(klass)
25
+ klass.extend(ClassMethods)
26
+ end
27
+
28
+ module ClassMethods
29
+ def from_h(data)
30
+ new(*data.values_at(*attribute_names))
31
+ end
32
+
33
+ def from_json(json_string)
34
+ data = JSON.parse(json_string)
35
+ from_h(data)
36
+ end
37
+
38
+ def from_yaml(yaml_string)
39
+ data = YAML.load(yaml_string)
40
+ from_h(data)
41
+ end
42
+
43
+ def from_xml(xml_element)
44
+ raise NotImplementedError, "#{self}#from_xml not implemented!"
45
+ end
46
+
47
+ private
48
+
49
+ def attribute_names
50
+ @attribute_names ||= []
51
+ end
52
+
53
+ def attr_serializable(*attrs)
54
+ attrs.each do |attr|
55
+ attribute_names << attr.to_sym
56
+ define_method(attr) { instance_variable_get("@#{attr}") }
57
+ define_method("#{attr}=") { |value| instance_variable_set("@#{attr}", value) }
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ module Oscal
2
+ class Statement
3
+ attr_accessor :description, :prose, :properties
4
+
5
+ def initialize(description, prose, properties)
6
+ @description = description
7
+ @prose = prose
8
+ @properties = properties
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oscal
4
+ VERSION = "0.1.0"
5
+ end
data/lib/oscal.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "oscal/version"
4
+ require_relative "oscal/serializer"
5
+ require_relative "oscal/catalog"
6
+ require_relative "oscal/component"
7
+ require_relative "oscal/control"
8
+ require_relative "oscal/group"
9
+ require_relative "oscal/part"
10
+ require_relative "oscal/parameter"
11
+ require_relative "oscal/metadata_block"
12
+ require_relative "oscal/profile"
13
+ require_relative "oscal/property"
14
+ require_relative "oscal/prose"
15
+ require_relative "oscal/statement"
16
+
17
+ module Oscal
18
+ class Error < StandardError; end
19
+
20
+ class UnknownAttributeError < Error; end
21
+ class InvalidTypeError < Error; end
22
+ end
data/oscal.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/oscal/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "oscal"
7
+ spec.version = Oscal::VERSION
8
+ spec.authors = ["Ronald Tse"]
9
+ spec.email = ["ronald.tse@ribose.com"]
10
+
11
+ spec.summary = "Interact with OSCAL models"
12
+ spec.description = "Ruby library and parser for OSCAL models"
13
+ spec.homepage = "https://github.com/metanorma/oscal-ruby/"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/metanorma/oscal-ruby/"
18
+ spec.metadata["changelog_uri"] = "https://github.com/metanorma/oscal-ruby/CHANGELOG"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "yaml"
32
+ end
data/sig/oscal.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Oscal
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oscal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ronald Tse
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yaml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Ruby library and parser for OSCAL models
28
+ email:
29
+ - ronald.tse@ribose.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - CODE_OF_CONDUCT.md
36
+ - Gemfile
37
+ - README.adoc
38
+ - Rakefile
39
+ - lib/oscal.rb
40
+ - lib/oscal/catalog.rb
41
+ - lib/oscal/component.rb
42
+ - lib/oscal/control.rb
43
+ - lib/oscal/group.rb
44
+ - lib/oscal/metadata_block.rb
45
+ - lib/oscal/parameter.rb
46
+ - lib/oscal/part.rb
47
+ - lib/oscal/profile.rb
48
+ - lib/oscal/property.rb
49
+ - lib/oscal/prose.rb
50
+ - lib/oscal/serializer.rb
51
+ - lib/oscal/statement.rb
52
+ - lib/oscal/version.rb
53
+ - oscal.gemspec
54
+ - sig/oscal.rbs
55
+ homepage: https://github.com/metanorma/oscal-ruby/
56
+ licenses: []
57
+ metadata:
58
+ homepage_uri: https://github.com/metanorma/oscal-ruby/
59
+ source_code_uri: https://github.com/metanorma/oscal-ruby/
60
+ changelog_uri: https://github.com/metanorma/oscal-ruby/CHANGELOG
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.7.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.3.7
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Interact with OSCAL models
80
+ test_files: []