oscal 0.1.0 → 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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.docker/Dockerfile +19 -0
  3. data/.docker/Makefile +43 -0
  4. data/.docker/docker-compose.yml +14 -0
  5. data/.docker/readme.md +61 -0
  6. data/.github/workflows/rake.yml +15 -0
  7. data/.github/workflows/release.yml +24 -0
  8. data/.gitignore +13 -0
  9. data/.gitmodules +3 -0
  10. data/.hound.yml +5 -0
  11. data/.rspec +0 -1
  12. data/.rubocop.yml +10 -0
  13. data/.ruby-version +1 -0
  14. data/Gemfile +4 -0
  15. data/LICENSE +25 -0
  16. data/Makefile +1 -0
  17. data/README.adoc +66 -0
  18. data/Rakefile +13 -6
  19. data/bin/console +30 -0
  20. data/bin/rspec +27 -0
  21. data/bin/setup +8 -0
  22. data/docker-compose.yml +1 -0
  23. data/exe/convert2oscalyaml.rb +560 -0
  24. data/lib/oscal/add.rb +26 -0
  25. data/lib/oscal/address.rb +22 -0
  26. data/lib/oscal/address_line.rb +11 -0
  27. data/lib/oscal/alter.rb +22 -0
  28. data/lib/oscal/assembly.rb +119 -0
  29. data/lib/oscal/assessment_plan.rb +28 -0
  30. data/lib/oscal/assessment_result.rb +230 -0
  31. data/lib/oscal/attribute_type_hash.rb +80 -0
  32. data/lib/oscal/back_matter.rb +20 -0
  33. data/lib/oscal/base64_object.rb +11 -0
  34. data/lib/oscal/base_class.rb +50 -0
  35. data/lib/oscal/catalog.rb +51 -10
  36. data/lib/oscal/choice.rb +11 -0
  37. data/lib/oscal/citation.rb +22 -0
  38. data/lib/oscal/combine.rb +11 -0
  39. data/lib/oscal/common_utils.rb +35 -0
  40. data/lib/oscal/constraint.rb +20 -0
  41. data/lib/oscal/control.rb +20 -30
  42. data/lib/oscal/custom.rb +22 -0
  43. data/lib/oscal/datatypes.rb +50 -0
  44. data/lib/oscal/document_id.rb +11 -0
  45. data/lib/oscal/email_address.rb +11 -0
  46. data/lib/oscal/exclude_control.rb +22 -0
  47. data/lib/oscal/external_id.rb +11 -0
  48. data/lib/oscal/group.rb +26 -34
  49. data/lib/oscal/guideline.rb +11 -0
  50. data/lib/oscal/hash_object.rb +11 -0
  51. data/lib/oscal/import_object.rb +22 -0
  52. data/lib/oscal/include_control.rb +22 -0
  53. data/lib/oscal/insert_control.rb +22 -0
  54. data/lib/oscal/link.rb +11 -0
  55. data/lib/oscal/list.rb +160 -0
  56. data/lib/oscal/location.rb +31 -0
  57. data/lib/oscal/location_uuid.rb +11 -0
  58. data/lib/oscal/logger.rb +8 -0
  59. data/lib/oscal/matching.rb +11 -0
  60. data/lib/oscal/member_of_organization.rb +11 -0
  61. data/lib/oscal/merge.rb +20 -0
  62. data/lib/oscal/metadata_block.rb +28 -13
  63. data/lib/oscal/modify.rb +22 -0
  64. data/lib/oscal/parameter.rb +22 -19
  65. data/lib/oscal/parsing_functions.rb +19 -0
  66. data/lib/oscal/part.rb +14 -22
  67. data/lib/oscal/party.rb +36 -0
  68. data/lib/oscal/party_uuid.rb +11 -0
  69. data/lib/oscal/profile.rb +33 -7
  70. data/lib/oscal/property.rb +4 -25
  71. data/lib/oscal/remove.rb +11 -0
  72. data/lib/oscal/resource.rb +29 -0
  73. data/lib/oscal/responsible_party.rb +24 -0
  74. data/lib/oscal/revision.rb +23 -0
  75. data/lib/oscal/rlink.rb +20 -0
  76. data/lib/oscal/role.rb +22 -0
  77. data/lib/oscal/select.rb +20 -0
  78. data/lib/oscal/serializer.rb +17 -4
  79. data/lib/oscal/set_parameter.rb +31 -0
  80. data/lib/oscal/telephone_number.rb +11 -0
  81. data/lib/oscal/test.rb +11 -0
  82. data/lib/oscal/url.rb +11 -0
  83. data/lib/oscal/value.rb +37 -0
  84. data/lib/oscal/version.rb +1 -1
  85. data/lib/oscal/with_id.rb +40 -0
  86. data/lib/oscal.rb +1 -13
  87. data/oscal.gemspec +9 -11
  88. data/spec/oscal/catalog_spec.rb +40 -0
  89. data/spec/oscal_spec.rb +7 -0
  90. data/spec/sample_inputs/import-ap.json +4 -0
  91. data/spec/spec_helper.rb +15 -0
  92. metadata +84 -10
  93. data/lib/oscal/component.rb +0 -14
  94. data/lib/oscal/prose.rb +0 -13
  95. data/lib/oscal/statement.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6c9dffa10602fbcd753774bb2705bfa2e16f2ff29bbed89e7a2283a6b0d7391
