Monday, February 13, 2023

npm ERR! code ENOENT - npm WARN checkPermissions Missing write access

I received the exception below while installing the magnolia CLI npm package from the checked-out code repository(https://github.com/robertkowalski/magnolia-cli.git).

npm install -g

npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\bluebird
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\command-exists
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\commander
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\diff
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\fs-extra
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\findup-sync
npm WARN checkPermissions Missing write access to xxxxt\Magnolia\magnolia-cli\node_modules\i18next
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\i18next-sync-fs-backend
npm WARN checkPermissions Missing write access to xxxxt\Magnolia\magnolia-cli\node_modules\npm-registry-client
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\inquirer
npm WARN checkPermissions Missing write access to xxxxt\Magnolia\magnolia-cli\node_modules\osenv
npm WARN checkPermissions Missing write access to xxxxt\Magnolia\magnolia-cli\node_modules\progress
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\tar
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\yaml-js
npm WARN checkPermissions Missing write access toxxxx\Magnolia\magnolia-cli\node_modules
npm WARN checkPermissions Missing write access to xxxx\Magnolia\magnolia-cli\node_modules\@magnolia
npm ERR! code ENOENT
npm ERR! syscall access
npm ERR! path xxxx\Magnolia\magnolia-cli\node_modules\ansi-escapes
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, access 'xxxx\Magnolia\magnolia-cli\node_modules\ansi-escapes'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xxx\AppData\Roaming\npm-cache\_logs\2023-02-13T18_36_08_935Z-debug.log

This error was due to the magnolia CLI already installed globally through "npm install  @magnolia/cli -g".

Use "npm list @magnolia/cli -g" command to view the existing package; uninstall the existing package through "npm uninstall @magnolia/cli"

Now the local installation(npm install -g) from the checked-out code will be a success.



Thursday, January 26, 2023

Selective Proxying to debug live website issues.


I was recently working on debugging a live website issue; it was only reproducible on the live website, and it was challenging to debug the issue with the live site. Based on my research, I identified selective proxying — modifying the response for the selected URLs and passing the rest of the traffic to the live URL- helping debug live website issues quickly. I want to share some possible tools and configurations that can be used to debug live website issues through selective proxying.

The actual issue was the JavaScript embedded into the HTML page was not working as expected; to debug the problems, the script in the HTML should be modified. Finally, I used the Fiddler Autoresponder to serve only the specific HTML from the Local File and the remaining URLs through live websites. This helps me modify the embed script, identify the root of the problem, and address it.

Fiddler Autoresponder:

The Auto Responder feature in Fiddler Everywhere allows you to create “Rules” triggered when a particular request is issued. Fiddler’s Autoresponder will enable you to return files from your local disk instead of transmitting the request to the server.

The Fiddler can be downloaded from Download Fiddler Web Debugging Tool for Free by Telerik.

Select Autoresponder from Fiddler UI and click Add Rule.

Add the string to match — the URL that should be responded to with local file content.

Select Find File and locate the local File — in my case, I will replace the response for one the HTML — copy the actual HTML response through the view page source in the live URL, store it in the local File, and modify the content as required.

Save and Enable the Rule

Enable the “Decrypt HTTPS Traffic” option if you are debugging HTTPs websites.

Tools → Options → HTTPS

I am selecting No for the root certificate; if the root certificate is not accepted, you will receive an untrusted SSL certificate error while accessing the website — the root certificate can be trusted later if required.

I am enabling the Decrypt only for the browsers.

Click Ok and access the website(page); the specific page will be rendered from a local file — I have enabled a quick alert on the local File.

Now the specific HTML file is loaded locally; all remaining requests are responded to from the live server— including the relative links inside the HTML page loaded from locally.

The SSL certificate error may block some of the externally linked resources from loading; if you want, you can trust the Fiddler root certificate (keep security in mind)

Go to Tools → Option → HTTPS, Click on Actions → Trust Root Certificate.

Follow the screens and Trust the certificate; now, the SSL error will be removed.

You can remove the root certificate if required through Tools →Options → HTTPS →Actions →Reset All Certificates.

The Fiddler is enabled system-wide to capture all the traffic; you can modify the configurations to capture only the specific traffic. Also, you can pause the capturing by unselecting the File →Capture Traffic configuration.

Requestly:

Another option is using the Requestly Desktop app to proxy the response; the Requestly Desktop app can be downloaded from Desktop App to Intercept & Modify HTTP Requests | Requestly

First, open the browser profile (recommend new profile) through the connected app.

Now enable an HTTP Rule.

Select Modify Response Rule

Add the URL for the response that should be replaced — refer to the previous option for replacing HTML with local content.

Place the updated content (in my case, HTML) in the response body.

Provide a Rule name and Save the Rule (Ctrl+S)

Now test the page through the browser session opened by Requestly. For the matching page, the response body is replaced by content specified in the Rule, and the remaining links are directed to the live server.

The Requestly is simple to configure and restricted to a specific browser session, but the Fiddler will give more functionalities like traffic monitoring, SSL support, etc. You can even use other proxies like Charles proxy etc.; consider the security before using any tools for proxying the requests- use the proxies only when you need some debugging.



Friday, November 4, 2022

Git submodules — Merge the content of multiple branches across git repositories at build time.

In some cases, you may have a requirement to deploy the changes to a platform through a single repository/branch, e.g., AEM Cloud manager; AEM cloud manager supports a single repository and a branch to deploy the code changes to a specific environment — the containers are rebuilt on every deployment, so the complete code needs to be deployed on every deployment.

This can create restrictions while multiple teams working on different projects that all need to be deployed into the same platform; one approach is keeping all the project codes in a single repository, and all the teams can work on the same code repository, but sometimes this can lead into conflicts and dependencies between projects team.

Git submodules:

Git submodules can help to handle this scenario; Git submodules allow to merge of the content of multiple branches across repositories at build time. Git submodules help maintain complex projects by allowing independent repositories to exist as subdirectories within a wider project repository.

I have two maven projects in two different repositories; both repositories are enabled with the main branch

https://github.com/techforum-repo/project1.git
https://github.com/techforum-repo/project2.git

I have the main repository — https://github.com/techforum-repo/main-repository.git with the main branch

The below pom.xml enabled in the main-repository

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="
https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>albin</groupId>
<artifactId>main-repository</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>project1</module>
<module>project2</module>
</modules>
</project>

Now add the submodule to the main repository by executing the below command on the main-repository folder

git submodule add -b main https://github.com/techforum-repo/project1.git project1
git submodule add -b main
https://github.com/techforum-repo/project2.git project2

This will generate the .gitmodules file with the below content

[submodule "project1"]
path = project1
url =
https://github.com/techforum-repo/project1.git
branch = main
[submodule "project2"]
path = project2
url =
https://github.com/techforum-repo/project2.git
branch = main

The submodules are checked out under the main repository; now you can commit the submodule changes to the main-repository

git add .
git commit -m "Added the submodule to the project."
git push

Now the submodules are committed to the main-repository

To build the project.

Clone the Main Repository - git clone https://github.com/techforum-repo/main-repository.gitExecute - git submodule init && git submodule update

or

git clone --recurse-submodules https://github.com/techforum-repo/main-repository.git

Now build the main project (add the required parameters) — this will build the Sub Modules projects internally

mvn clean installmvn clean install -PautoInstallPackage -Daem.port=4503

Some of the Useful commands to manage Submodules

Update the Submodules in the main repository - git submodule update --remote
Update Specific Project - git submodule update --remote project2
Verify the status of the submodules - git submodule status
Show commit summary - git submodule summary
Run an arbitrary shell command in each checked-out submodule - git submodule foreache.g git submodule foreach 'echo $sm_path `git rev-parse HEAD`'

One of the concerns here is whenever the files from the Submodules (Project1 or Project2) are modified, the auto build through CI/CD pipeline will not be triggered as the build pipeline is configured to the main repository. The main repository will not be aware of the changes on the submodules.

This can be addressed by updating the submodules in the main repository with every change in the submodules (Project1 or Project2)

Execute the below commands on the main repository whenever there is a change on individual submodules, e.g., Project1, Project2 through a repository or external pipeline.git submodule update --remote
git add .
git commit -m "Sub Module Updated."
git push

To enable this in AEM Cloud Manager, create project-specific repositories in the Cloud Manager Program and create a main repository with the required submodules configurations. Enable the main repository to the pipelines so that all the required submodules will be deployed. You make the same repository structure in your source code management tool and enable the pipelines to sync the repository between your code repositories and Cloud Manager Repositories. Refer to https://betterprogramming.pub/a-bitbucket-ci-cd-pipeline-to-sync-branches-with-github-1c885cefe202 for details on syncing repositories.