-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'npm/config' of github.com:open-component-model/ocm into…
… npm/config
- Loading branch information
Showing
33 changed files
with
369 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package npm | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/mandelsoft/filepath/pkg/filepath" | ||
"github.com/mandelsoft/vfs/pkg/osfs" | ||
"github.com/mandelsoft/vfs/pkg/vfs" | ||
|
||
"github.com/open-component-model/ocm/pkg/contexts/config" | ||
credcfg "github.com/open-component-model/ocm/pkg/contexts/credentials/config" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils/defaultconfigregistry" | ||
"github.com/open-component-model/ocm/pkg/errors" | ||
) | ||
|
||
const ( | ||
ConfigFileName = ".npmrc" | ||
) | ||
|
||
func init() { | ||
defaultconfigregistry.RegisterDefaultConfigHandler(DefaultConfigHandler, desc) | ||
} | ||
|
||
func DefaultConfig() (string, error) { | ||
d, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
return filepath.Join(d, ConfigFileName), nil | ||
} | ||
|
||
func DefaultConfigHandler(cfg config.Context) error { | ||
// use docker config as default config for ocm cli | ||
d, err := DefaultConfig() | ||
if err != nil { | ||
return nil | ||
} | ||
if ok, err := vfs.FileExists(osfs.New(), d); ok && err == nil { | ||
ccfg := credcfg.New() | ||
ccfg.AddRepository(NewRepositorySpec(d, true)) | ||
err = cfg.ApplyConfig(ccfg, d) | ||
if err != nil { | ||
return errors.Wrapf(err, "cannot apply npm config %q", d) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
var desc = fmt.Sprintf(` | ||
The npm configuration file at <code>~/%s</code> is | ||
read to feed in the configured credentials for NPM registries. | ||
`, ConfigFileName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.