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

Adding a seed as a library #63

Closed
nawgz opened this issue Mar 11, 2018 · 3 comments
Closed

Adding a seed as a library #63

nawgz opened this issue Mar 11, 2018 · 3 comments

Comments

@nawgz
Copy link
Contributor

nawgz commented Mar 11, 2018

Looking through the documentation, I don't see an easy way to accomplish this.

I have seeds which define the meta-models I wish to use as a library, call them ModelA and ModelB. When creating a new project, I wish for the user to select a project type: ModelA or ModelB, and have this create a new project which has ModelA or ModelB included as a library in the new project, defining the meta in an immutable fashion for the user and allowing for me to update the seeds and use the nice updating features.

Is this the correct way to do this? The other way I would see this being done is by having my seeds actually be an empty project with the library already imported, but managing the library updates in that paradigm seems less intuitive.

If using seeds to import the library is a good way to do it, how can I invoke core.addLibrary or client.addLibrary to do this? From reading thru the webgme repository's code / using the UI, it seems the way this is accomplished is by having the user upload a .webgmex file, parsing that with the BlobClient, and then calling client.addLibrary(namespace, blobArtifact, callback), but this requires the user to have access to the .webgmex file, or sending it over the wire to do them and doing this in the background. Neither of those are ideal. Any thoughts / suggestions?

@nawgz
Copy link
Contributor Author

nawgz commented Mar 12, 2018

Here's how I solved this, for reference:

  1. Make a new RestComponent
  2. At the initialize step for that component, make sure an admin user exists, and make a new BlobClient via
const blobClient;

gmeAuth.generateJWTokenForAuthorizedUser(adminUser.id)
.then((adminToken) => {
  return new BlobClient({
    logger: this.logger,
    httpsecure: false, // must pass so blobClient doesn't use localhost:80
    server: serverUrl, // must pass so blobClient doesn't use localhost:80
    serverPort: serverPort, // must pass so blobClient doesn't use localhost:80
    webgmeToken: adminToken, // must pass so blobClient is authorized
  });
})
  1. Load the seed file via fs.readFile, passing the data buffer to BlobClient.putFile(seedName, dataBuffer)
  2. When creating a new project via the front-end, get the seedHash from the BlobClient via a custom API route /api/seedhash/:seedName which returns the seedHash for the seedName generated from the BlobClient.putFile(seedName, dataBuffer) request
  3. Use the seedHash like client.addLibrary(seedName, seedHash) after calling client.seedProject with EmptyProject

I think the really inelegant part of this was Step 2. It seemed as if I should be able to simply get a reference to that seedHash from a built-in function, for any seed I passed in the webgme config initially. In any case, if you see a better solution to this please let me know.

@pmeijer
Copy link
Contributor

pmeijer commented Mar 12, 2018

An alternatively approach would be to have the seeds contain the meta-models as libraries. (Not sure why that would be less intuitive? If you fork or clone a nodejs repo at github - the dependencies comes with the "seed".) If these are created using a link to an "intra-deployment" project, the soft-link will be preserved in the seed. Whenever there are updates in the linked library an update notification is generated (granted the user has read access to the project) and from the default UI the update can be done with one click.

Regardless, I don't see why we couldn't add this. Can you make an issue for it?

 It seemed as if I should be able to simply get a reference to that seedHash from a built-in function, for any seed I passed in the webgme config initially.

@pmeijer
Copy link
Contributor

pmeijer commented Mar 12, 2018

No need for another issue #64 adds a new rest point and also allows you do pass in a seed name in addLibrary (the actual worker request already supported passing in a name of a seed - but it wasn't exposed on the client api).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants