-
Notifications
You must be signed in to change notification settings - Fork 42
Add SSO group id lookup parameter resolver #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrewjhumphrey
merged 24 commits into
master
from
andrewjhumphrey-sso-group-id-parameter-resolverid
Jul 11, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b391b4e
Tests!
andrewjhumphrey 8edf382
Add in resolver code and integrate into main app
andrewjhumphrey 380ff82
linting
andrewjhumphrey 97feb2f
Add some documentation too
andrewjhumphrey d0c6d62
PR Feedback fixes
andrewjhumphrey 6de910d
Add tests for the finder class too
andrewjhumphrey 6fd6c5a
Make ruby3.0+ compatible
andrewjhumphrey eabc066
Handle positional args properly
andrewjhumphrey 8280eb3
Another attempt to fix ruby3 incompatibilities
andrewjhumphrey 47d2b64
Revert "Another attempt to fix ruby3 incompatibilities"
andrewjhumphrey ba77d21
Revert "Handle positional args properly"
andrewjhumphrey 40d4e7e
Let people know which directory was searched
andrewjhumphrey f51bee8
Pass hash, not named arguments
andrewjhumphrey 3bf111c
Pass hash, not named arguments (in all the places, not just some)
andrewjhumphrey 6f79b20
Use a before block
andrewjhumphrey 4025580
Umm, itchy tab key finger
andrewjhumphrey f55d905
Update docs and test for new way of specifying identity-store-id
andrewjhumphrey f702341
Remove the top level sso_identity_store_id attribute
andrewjhumphrey af6e6bd
Use the same format as stack_output does to specify the region,identi…
andrewjhumphrey 45d27f0
Use much more efficient method of finding group
andrewjhumphrey af64e1d
hash not keywords again
andrewjhumphrey 43f67e4
And again
andrewjhumphrey f8b6f67
Update with PR details
andrewjhumphrey d6cb2ae
Remove double double quote
andrewjhumphrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| module StackMaster | ||
| module ParameterResolvers | ||
| class SsoGroupId < Resolver | ||
| InvalidParameter = Class.new(StandardError) | ||
|
|
||
| def initialize(config, stack_definition) | ||
| @config = config | ||
| @stack_definition = stack_definition | ||
| end | ||
|
|
||
| def resolve(value) | ||
| sso_group_id_finder.find(value) | ||
| end | ||
|
|
||
| private | ||
| def sso_group_id_finder | ||
| StackMaster::SsoGroupIdFinder.new() | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| module StackMaster | ||
| class SsoGroupIdFinder | ||
| SsoGroupNotFound = Class.new(StandardError) | ||
|
|
||
| def find(reference) | ||
| output_regex = %r{(?:(?<region>[^:]+):)?(?<identity_store_id>[^:/]+)/(?<group_name>.+)} | ||
|
|
||
| if !reference.is_a?(String) || !(match = output_regex.match(reference)) | ||
| raise ArgumentError, 'Sso group lookup parameter must be in the form of [region:]identity-store-id/group_name' | ||
| end | ||
|
|
||
| region = match[:region] || StackMaster.cloud_formation_driver.region | ||
| client = Aws::IdentityStore::Client.new({ region: region }) | ||
orien marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| begin | ||
| response = client.get_group_id({ | ||
| identity_store_id: match[:identity_store_id], | ||
| alternate_identifier: { | ||
| unique_attribute: { | ||
| attribute_path: 'displayName', | ||
| attribute_value: match[:group_name], | ||
| }, | ||
| }, | ||
| }) | ||
| return response.group_id | ||
| rescue Aws::IdentityStore::Errors::ServiceError => e | ||
| puts "Error calling GetGroupId: #{e.message}" | ||
| end | ||
|
|
||
| raise SsoGroupNotFound, "No group with name #{match[:group_name]} found in identity store #{match[:identity_store_id]} in #{region}" | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| module StackMaster | ||
| VERSION = "2.16.0" | ||
| VERSION = "2.17.0" | ||
andrewjhumphrey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
50 changes: 50 additions & 0 deletions
50
spec/stack_master/parameter_resolvers/sso_group_id_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| require 'spec_helper' | ||
|
|
||
| RSpec.describe StackMaster::ParameterResolvers::SsoGroupId do | ||
| let(:config) { instance_double('Config') } | ||
| let(:stack_definition) { instance_double('StackDefinition', region: 'us-east-1') } | ||
|
|
||
| subject(:resolver) { described_class.new(config, stack_definition) } | ||
|
|
||
| let(:group_reference) { 'us-east-1:d-12345678/AdminGroup' } | ||
| let(:resolved_group_id) { 'abc-123-group-id' } | ||
| let(:finder) { instance_double(StackMaster::SsoGroupIdFinder) } | ||
|
|
||
| before do | ||
| allow(StackMaster::SsoGroupIdFinder).to receive(:new).and_return(finder) | ||
| end | ||
|
|
||
| describe '#resolve' do | ||
| context 'when group is found' do | ||
| it 'returns the resolved group ID' do | ||
| expect(finder).to receive(:find).with(group_reference).and_return(resolved_group_id) | ||
|
|
||
| result = resolver.resolve(group_reference) | ||
| expect(result).to eq(resolved_group_id) | ||
| end | ||
| end | ||
|
|
||
| context 'when SsoGroupIdFinder raises an error' do | ||
| it 'propagates the SsoGroupNotFound error' do | ||
| allow(finder).to receive(:find).and_raise(StackMaster::SsoGroupIdFinder::SsoGroupNotFound) | ||
|
|
||
| expect { | ||
| resolver.resolve(group_reference) | ||
| }.to raise_error(StackMaster::SsoGroupIdFinder::SsoGroupNotFound) | ||
| end | ||
| end | ||
|
|
||
| context 'with invalid input' do | ||
| let(:invalid_reference) { 'not/a/valid/reference' } | ||
|
|
||
| it 'raises ArgumentError from SsoGroupIdFinder' do | ||
| allow(finder).to receive(:find).and_raise(ArgumentError) | ||
|
|
||
| expect { | ||
| resolver.resolve(invalid_reference) | ||
| }.to raise_error(ArgumentError) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| require 'spec_helper' | ||
|
|
||
| RSpec.describe StackMaster::SsoGroupIdFinder do | ||
| let(:group_name) { 'AdminGroup' } | ||
| let(:identity_store_id) { 'd-12345678' } | ||
| let(:region) { 'us-east-1' } | ||
| let(:reference) { "#{region}:#{identity_store_id}/#{group_name}" } | ||
| let(:aws_client) { instance_double(Aws::IdentityStore::Client) } | ||
|
|
||
| subject(:finder) do | ||
| allow(Aws::IdentityStore::Client).to receive(:new).with({region: region}).and_return(aws_client) | ||
| described_class.new | ||
| end | ||
|
|
||
| before do | ||
| allow(StackMaster).to receive(:cloud_formation_driver).and_return(double(region: region)) | ||
| end | ||
|
|
||
| describe '#find' do | ||
| context 'when the group is found successfully' do | ||
| it 'returns the group ID' do | ||
| group_id = 'abc-123-group-id' | ||
|
|
||
| response = double(group_id: group_id) | ||
| expect(aws_client).to receive(:get_group_id).with({ | ||
| identity_store_id: identity_store_id, | ||
| alternate_identifier: { | ||
| unique_attribute: { | ||
| attribute_path: 'displayName', | ||
| attribute_value: group_name | ||
| } | ||
| } | ||
| }).and_return(response) | ||
|
|
||
| expect(finder.find(reference)).to eq(group_id) | ||
| end | ||
| end | ||
|
|
||
| context 'when the group is not found' do | ||
| it 'raises SsoGroupNotFound' do | ||
| error = Aws::IdentityStore::Errors::ResourceNotFoundException.new( | ||
| Seahorse::Client::RequestContext.new, | ||
| "Group not found" | ||
| ) | ||
|
|
||
| expect(aws_client).to receive(:get_group_id).and_raise(error) | ||
|
|
||
| expect { | ||
| finder.find(reference) | ||
| }.to raise_error(StackMaster::SsoGroupIdFinder::SsoGroupNotFound, /No group with name #{group_name} found/) | ||
| end | ||
| end | ||
|
|
||
| context 'when region is not provided in reference' do | ||
| let(:reference_without_region) { "#{identity_store_id}/#{group_name}" } | ||
|
|
||
| it 'uses the fallback region from cloud_formation_driver' do | ||
| allow(Aws::IdentityStore::Client).to receive(:new).with({region: region}).and_return(aws_client) | ||
|
|
||
| group_id = 'fallback-region-group-id' | ||
| response = double(group_id: group_id) | ||
|
|
||
| expect(aws_client).to receive(:get_group_id).with({ | ||
| identity_store_id: identity_store_id, | ||
| alternate_identifier: { | ||
| unique_attribute: { | ||
| attribute_path: 'displayName', | ||
| attribute_value: group_name | ||
| } | ||
| } | ||
| }).and_return(response) | ||
|
|
||
| expect(finder.find(reference_without_region)).to eq(group_id) | ||
| end | ||
| end | ||
|
|
||
| context 'when input is not a string' do | ||
| it 'raises ArgumentError' do | ||
| expect { | ||
| finder.find(123) | ||
| }.to raise_error(ArgumentError, /Sso group lookup parameter must be in the form/) | ||
| end | ||
| end | ||
|
|
||
| context 'when input is an invalid string' do | ||
| it 'raises ArgumentError' do | ||
| invalid_reference = 'badformat' | ||
|
|
||
| expect { | ||
| finder.find(invalid_reference) | ||
| }.to raise_error(ArgumentError, /Sso group lookup parameter must be in the form/) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.