npm publish to Artifactory results in Failed PUT 302 - node.js

When I try to npm publish to a private npm repository on Artifactory I get a Failed PUT 302 error. I followed the directions in their video(https://www.youtube.com/watch?v=gyQ0riy3Hk8) and set up a remote repository that points to registry.npmjs.org, another that is the private repo(npm-local), and a virtual repo that aggregates the remote and private repos.
I set up my ~/.npmrc file to use the Artifactory virtual repo and added my credentials. I am able to install public packages fine using this setup. But when I try to publish directly to /npm-local I always get Failed PUT 302 - the repository responds with a generic nginx 302 Found page and npm can't parse the html.
Currently I am using npm#2.13.3 but I even tried reverting back to 1.4.x after reading npm publish to Artifactory not working and had the same issue.
Also I have tried publishing a directory with package.json in it and a tarball - both produce the same 302 error.

After several emails and a phone call I found the fix:
login to artifactoryonline
Goto Admin Tab
Under general settings set the Custom URL Base to: https://YOUR_ACCOUNT_NAME.artifactoryonline.com/YOUR_ACCOUNT_NAME
They said that they are working on having this set for you by default but until then you have to set it manually. Unfortunately it is not documented anywhere and not mentioned in any of the videos that I saw.

NPM v6 is not able to handle the HTTP Status 302. It process this code as successful printing PUT 302 into verbose output. It happens for example, if the Artifactory server expects the connection over https and redirects all the requests from port 80 to 443. NPM v8 handles redirects correctly.

Related

Problems downloading packages using "ptxdist get"

I'm trying to compile Linux for an embedded system. I'm using ptxdist command to build the system.
My colleague told me to use ptxdist get so we can get all dependencies downloaded before we start compiling.
We also sit behind a proxy and my /etc/environment is configured with the http/https/ftp proxy (same IP and port for all), as well as apt (meaning that wget works fine without extra parameters)
PROBLEM:
Running ptxdist get will download some of the packages, others it will just not download and the following error appears (example for 2 packages):
Here is an example when it worked fine:
---------------------------
target: cmake-3.13.4.tar.gz
---------------------------
--2019-07-23 20:54:28-- https://cmake.org/files/v3.13/cmake-3.13.4.tar.gz
Connecting to <PROXY IP HERE>:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: 8617881 (8.2M) [application/x-gzip]
Saving to: '/home/xxxxxxx/xxxxxxx/xxxxxxx/src/cmake-3.13.4.tar.gz.RSjrC7k7mC'
/home/xxxxxxx/x 100%[===================>] 8.22M 2.00MB/s in 4.7s
2019-07-23 20:54:34 (1.75 MB/s) - '/home/xxxxxxx/xxxxxxx/xxxxxxx/src/cmake-3.13.4.tar.gz.RSjrC7k7mC' saved [8617881/8617881]
And here an example when it failed:
-----------------------
target: lzo-2.08.tar.gz
-----------------------
--2019-07-23 20:55:13-- http://www.oberhumer.com/opensource/lzo/download/lzo-2.08.tar.gz
Connecting to <PROXY IP HERE>:8080... connected.
Proxy request sent, awaiting response... 502 Proxy Error ( The specified network name is no longer available. )
2019-07-23 20:55:13 ERROR 502: Proxy Error ( The specified network name is no longer available. ).
--2019-07-23 20:55:13-- http://www.pengutronix.de/software/ptxdist/temporary-src/lzo-2.08.tar.gz
Connecting to <PROXY IP HERE>:8080... connected.
Proxy request sent, awaiting response... 502 Proxy Error ( The specified network name is no longer available. )
2019-07-23 20:55:13 ERROR 502: Proxy Error ( The specified network name is no longer available. ).
make: *** [/home/xxxxxxxx/xxxxxxx/xxxxxxx/src/lzo-2.08.tar.gz] Error 1
Could not download package
URL: http://www.oberhumer.com/opensource/lzo/download/lzo-2.08.tar.gz
/usr/local/lib/ptxdist-2019.03.1/rules/post/ptxd_make_world_get.make:17: recipe for target '/home/xxxxxxx/xxxxxxx/xxxxxxx/src/lzo-2.08.tar.gz' failed
Even if I repeat ptxdist get, it stops at the same exact package that fails.
BUT:
If I just use
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.08.tar.gz
it downloads the file just fine, same happens to ANY other package that fails, using the URL that shows up above.
When I run ptxdist get then it moves on to other downloads as it sees the file already there, and then hangs on the next download that failes.
ALSO TRIED:
I also tried to run ptxdist setup and configure the proxy there. Nothing changes in the terminal, so no luck...
ALSO TRIED:
I also wrote a script that takes package names using ptxdist print PACKAGES, then gets the URL using ptxdist package-info <PKG> then downloads the file via wget <URL>, this solved most part of the errors while running ptxdist get as wget works fine, but it seems that there are many other packages that are needed and not listed with ptxdist print PACKAGES...
Any idea what is wrong and what can I do?
Since I'm supposed to automate this task, there is no way manual interaction (for using wget on failing packages) is an option...

Jenkins Error 128 / Git Error 403: Jenkins can't connect to my Bitbucket repository

OS: Ubuntu 16.04
Hypervisor: VirtualBox
Network configuration: Nat Network with port forwarding to access the vms through the host ip. I can also ping a VM from another VM.
I try to connect my Jenkins app hosted on a VM to my BitBucket server also on a VM. I followed a tutorial on internet but when i enter the address of my git repository i'm getting this:
Failed to connect to repository : Command "usr/bin/git ls-remote -h http://admin#192.168.6.102:8005/scm/tes/repository-test.git HEAD" returned status code 128:
stdout:
stderr: fatal: unable to access 'http://admin#192.168.6.102:8005/scm/tes/repository-test.git/': The requested URL returned error: 403
So, to be sure I tried to exectute the command on the terminal... and on the terminal it seems to work.. I can also push, clone, pull etc..
On this image you can see that it's true
Do you have an explanation?
EDIT:
I try some others things like use or not sudo to see if the permissions problem came from that and it seems that it's not the case.
But I see that there is no result when we use the "HEAD" argument.
Do you think that because "HEAD" give no result, git in jenkins interprets it like no answer and returns the damn** error 403?
EDIT 2:
I found that on the web: http: // jenkins-ci.361315.n4.nabble.com/Jenkins-GIT-ls-remote-error-td4646903.html
The guy has the same problem but in a different way, I will try to allocate more RAM to see if it does the trick.
There could be many possible problems, but you are getting 403 - Access Forbidden, which indicates some problem with permissions. I would suggest first common mistakes:
a) trying https instead http - my scm only uses https,
b) check if admin is correct - scm by default uses scmadmin.
Here I run the exact same command twice.
The first time I used the proxy configuration wich I need to access internet, and the second time I set the mandatory server on "none".
So there is a problem with the damn proxy.
I was thinking that the proxy was not used in NAT connection with VirtualBox...
I found the solution.
I had to reinstall jenkins to have a user named "jenkins" with his own home directory.
I don't know if it is linked or not, but I configured my bitbucket server to use only HTTPS with a self signed certificate (I work in lan)
My troubleshoot was linked with my proxy settings.
I disabled all my proxy settings in Linux so I was able to launch the command that did'nt worked in jenkins with terminal.
I logged with sudo su jenkins the commands also worked.
I found out that in the home directory of the jenkins user there was a "proxy.xml" file. I opened it and saw my old proxy settings.
I deleted all the content with vim, saved and restarted and the error was gone.
there can be git version miss match.....
I would suggest you update git once. maybe it will resolve your issues.