4
- data.tar.gz: dd31b313d847beb37d506adfedf853a588b977e06c49eb4fd973b064ffd2bcb6
3
+ metadata.gz: 562c827a391c4d86af9edb5cdf98ee1a61fb3a7d57374aa29a3a70609df09bb3
4
+ data.tar.gz: 2031cf36b122b094cb3532bff51534de756907327d7f3bb09456a9120a510607
5
5
  SHA512:
6
- metadata.gz: a8f32ccd54e26dbc258dd8d2523379b62e4cddb04283ac473abf1553b27c66d87cb68ce465ae1841afb37adcad9b67d537388f3b0f0abd7795767ee0bdbec072
7
- data.tar.gz: a963912423d5de00406411403949bb010309a07721e6b6de7d6362f30324d281ae05701cb8ca9f17c830d393210a4a1e0a649d77e86aabb25d58699316c592dd
6
+ metadata.gz: cbd11774c99f75b1e8b365488fb3fdd4969a7917de692cbf7546118b2a3102767af8b9ed9a140c2998a0d4cff9f282061eeea03da47371b864d67067307433c3
7
+ data.tar.gz: d7510b9543be93b734be45f0d4140d32413af2d8a5462339bac65db9de3ff9a98c3b696537af73a9f23c1f491e85b269e898008df07da5180b2036e52fdff48a
@@ -0,0 +1,19 @@
1
+ ARG RUBY_IMAGE=ruby:3.1.2-slim
2
+
3
+ FROM ${RUBY_IMAGE}
4
+
5
+ RUN apt-get update \
6
+ && apt-get install -y build-essential git \
7
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
8
+
9
+ # install latest bundler
10
+ RUN gem install bundler
11
+
12
+ # Create app directory
13
+ WORKDIR /workspace
14
+
15
+ # Set bundle path
16
+ ENV BUNDLE_PATH /bundle
17
+
18
+ # Default to console
19
+ CMD ["bin/console"]
data/.docker/Makefile ADDED
@@ -0,0 +1,43 @@
1
+ export SPEC ?= spec
2
+ SPEC_FILE = $(subst ../,, $(SPEC))
3
+ export RUBY_IMAGE ?= ruby:3.1.2-slim
4
+
5
+ .PHONY: up
6
+ up:
7
+ docker-compose up
8
+
9
+ .PHONY: down
10
+ down:
11
+ docker-compose down
12
+
13
+ .PHONY: test
14
+ test: rspec
15
+
16
+ .PHONY: ssh
17
+ ssh:
18
+ docker-compose run lib bash
19
+
20
+ .PHONY: install
21
+ install:
22
+ docker-compose run lib bin/setup
23
+
24
+ .PHONY: console
25
+ console:
26
+ docker-compose run lib bin/console
27
+
28
+ .PHONY: rspec
29
+ rspec:
30
+ docker-compose run lib bin/rspec ${SPEC_FILE}
31
+
32
+ .PHONY: rake
33
+ rake:
34
+ docker-compose run lib bundle exec rake
35
+
36
+ .PHONY: lint
37
+ lint:
38
+ docker-compose run lib bundle exec rubocop
39
+
40
+ .PHONY: setup
41
+ setup:
42
+ docker-compose build --build-arg RUBY_IMAGE=${RUBY_IMAGE}
43
+ docker-compose run lib bin/setup
@@ -0,0 +1,14 @@
1
+ version: "3"
2
+
3
+ services:
4
+ lib:
5
+ build:
6
+ context: .
7
+ dockerfile: ./.docker/Dockerfile
8
+
9
+ volumes:
10
+ - .:/workspace
11
+ - bundle:/bundle
12
+
13
+ volumes:
14
+ bundle:
data/.docker/readme.md ADDED
@@ -0,0 +1,61 @@
1
+ ## Docker
2
+
3
+ This directory is only meant to be used for development, and contains some
4
+ necessary setup to spin up docker containers with multiple ruby environment.
5
+
6
+ ### Setup
7
+
8
+ Before doing anything, you might want to create a symlink to the docker file and
9
+ Makefile. This would allow you to avoid some of the unnecessary work related to
10
+ the file paths To do that run the following from the root of the project.
11
+
12
+ ```
13
+ ln -sf .docker/Makefile .
14
+ ln -sf .docker/docker-compose.yml .
15
+ ```
16
+
17
+ By default it usages the most recent ruby version for docker environment, but if
18
+ you want to run it in any specific version then you can set it up by exporting
19
+ `RUBY_IMAGE` environment variable in your shell:
20
+
21
+ ```sh
22
+ export RUBY_IMAGE=ruby:3.0-buster
23
+ ```
24
+
25
+ Once everything is set then you would need to build the development images for
26
+ the first time and you can do that using:
27
+
28
+ ```sh
29
+ make setup
30
+ ```
31
+
32
+ The setup process will install all dependencies and it will also setup a volume
33
+ to speed up the repeated gem installation.
34
+
35
+ ### Playground
36
+
37
+ The `Makefile` contains two target for tests, and you can run the tests using
38
+ any of the following commands:
39
+
40
+ ```sh
41
+ make test
42
+
43
+ # or
44
+ make rspec
45
+ ```
46
+
47
+ If you need more control, and you want to do some development on the go then you
48
+ can get into the container using:
49
+
50
+ ```sh
51
+ make ssh
52
+ ```
53
+
54
+ ### Cleanup
55
+
56
+ Once you are done with your experiment then you can cleanup the docker
57
+ environment using the following command.
58
+
59
+ ```sh
60
+ make down
61
+ ```
@@ -0,0 +1,15 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ jobs:
12
+ rake:
13
+ uses: metanorma/ci/.github/workflows/generic-rake.yml@main
14
+ secrets:
15
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
@@ -0,0 +1,24 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: release
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
+ required: true
12
+ default: 'skip'
13
+ repository_dispatch:
14
+ types: [ do-release ]
15
+
16
+ jobs:
17
+ release:
18
+ uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
19
+ with:
20
+ next_version: ${{ github.event.inputs.next_version }}
21
+ secrets:
22
+ rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
23
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
24
+
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .rubocop-https---**
13
+ Gemfile.lock
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "spec/oscal-content"]
2
+ path = spec/oscal-content
3
+ url = https://github.com/usnistgov/oscal-content
data/.hound.yml ADDED
@@ -0,0 +1,5 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ ruby:
4
+ enabled: true
5
+ config_file: .rubocop.yml
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
- --format documentation
2
1
  --color
