Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
entitlements-app (1.1.0)
entitlements-app (1.2.0)
concurrent-ruby (~> 1.3, >= 1.3.1)
faraday (~> 2.0)
logger (~> 1.6)
Expand Down Expand Up @@ -33,6 +33,7 @@ GEM
crack (1.0.0)
bigdecimal
rexml
date (3.4.1)
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
Expand Down Expand Up @@ -67,7 +68,8 @@ GEM
parser (3.3.1.0)
ast (~> 2.4.1)
racc
psych (5.1.2)
psych (5.2.3)
date
stringio
public_suffix (5.0.5)
racc (1.8.0)
Expand Down Expand Up @@ -131,7 +133,7 @@ GEM
simplecov (< 1.0)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
stringio (3.1.0)
stringio (3.1.4)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
Expand Down
22 changes: 22 additions & 0 deletions lib/entitlements/data/groups/calculated/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ def description
parsed_data.fetch("description", "")
end

# Standard interface: Get the schema version of this group.
#
# Takes no arguments.
# Examples: "entitlements/v1", "entitlements/v1.2.3", "entitlements/1.2.3"
# Format: namespace/major.minor.patch
#
# Returns a String with the schema version (k8s-style), or "entitlements/v1" if undefined.
Contract C::None => String
def schema_version
schema_version = parsed_data.fetch("schema_version", "entitlements/v1").to_s

namespace, version = schema_version.split("/")

unless namespace.match?(/\A[a-zA-Z0-9]+\z/) && version.match?(/\A(v?\d+(\.\d+){0,2})\z/)
raise "Invalid schema version format: #{schema_version} - Expected format is '<namespace>/<version>' " \
"- Examples: entitlements/v1, entitlements/v1.2.3, entitlements/1.2.3"
end

# rebuild the schema version string to ensure it's in the correct format and return it
return "#{namespace}/#{version}"
end

# Files can support modifiers that act independently of rules.
# This returns the modifiers from the file as a hash.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Entitlements
module Version
VERSION = "1.1.0"
VERSION = "1.2.0"
end
end
51 changes: 51 additions & 0 deletions spec/unit/entitlements/data/groups/calculated/yaml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,57 @@
end
end

describe "#schema_version" do
it "returns the version string when one is set" do
filename = fixture("ldap-config/filters/no-filters-with-schema-version.yaml")
subject = described_class.new(filename: filename)
expect(subject.schema_version).to eq("entitlements/1.2.3")
end

it "returns the version string when one is set without the patch" do
filename = fixture("ldap-config/filters/no-filters-with-schema-version-no-patch.yaml")
subject = described_class.new(filename: filename)
expect(subject.schema_version).to eq("entitlements/1.2")
end

it "returns the version string when one is set with just the major version" do
filename = fixture("ldap-config/filters/no-filters-with-schema-version-major.yaml")
subject = described_class.new(filename: filename)
expect(subject.schema_version).to eq("entitlements/1")
end

it "returns the version string when one is set with just the major version (with v prefix)" do
filename = fixture("ldap-config/filters/no-filters-with-schema-version-major-with-v.yaml")
subject = described_class.new(filename: filename)
expect(subject.schema_version).to eq("entitlements/v1")
end


it "returns the version string when one is set (with v prefix)" do
filename = fixture("ldap-config/filters/no-filters-with-schema-version-with-v.yaml")
subject = described_class.new(filename: filename)
expect(subject.schema_version).to eq("entitlements/v1.2.3")
end

it "returns the default version when schema_version is undefined" do
filename = fixture("ldap-config/filters/no-filters-description.yaml")
subject = described_class.new(filename: filename)
expect(subject.schema_version).to eq("entitlements/v1")
end

it "throws an error when an invalid schema_version string is provided" do
filename = fixture("ldap-config/filters/no-filters-with-bad-schema-version.yaml")
subject = described_class.new(filename: filename)
expect { subject.schema_version }.to raise_error(RuntimeError, /Invalid schema version format/)
end

it "throws an error when the version string is missing the namespace" do
filename = fixture("ldap-config/filters/no-filters-with-missing-version-namespace.yaml")
subject = described_class.new(filename: filename)
expect { subject.schema_version }.to raise_error(RuntimeError, /Invalid schema version format/)
end
end

describe "#initialize_filters" do
it "returns the default filter hash when no filters are defined" do
filename = fixture("ldap-config/filters/no-filters.yaml")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Yo kittens
schema_version: entitlements/1.abc2.3
rules:
or:
- username: russianblue
- username: BlackManx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Yo kittens
schema_version: 1.2.3
rules:
or:
- username: russianblue
- username: BlackManx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Yo kittens
schema_version: entitlements/v1
rules:
or:
- username: russianblue
- username: BlackManx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Yo kittens
schema_version: entitlements/1
rules:
or:
- username: russianblue
- username: BlackManx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Yo kittens
schema_version: entitlements/1.2
rules:
or:
- username: russianblue
- username: BlackManx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Yo kittens
schema_version: entitlements/v1.2.3
rules:
or:
- username: russianblue
- username: BlackManx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Yo kittens
schema_version: entitlements/1.2.3
rules:
or:
- username: russianblue
- username: BlackManx
Binary file added vendor/cache/date-3.4.1.gem
Binary file not shown.
Binary file removed vendor/cache/psych-5.1.2.gem
Binary file not shown.
Binary file added vendor/cache/psych-5.2.3.gem
Binary file not shown.
Binary file removed vendor/cache/stringio-3.1.0.gem
Binary file not shown.
Binary file added vendor/cache/stringio-3.1.4.gem
Binary file not shown.
Loading