Installing scoped npm packages from Artifactory

I am trying to get scoped npm packages to work with Artifactory behind Apache. I can publish a scoped package to Artifactory and it creates the following path in the npm-local repo: #scopename/packagename/-/#scopename/packagename-version.tgz
My problems arise trying to install this package. I get a 404 Not Found: #scopename/packagename. Looking at the debug log I can see that maybe it has something to do with the encoding of the slashes:
22 http request GET https://artifacts.company.com/artifactory/api/npm/npm-local/#scopename%2fpackagename
23 http 404 https://artifacts.company.com/artifactory/api/npm/npm-local/#scopename%2fpackagename
I have followed the online documentation. I added AllowEncodedSlashes NoDecode to the virtual host and org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true to the catalina.properties file on tomcat.
Am I missing something?
This looks like a reverse proxy issue. Check your request.log. If the request is coming is as /api/npm/npm-group/#angular/core instead of /api/npm/npm-group/#angular%2Fcore, that is something that need to addressed in your reverse proxy.
You have to change two things:
Implement the setting org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH = true
Remove of the context root from the proxy_pass variable in /etc/nginx/conf.d/default.conf

How can I diagnose why `npm publish` quietly does... nothing?

I've created a npm package following several different sets of instructions online. Here is what I have: https://github.com/joelarson4/CharFunk/blob/master/package.json
When I do an npm publish, I get a single newline of output (no errors, no anything). But from what I can tell, my package is not on npmjs.org. https://www.npmjs.org/package/CharFunk is an error page.
How can I figure out what I'm missing?
You solved your problem, but for others; You might see more information with:
npm publish --verbose
You might have loglevel set to silent. Try doing
npm config set loglevel verbose --global
and then rerunning your npm commands to see if that gives more useful detail.
If not, try editing ~/.npmrc and setting
loglevel verbose
The extra information provided should help clarify the problem.
I did have similar problem working with our local Nexus server.
NPM v6 is not able to handle the HTTP Status 302. It understands this code as success printing npm http fetch PUT 302 into verbose output. It happened in my case, as the Nexus server expected the connection over https and the firewall redirected all the requests from port 80 to 443.
To fix it, I changed the publishConfig in the package.json referencing the Nexus server over https.
"publishConfig": {
"registry": "https://nexus.example.com/repository/npm-private/"
},
NPM v8 handles redirects correctly and doesn't need this fix.

Accessing NPM repository through a proxy

I'm trying to access the npm repository from an intranet using a proxy.
Using the proxy (set in the environment variables HTTP_Proxy and HTTPS_Proxy) I'm able to access the repository without ssl using my browser, and using wget:
wget registry.npmjs.org/yuidocjs
When I use https, I can access with my browser, but not with wget
wget https://registry.npm.js.org/yuidocjs #fails
When I try to use NPM, setting registry=http://registry.npm.js.org/ results in a 404.
When I use the default https registry path, it results in a timeout.
Anything I'm missing here? My config file looks like this:
proxy = http://ems-lnx222:8080/proxy.pac
https-proxy = http://ems-lnx222:8080/proxy.pac
registry = http://registry.npmjs.org/
prefix = /ws/bemccorm-rtp/npm-packages
strict-ssl = false
Update
After some more playing I figured out that the .pac proxies seemed to be causing a problem.
I used a normal proxy instead, and now get a 200 status, GET the correct tgz file, and then receive an npm ERR! fetch failed when trying to fetch the file.
I am sure it was a typo but just to make it more clear for debugging.
When I use https, I can access with my browser, but not with wget
wget https://registry.npm.js.org/yuidocjs #fails
The domain was wrong... npm.JS instead of npmjs...
Going further with wget
wget https://registry.npmjs.org/yuidocjs
--2013-07-09 15:57:25-- https://registry.npmjs.org/yuidocjs
Resolving registry.npmjs.org (registry.npmjs.org)... 67.228.31.146
Connecting to registry.npmjs.org (registry.npmjs.org)|67.228.31.146|:443... connected.
ERROR: cannot verify registry.npmjs.org’s certificate, issued by “/C=US/ST=CA/L=Oakland/O=npm/OU=npm Certificate Authority/CN=npmCA/emailAddress=i#izs.me”:
Unable to locally verify the issuer’s authority.
To connect to registry.npmjs.org insecurely, use ‘--no-check-certificate’.
If you use --no-check-certificate it works and download.
But we know this is not your MAIN problem your Main problem is the .PAC files.
I worked as a sysadmin and several times we have to write different rules at .pac files as:
1) If it is internal send everything to this router
2) If connected by vpn network do this
3) etc
So Please do a get and transcribe the .pac files so we can see the rules.
The .pac files is nothing more than javascript.
Regards
Repocache worked for this.
npm config set registry https://127.0.0.1:5000/npm/default/
npm install color
Startup repocache with setting below:
[npm.upstream.default]
url = https://registry.npmjs.org
If proxy is need, add proxy like:
http = http://127.0.0.1:1087
https = socks5://127.0.0.1:1086

Resources