3
2
  --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ inherit_from:
4
+ - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
5
+
6
+ # local repo-specific modifications
7
+ # ...
8
+
9
+ AllCops:
10
+ TargetRubyVersion: 2.7
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.1
data/Gemfile CHANGED
@@ -10,3 +10,7 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+
14
+ gem "rubocop-performance", "~> 1.16"
15
+
16
+ gem "debug"
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2023, Ribose
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Makefile ADDED
@@ -0,0 +1 @@
1
+ .docker/Makefile
data/README.adoc CHANGED
@@ -1,5 +1,15 @@
1
1
  = OSCAL in Ruby
2
2
 
3
+ == Purpose
4
+
5
+ This is an implementation of the OSCAL models, allowing the manipulation of
6
+ these models, as well as reading and writing of OSCAL serialization formats
7
+ (YAML, JSON, XML).
8
+
9
+ NOTE: This gem is used by the
10
+ https://github.com/metanorma/metanorma-plugin-oscal[Metanorma plugin for OSCAL].
11
+
12
+
3
13
  == Installation
4
14
 
5
15
  Install the gem:
@@ -20,6 +30,59 @@ gem 'oscal'
20
30
 
21
31
  TODO: Write usage instructions here
22
32
 
33
+ [source,ruby]
34
+ ----
35
+ > require 'oscal'
36
+ > x = Oscal::Catalog.load_from_yaml('spec/oscal-content/examples/catalog/yaml/basic-catalog.yaml')
37
+ =>
38
+ #<Oscal::Catalog:0x000000010b817e08
39
+ ...
40
+ > x.groups.first.groups.first.parts.first.prose
41
+ => "To establish a management framework to initiate and control the implementation and operation of information security within the organization."
42
+ ----
43
+
44
+ Get all controls
45
+
46
+ [source,ruby]
47
+ ----
48
+ > require 'oscal'
49
+ > x = Oscal::Catalog.load_from_yaml('spec/oscal-content/examples/catalog/yaml/basic-catalog.yaml')
50
+ =>
51
+ #<Oscal::Catalog:0x000000010b817e08
52
+ ...
53
+ > o = x.get_all_controls
54
+ > o.count
55
+ => 4
56
+ ----
57
+
58
+ Find object by id
59
+
60
+ [source,ruby]
61
+ ----
62
+ > require 'oscal'
63
+ > x = Oscal::Catalog.load_from_yaml('spec/oscal-content/examples/catalog/yaml/basic-catalog.yaml')
64
+ =>
65
+ #<Oscal::Catalog:0x000000010b817e08
66
+ ...
67
+ > p = x.find_object_by_id('s1.1_smt')
68
+ =>
69
+ #<Oscal::Part:0x000000014c0c4070 @id="s1.1_smt", ...>
70
+ ----
71
+
72
+ Find object by uuid
73
+
74
+ [source,ruby]
75
+ ----
76
+ > require 'oscal'
77
+ > x = Oscal::Catalog.load_from_yaml('spec/oscal-content/examples/catalog/yaml/basic-catalog.yaml')
78
+ =>
79
+ #<Oscal::Catalog:0x000000010b817e08
80
+ ...
81
+ > p = x.find_object_by_id('74c8ba1e-5cd4-4ad1-bbfd-d888e2f6c724', x, :uuid)
82
+ =>
83
+ #<Oscal::Catalog:0x000000014c0c5f38 @uuid="74c8ba1e-5cd4-4ad1-bbfd-d888e2f6c724", ...>
84
+ ----
85
+
23
86
  == Ruby library usage
24
87
 
25
88
  TODO: Write usage instructions here
@@ -47,3 +110,6 @@ Everyone interacting in the Oscal project's codebases, issue trackers, chat room
47
110
  == LICENSE
48
111
 
49
112
  Copyright Ribose. The OSCAL schema is published by NIST.
113
+
114
+ Published under the 2-clause BSD license.
115
+
data/Rakefile CHANGED
@@ -3,10 +3,17 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
5
 
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
6
+ # Note:
7
+ #
8
+ # There seems to be lots of issue with the current rubocop rules
9
+ # We are commenting this out for the moment, so instead of fixing
10
+ # those right away, we can focus on the new codes and then later
11
+ # come back to this and fix the issues.
12
+ #
13
+ # require "rubocop/rake_task"
14
+ # RuboCop::RakeTask.new
15
+ #
16
+ # task default: %i[spec rubocop]
9
17
 
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
18
+ RSpec::Core::RakeTask.new(:spec)
19
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "oscal"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+
16
+ def reload!(print = true)
17
+ puts "Reloading ..." if print
18
+ # Main project directory.
19
+ root_dir = File.expand_path("..", __dir__)
20
+ # Directories within the project that should be reloaded.
21
+ reload_dirs = %w{lib}
22
+ # Loop through and reload every file in all relevant project directories.
23
+ reload_dirs.each do |dir|
24
+ Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
25
+ end
26
+ # Return true when complete.
27
+ true
28
+ end
29
+
30
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ .docker/docker-compose.yml