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

Dynamic mount point #42

Closed
miladhashemi opened this issue Nov 29, 2020 · 12 comments
Closed

Dynamic mount point #42

miladhashemi opened this issue Nov 29, 2020 · 12 comments
Assignees

Comments

@miladhashemi
Copy link
Contributor

Hi,
Is it possible to create mountpoint at runtime?
For example, in an application, can I careate a new mountpoint with one of adapters registered before?
server.js:
can we do something like this?
{....core.configuration.mountpoints, newMountpoint} and using it as mountpoints list in application. or just create an mountpoint entry and use it:

const mountpoint = ({
    adapter:'monster',
    name:'Run time mountpoint',
    attributes : .............
})

an then use mountpoint. for creating mountpoint in application.

Also How can I do this independent of an application. creating mountpoint at osjs run time under some condition, and accessing it in whole osjs.

@andersevenrud
Copy link
Member

andersevenrud commented Nov 29, 2020

This is technically possible, but the APIs are not exposed via any service providers in the current version(s) of the client and server.

If you create an issue in the osjs-client as well then I'll try to look at it by this week.

Also How can I do this independent of an application.

Create a service provider. You could wire it together either via signals (events) or a service contract.

class MyServiceProvider {
  constructor(core, options = {}) {
    this.core = core
    this.options = options
  }

  async init() {
    this.core.singleton('my-service', this.createMyContract())
  }

  createMyContract() {
    return {
      mount: () => this.createSomeMountpoint()
    }
  }

  createSomeMountpoint() {
    // This is where you would add stuff to do actual operations
  }
}

Then via your apps do core.make('my-service').mount().

@andersevenrud
Copy link
Member

Then via your apps do

Which does not have to be an app ofc. And as for conditions, you can create your own state(s) and such and as I mentioned wire it together with events.

If you have some idea how you need it to work, then show me and I can write a more complete example.

@miladhashemi
Copy link
Contributor Author

miladhashemi commented Nov 30, 2020

Let's consider this scenario.
A user logins to osjs. each user may has different mountpoint with deferent attirbutes (but all of them have the same adapter).
for example:

mountpoints: [{
              name: 'myMonster',
              adapter: 'monster',
              attributes: {
                  endpoint: "http://localhost:12345/auth/v1.0",
              }
          }, {
              name: 'some-name',
              adapter: 'monster',
              attributes: {
                  endpoint: "http://somehost:8080/auth/v1.0",
              }
          }, ... // mountpoints could be more
]

This object must be created at runtime as a user logins to OS.js, and a user must could seen his mountpoints and select each one to mount/unmount.
creating a client adapter couldn't help because all mountpoints are remote.

Create a service provider. You could wire it together either via signals (events) or a service contract.

Still I didn't write service provider.

Of course I think one way may helps:
when a user try logins with username and password, after validation he gets token and endpoints list. then we could save tokens in session storage for every adapter method query(checking user's privileges) and save endpoints and name in osjs settings. In this way, certainly we need implement server.js for each application needs this mountpoints(with passing token and endpoint to server.js) and call vfs there and return response.(creating server.js for each application is this approach disatvantge)
I hope I have told it clear.

@andersevenrud
Copy link
Member

With the scenario you just described it sounds like you might not need any runtime dynamic mount/unmount on the client-side, but rather make the login process manipulate the mounpoint list (upon login) that usually comes from the statically generated configuration.

As for the server side, since you're using the same adapter for everything, I think a nice way to approach this is to make a mountpoint adapter support RegEx in the name property.

I think this solves the issue in a fast and efficient way for your needs -- at least if you know what name(s) you're going to use for your mountpoints.

So, to summarize:

  1. Change the Filesystem component in the client to initially store the mountpoint list from config
    • Add API method to add to this list
    • Add this API method to the VFS service contract
  2. Change the Filesystem component in the server to support RegEx matching on mountpoint names

@andersevenrud andersevenrud self-assigned this Dec 24, 2020
@miladhashemi
Copy link
Contributor Author

Sorry Anders, we started new contribution on openstack (tempAuth+keystone) authentication that must completed first. We make new issue to contribute openstack authentication soon!

As for the server side, since you're using the same adapter for everything, I think a nice way to approach this is to make a mountpoint adapter support RegEx in the name property.

Actually we need mount users object storage as they login(Now we create mountpoint right after users login, in auth adapter). bellow code do this for us:

.
.
.
const projectIds = Object.keys(req.session.swiftAuth.projects);
let fs = core.make('osjs/fs');
projectIds.map (item => {
  const name = req.session.swiftAuth.projects[item]['name'];
  fs.mountpoints.push({name: name, adapter: 'monster', id:item, attributes:{}});
});
.
.
.

Create a service provider. You could wire it together either via signals (events) or a service contract.

As you said before, we must write serviceProvider to decouple this operation from login and depends it to auth SP.

But our new issue is creating client mountpoints to showing user! Do we need create a client service provider for this porpuse?
we store mountpoint name in server session. (actually we need create mountpoint list in client after user login too).

@miladhashemi
Copy link
Contributor Author

So, to summarize:

  1. Change the Filesystem component in the client to initially store the mountpoint list from config
    Add API method to add to this list
    Add this API method to the VFS service contract
  2. Change the Filesystem component in the server to support RegEx matching on mountpoint names

This wasn't clear to my why i need modify Filesystem component. what is your mean of VFS service contract.
Is it necessary to modify server filesystem when we could add dynamically? Where might it cause a problem when push to mountpoints?

@andersevenrud
Copy link
Member

This wasn't clear to my why i need modify Filesystem component

This was a summary of what would need to be changed in osjs-client with the suggestions I offered. So it would be me that actually does this.

But our new issue is creating client mountpoints to showing user! Do we need create a client service provider for this porpuse?
we store mountpoint name in server session. (actually we need create mountpoint list in client after user login too).

Please use the following issue for client side stuff: os-js/osjs-client#134

In any case, I would recommend creating a service provider for this. Store the data required to set up the mountpoints in the user data, then just use the new methods that will be implemented by os-js/osjs-client#134.

The reason for this is that the VFS is not available before after a user has logged in (this can be customized, but I would not recommend it).

@andersevenrud
Copy link
Member

andersevenrud commented Jan 3, 2021 via email

@miladhashemi
Copy link
Contributor Author

Because you tell me on another issue if your issue solved close issue. I think the problem solved.

fs.mountpoints.push({name: name, adapter: 'monster', id:item, attributes:{}});
I didn't should close an issue when someone self-assigned it..right?

@miladhashemi miladhashemi reopened this Jan 4, 2021
@andersevenrud
Copy link
Member

But I don't think this is solved 😄

There still is no proper way to dynamically add/remove mountpoints on the server.

Pushing into that array is a very brute force way of doing this, and is not guaranteed to work forever of some internal mechanics change slightly.

I wrote here what I feel needs to be done to solve this correctly: #42 (comment)

@andersevenrud
Copy link
Member

I just realized there's a way to dynamically add mountpoints in the server already 😊

// Example using the standard home mountpoint setup
core.make('osjs/fs').mount({
  name: 'example',
  attributes: {
    root: '{vfs}/{username}'
  }
})

I might actually make it so the client also supports using mount() with an object just like the new addMountpoint i made there so that the API signatures are similar.

@andersevenrud
Copy link
Member

If that does not solve your issue, please re-open 😊

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

No branches or pull requests

2 participants