Skip to content

feat: allow generator to pull from private npm repo - #1061

Merged
asyncapi-bot merged 69 commits into
asyncapi:masterfrom
AayushSaini101:issue-538
Jan 18, 2024
Merged

asyncapi-bot merged 69 commits into
asyncapi:masterfrom
AayushSaini101:issue-538

Conversation

@AayushSaini101

@AayushSaini101 AayushSaini101 commented Nov 7, 2023 •

Copy link
Copy Markdown
Contributor

Resolves #538
Resolves #1100

Description:

  • Allow the Generator to pull the template from the private repo. [ Check docs/installing-privateTemplate.md]
  • Adding new testing to verify the Generator pulls template from the private Repository.
  • Integrate project tests now run in isolation, each separately
  • Now tests do not make any changes to the file system of the host (entrypoint script) - they run longer but yeah, there is no other way to do it
  • The code of html-template no longer needs to be stored inside the test project
  • Some await/async bugs and removal of redundant promises
  • update arborist to as latest as possible without breaking node 12 support

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

@derberg Hello Sir. I updated the PR according to your instructions. Can you please review :)

@derberg

derberg commented Nov 22, 2023

Copy link
Copy Markdown
Member

sorry, few days delay from my side, not feeling well

@aeworxet fyi ☝🏼

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

sorry, few days delay from my side, not feeling well

@aeworxet fyi ☝🏼

@magicmatatjahu @jonaslagoni Can you please review this

@derberg

derberg commented Dec 12, 2023

Copy link
Copy Markdown
Member

Hey there, sorry a lot for delay.

There are some improvements we need here:

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestions working on them

@derberg I have done some changes how can i test it locally i checked the documentation but cannot able to find the suitable method how to test the changes locally can you tell me some points . So that i can ensure to test before pushing

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

3 New issues 0 Security Hotspots No data about Coverage 0.0% Duplication on New Code

See analysis details on SonarCloud

Working on fix it

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

@derberg Done, Do we need to add documentation in generator or update in AsyncapiDoc

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

Thanks working on fix

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

added few comments

also please see why tests are failing

last but not least please specify how did you test new functionality to make sure it works - like integration test I mean

Comment thread lib/generator.js Resolved
Comment thread docs/template.md Resolved
Comment thread lib/generator.js Resolved
@AayushSaini101

Copy link
Copy Markdown
Contributor Author

added few comments

also please see why tests are failing

last but not least please specify how did you test new functionality to make sure it works - like integration test I mean

Fix Test cases and added new test cases:

image

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

left some comments

I'm wondering how we could test it to make sure private registry works. Setting up automated test will be huge, but maybe we could at least have a short instruction for manual testing whenever we modify this functionality 🤔

so basically:

you know, like developer guide

Comment thread test/generator.test.js Resolved
Comment thread test/generator.test.js Resolved
Comment thread lib/generator.js Resolved
Comment thread lib/generator.js Resolved
Comment thread lib/generator.js Resolved
@AayushSaini101

Copy link
Copy Markdown
Contributor Author

left some comments

I'm wondering how we could test it to make sure private registry works. Setting up automated test will be huge, but maybe we could at least have a short instruction for manual testing whenever we modify this functionality 🤔

so basically:

you know, like developer guide

Added small doc @derberg

@aeworxet

Copy link
Copy Markdown

@asyncapi/bounty_team

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

left some comments
I'm wondering how we could test it to make sure private registry works. Setting up automated test will be huge, but maybe we could at least have a short instruction for manual testing whenever we modify this functionality 🤔
so basically:

you know, like developer guide

Added small doc @derberg

@derberg I used verdaccio to create private repository in the local.

@AayushSaini101

AayushSaini101 commented Dec 21, 2023 •

Copy link
Copy Markdown
Contributor Author

@derberg Can you please check before you go for holidays 🙏🏼

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for not reviewing before holidays, I just had to many topics to close

Comment thread lib/generator.js Resolved
Comment thread docs/installing-privateTemplate.md Outdated

**Step 1:** Settuping Private Repository in Local:

Installing [verdaccio](https://verdaccio.org/) using below command:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was thinking, wouldn't it be better to hide all of this and just extend https://github.com/asyncapi/generator/tree/master/test/test-project that is responsible for testing generator in isolated environment 🤔

If I'm correct you would just have to:

so with above you are getting rid of step 1-4 from this instruction

and to get rid last step:

Thoughts? this way we get one document less to maintain, and out of the box good quality integration test that would work out of the box as we have GitHub Action workflow for it -> https://github.com/asyncapi/generator/blob/master/.github/workflows/pr-testing-with-test-project.yml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was thinking, wouldn't it be better to hide all of this and just extend https://github.com/asyncapi/generator/tree/master/test/test-project that is responsible for testing generator in isolated environment 🤔

If I'm correct you would just have to:

so with above you are getting rid of step 1-4 from this instruction

and to get rid last step:

Thoughts? this way we get one document less to maintain, and out of the box good quality integration test that would work out of the box as we have GitHub Action workflow for it -> https://github.com/asyncapi/generator/blob/master/.github/workflows/pr-testing-with-test-project.yml

@derberg I have tried using docker but we have to manually publish the template the repository, after providing the username and password in config, we have to still login, i have tried https://github.com/verdaccio/verdaccio/tree/master/docker-examples/v4/https-portal-example this example but also we have to manually publish the repo, Event the official video is publishing the repo manually [ We have to manually ]login https://www.youtube.com/watch?v=zRI0skF1f8I&t=234s&ab_channel=Docker
image

  • Also i cannot pass parameters in the cli for login and publishing the repository.
image

I guess existing the small doc is sufficient to help developers

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please push to repo what you have in regards to verdaccio so I can try to help on my side. But first I need to see what configs you already tried

Comment thread lib/generator.js Resolved
Comment thread lib/generator.js Resolved
Comment thread lib/generator.js Resolved
Comment thread lib/generator.js Resolved
@AayushSaini101

Copy link
Copy Markdown
Contributor Author

Please push to repo what you have in regards to verdaccio so I can try to help on my side. But first I need to see what configs you already tried

Sure @derberg

@AayushSaini101

Copy link
Copy Markdown
Contributor Author

Sonar Cloud issue can be avoided because it is suggested to use optional changing that will cause lint issue

Comment thread docs/using-private-template.md Outdated
title: "Using private templates"
weight: 180
---
[Generator](https://www.asyncapi.com/tools/generator) allows to fetch the template from the private repositories like verdaccio, nexus, npm etc. Let's understand how can use the Generator to fetch the templates from the private repositories.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
[Generator](https://www.asyncapi.com/tools/generator) allows to fetch the template from the private repositories like verdaccio, nexus, npm etc. Let's understand how can use the Generator to fetch the templates from the private repositories.
Generator allows to fetch the template from the private repositories like verdaccio, nexus, npm etc.

no need to have one more sentence + link to generator - as long these are generator docs 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done @derberg

Comment thread docs/using-private-template.md Outdated

* **token:** Optional parameter to pass npm registry auth token that you can grab from .npmrc file

## Example to pull Private template:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
## Example to pull Private template:
## Pulling private template using library

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done @derberg

Comment thread docs/using-private-template.md Outdated
Comment on lines +20 to +35
const generator = new Generator('@asyncapi/html-template', outputDir,
{
debug: true,
install: true,
forceWrite: true,
templateParams: {
singleFile: true
},
registry: {
url: 'http://verdaccio:4873',
auth: 'YWRtaW46bmltZGE='
// base64 encoded username and password
// represented as admin:nimda

}
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const generator = new Generator('@asyncapi/html-template', outputDir,
{
debug: true,
install: true,
forceWrite: true,
templateParams: {
singleFile: true
},
registry: {
url: 'http://verdaccio:4873',
auth: 'YWRtaW46bmltZGE='
// base64 encoded username and password
// represented as admin:nimda
}
});
const generator = new Generator('@asyncapi/html-template', 'output',
{
debug: true,
registry: {
url: 'http://verdaccio:4873',
auth: 'YWRtaW46bmltZGE='
// base64 encoded username and password
// represented as admin:nimda
}
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done @derberg

Comment thread docs/using-private-template.md Outdated
}
});
```
Let's suppose the template name as @asyncapi/html-template is present in the private repository, In order to pull the template from the private repository, we need to pass the url and auth as a parameters. No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Let's suppose the template name as @asyncapi/html-template is present in the private repository, In order to pull the template from the private repository, we need to pass the url and auth as a parameters.
Let's assume you host `@asyncapi/html-template` in private package registry like Verdaccio. In order to pull this template you need to provide `registry.url` option that points to the registry URL and `registry.auth` as base64 encoded value that represents username and password. Instead of username and password you can also pass `registry.token`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done @derberg

Comment thread docs/using-private-template.md Outdated
[Generator](https://www.asyncapi.com/tools/generator) allows to fetch the template from the private repositories like verdaccio, nexus, npm etc. Let's understand how can use the Generator to fetch the templates from the private repositories.


## Parameters that needs to pass in Generator to pull private template:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
## Parameters that needs to pass in Generator to pull private template:
## Private registry options

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done @derberg

Comment thread docs/using-private-template.md Outdated
Comment on lines +10 to +15
* **URL:** The URL of the registry where is private template is present.
* **Auth:** Optional parameter to pass npm registry username and password encoded with base64, formatted like username:password value should be encoded.

**For example**: if the username and password is admin and nimda, we need to base64 encoded of admin:nimda.

* **token:** Optional parameter to pass npm registry auth token that you can grab from .npmrc file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* **URL:** The URL of the registry where is private template is present.
* **Auth:** Optional parameter to pass npm registry username and password encoded with base64, formatted like username:password value should be encoded.
**For example**: if the username and password is admin and nimda, we need to base64 encoded of admin:nimda.
* **token:** Optional parameter to pass npm registry auth token that you can grab from .npmrc file
* **registry.url**: The URL of the registry where is private template is present. Defaults to `registry.npmjs.org`
* **registry.auth**: Optional parameter to pass npm registry username and password encoded with base64, formatted like `username:password`. For example if the username and password is `admin` and `nimda`, you need to encode with base64 value like `admin:nimda` which results in `YWRtaW46bmltZGE=`.
* **registry.token** : Optional parameter to pass to npm registry auth token. To get the token you can first authenticate with registry using `npm login` and then grab generated token from `.npmrc` file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done @derberg

derberg
derberg previously approved these changes Jan 17, 2024

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well done 👏🏼
That was a big task, something that I definitely did not expect will be so advanced

but as a result we have lots of bugs solved, much better testing setup and very good reliable integration tests

@derberg

derberg commented Jan 17, 2024

Copy link
Copy Markdown
Member

@Florence-Njeri this PR has some docs, please have a look and approve 🙏🏼

@Florence-Njeri Florence-Njeri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Editorial review

Comment thread docs/using-private-template.md Resolved
Comment thread docs/using-private-template.md Resolved
Comment thread docs/using-private-template.md Resolved
Comment thread docs/using-private-template.md Resolved
Comment thread docs/using-private-template.md Resolved
Comment thread docs/using-private-template.md Resolved
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@derberg

derberg commented Jan 18, 2024

Copy link
Copy Markdown
Member

/rtm

@asyncapi-bot
asyncapi-bot merged commit b5ff633 into asyncapi:master Jan 18, 2024
@asyncapi-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

bounty AsyncAPI Bounty program related label ready-to-merge released

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

Bug: Need to perform exclusive testing in generator Generator doesn't pull template from private repo

6 participants