Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Conversation

@smithsz
Copy link
Contributor

@smithsz smithsz commented Mar 14, 2018

Thanks for your hard work, please ensure all items are complete before opening.

What

Support IAM authenticated databases when replicating.

How

Expose the IAM API key via the client session and inject into the replication document where applicable.

Testing

Includes additional mock unit tests.

Issues

Fixes #354.

@emlaver
Copy link
Contributor

emlaver commented Mar 15, 2018

Update copyright for _client_session.py

'IAM_TOKEN_URL', 'https://iam.bluemix.net/identity/token')

@property
def api_key(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be named get_api_key following the design of the functions in this class e.g. _get_access_token?

type(m_admin_party_client).admin_party = mock.PropertyMock(
return_value=True)
type(m_admin_party_client).server_url = mock.PropertyMock(
return_value=self.server_url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should put this code into it's own method so that it can be called by all tests in this class. It would require 4 if blocks for options admin_party, server_url, r_session, and is_iam_authenticated.

Copy link
Member

@ricellis ricellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not reviewed the tests for now as I think this might need bigger changes. I'm reluctant for it to scope creep into fixing the old source/target URL issue, but I think that is a lot easier if we remove the access to the current credentials and force them to be supplied appropriately for creating replicator documents.

create the target, if it does not already exist.
:param bool continuous: If set to True then the replication will be
continuous.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing user_ctx applies to a target only. I think we need to make source_user(_ctx?) and target_user(_ctx?) args that can be used to specify. We should alias the user_ctx to target_user to maintain backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what you mean here. Can we please go through it when you get a mo? Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a long time ago and I'm struggling to reverse engineer my meaning too! I think what I was getting at was that the user_ctx default setting is dependent on some checks on the target, but not the source. My suggestion above doesn't make sense either though.

What I think makes sense is that the default user_ctx is set if one isn't supplied, but should not depend on any checks for the source or target database.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed admin party check in eaaa7f1.

)
if source_db.admin_party:
pass # no credentials required
elif source_db.client.is_iam_authenticated:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auth used in a replicator document should be independent of the method with which the client is authenticated. For example there is no reason why I can't login python-cloudant with my account credentials and create a replicator document using any other credentials including IAM API keys.

This code should be a fallback only if the source_user is empty and target_user are empty. I think however, that a new version of the create_replication should require some credential information and the fallback should only be used in the backwards compatibility case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source_db and target_db are supplied to the create_replication method. They are type database objects and therefore don't share credentials used to POST the replication doc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see what you mean, everything is an object, so the specific credentials will have been supplied up front in construction of the necessary source or target database objects (or more specifically the client instances needed for those if they are distinct from the replicator.

I think it would be nice if a replication could be created with a source & target URLs and the associated API keys i.e. 4 strings instead of needing to potentially instantiate multiple clients and DBs, but that is out of scope here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to note that we made a decision to remove source/target URLs from replication (#342) as it wasn't working properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's why I think it is out of scope to try and re-introduce that in a working fashion here.

data['target'].update(
{'headers': {'Authorization': target_db.creds['basic_auth']}}
)
if source_db.admin_party:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be the target? Also shouldn't we only do these checks if a user_ctx wasn't provided?

@smithsz smithsz force-pushed the 354-support-iam-auth-in-replications branch 8 times, most recently from eaaa7f1 to 04deb46 Compare May 1, 2018 13:00
pass # noop - not required for admin party mode
elif self.database.creds and self.database.creds.get('user_ctx'):
data['user_ctx'] = self.database.creds['user_ctx']
if not data.get('user_ctx') and self.database.creds and \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where user_ctx doesn't exist in data and database.creds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, admin party mode.

Copy link
Contributor

@emlaver emlaver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@smithsz smithsz force-pushed the 354-support-iam-auth-in-replications branch from 04deb46 to 8cbee2a Compare May 10, 2018 13:52
@smithsz smithsz merged commit 1020447 into master May 10, 2018
@smithsz smithsz deleted the 354-support-iam-auth-in-replications branch May 10, 2018 14:26
@ricellis ricellis added this to the 2.next milestone May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants