Skip to content
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

Assignable user and application IDs #901

Merged
merged 2 commits into from
Apr 11, 2019
Merged

Assignable user and application IDs #901

merged 2 commits into from
Apr 11, 2019

Conversation

kouponmedia
Copy link

Updated validateAndCreateUser & validateAndCreateApp in user & application services. Changed order of object assign to allow id property to be used if present instead of generating a new uuid.

In my case, I need to integrate with an existing PKI where client_id/secret already exist for our customers. I want to be able to assign IDs to the client application instead of generating new IDs. See the following example:

{
  "$id": "http://express-gateway.io/models/applications.json",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "name": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name"
  ]
}

eg apps create -u <user> -p "name=<name>" -p "id=<id>"

Nicholas Carroll added 2 commits April 5, 2019 13:28
…ation services.

Changed order of object assign to allow id property to be used if present instead of generating a new uuid.
@codecov
Copy link

codecov bot commented Apr 5, 2019

Codecov Report

Merging #901 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #901   +/-   ##
=======================================
  Coverage   89.07%   89.07%           
=======================================
  Files         136      136           
  Lines        3688     3688           
=======================================
  Hits         3285     3285           
  Misses        403      403
Impacted Files Coverage Δ
lib/services/consumers/user.service.js 90.62% <100%> (ø) ⬆️
lib/services/consumers/application.service.js 89.69% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02b9a9e...fbb57a1. Read the comment docs.

Copy link
Member

@XVincentX XVincentX left a comment

Choose a reason for hiding this comment

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

Hey,

the changes look good to me, I just do not understand that line change in the tests; they feel wrong to me. If you could explain (or maybe find a better way) I can get this change in!

@kouponmedia
Copy link
Author

kouponmedia commented Apr 10, 2019

It wasn't obvious to me at first, but by switching the order of args in the Object.assign in validateAndCreateUser, the original passed in object is not being modified anymore and instead a new pointer is returned. This affected the test because the test tries to use the original pointer instead of one returned from the insert promise. This didn't affect actual behavior because the insert functions in both the user and application services always use objects returned from promises.

This does smell a bit because now a developer has to know that we're not just decorating pointers and instead we have to use the result of a promise because the pointer may have changed. Changing the order of Object.assign is not the only way this could be achieved. I really just want to be able to override the ID. Something like this would work too.

const baseUserProps = { isActive: 'true', username: _user.username, id: newUser.id || uuidv4() };
if (newUser) {
        user = Object.assign(newUser, baseUserProps); // update & return the original pointer
} else user = baseUserProps;

Thoughts?

@XVincentX XVincentX merged commit de96219 into ExpressGateway:master Apr 11, 2019
@XVincentX
Copy link
Member

Ok, that makes sense.

gatherchou pushed a commit to yilu-tech/express-gateway that referenced this pull request Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants