-
Notifications
You must be signed in to change notification settings - Fork 10
Add support for DSQL iam authentication #919
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
Open
leszek-bq
wants to merge
16
commits into
aws:main
Choose a base branch
from
leszek-bq:dsql_iam
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,294
−116
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
037ed3c
Add support for DSQL iam authentication
leszekamz 821750a
Fixed errors with updated interfaces for federated and octa plugins.
leszekamz 69a1a5c
flake and isort updates
leszekamz ed40d71
isort updates
leszekamz c838379
fixed unit tests
leszekamz 737adcf
added DSQL unit tests
leszekamz c52315b
sorting imports - isort
leszekamz 0cc92c5
adding iam_dsql plugin documentation
leszekamz b1f2180
updated readme.md
leszekamz cf805a8
addressing code review comments
leszekamz e1503c9
addressing more code review comments
leszekamz ab49fbc
Added integration tests for dsql and updated relevant files
leszekamz 268d816
merge with main
leszekamz fc9df7e
addressing code review comments
leszekamz 300b0ff
Removed unused method in test
leszekamz f0ad4da
Removed unused import in test
leszekamz 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
30 changes: 30 additions & 0 deletions
30
aws_advanced_python_wrapper/dsql_iam_auth_plugin_factory.py
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,30 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from aws_advanced_python_wrapper.iam_plugin import IamAuthPlugin | ||
from aws_advanced_python_wrapper.plugin import Plugin, PluginFactory | ||
from aws_advanced_python_wrapper.utils.dsql_token_utils import DSQLTokenUtils | ||
|
||
if TYPE_CHECKING: | ||
from aws_advanced_python_wrapper.plugin_service import PluginService | ||
from aws_advanced_python_wrapper.utils.properties import Properties | ||
|
||
|
||
class DsqlIamAuthPluginFactory(PluginFactory): | ||
def get_instance(self, plugin_service: PluginService, props: Properties) -> Plugin: | ||
return IamAuthPlugin(plugin_service, DSQLTokenUtils()) |
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
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,75 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Dict, Optional | ||
|
||
from aws_advanced_python_wrapper.utils.log import Logger | ||
from aws_advanced_python_wrapper.utils.telemetry.telemetry import \ | ||
TelemetryTraceLevel | ||
from aws_advanced_python_wrapper.utils.token_utils import TokenUtils | ||
|
||
if TYPE_CHECKING: | ||
from aws_advanced_python_wrapper.plugin_service import PluginService | ||
from boto3 import Session | ||
|
||
import boto3 | ||
|
||
logger = Logger(__name__) | ||
|
||
|
||
class DSQLTokenUtils(TokenUtils): | ||
def generate_authentication_token( | ||
self, | ||
plugin_service: PluginService, | ||
user: Optional[str], | ||
host_name: Optional[str], | ||
port: Optional[int], | ||
region: Optional[str], | ||
credentials: Optional[Dict[str, str]] = None, | ||
client_session: Optional[Session] = None) -> str: | ||
telemetry_factory = plugin_service.get_telemetry_factory() | ||
context = telemetry_factory.open_telemetry_context("fetch DSQL authentication token", TelemetryTraceLevel.NESTED) | ||
|
||
try: | ||
session = client_session if client_session else boto3.Session() | ||
if credentials is not None: | ||
client = session.client( | ||
'dsql', | ||
region_name=region, | ||
aws_access_key_id=credentials.get('AccessKeyId'), | ||
aws_secret_access_key=credentials.get('SecretAccessKey'), | ||
aws_session_token=credentials.get('SessionToken') | ||
) | ||
else: | ||
client = session.client( | ||
'dsql', | ||
region_name=region | ||
) | ||
|
||
if user == "admin": | ||
token = client.generate_db_connect_admin_auth_token(host_name, region) | ||
else: | ||
token = client.generate_db_connect_auth_token(host_name, region) | ||
|
||
logger.debug("TokenUtils.GeneratedNewAuthTokenLength", len(token) if token else 0) | ||
client.close() | ||
return token | ||
except Exception as ex: | ||
context.set_success(False) | ||
context.set_exception(ex) | ||
raise ex | ||
finally: | ||
context.close_context() |
Oops, something went wrong.
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.