@@ -46,6 +46,16 @@ they are updated as well.`,
4646 RunE : runPackageFirewallGo ,
4747}
4848
49+ var packageFirewallGoDevCmd = & cobra.Command {
50+ Use : "go-dev" ,
51+ Short : "Configure pkgsite-cli to use Vulnetix Package Firewall" ,
52+ Long : `Configure pkgsite-cli to use the Vulnetix pkg.go.dev API proxy.
53+
54+ This writes Basic auth credentials to netrc for packages.vulnetix.com and prints
55+ the shell alias or function needed to point pkgsite-cli at the firewall.` ,
56+ RunE : runPackageFirewallGoDev ,
57+ }
58+
4959type packageFirewallAction struct {
5060 Target string
5161 Result string
@@ -115,6 +125,64 @@ func runPackageFirewallGo(cmd *cobra.Command, args []string) error {
115125 return nil
116126}
117127
128+ func runPackageFirewallGoDev (cmd * cobra.Command , args []string ) error {
129+ ctx := display .FromCommand (cmd )
130+ t := ctx .Term
131+
132+ proxyURL := strings .TrimSpace (packageFirewallProxyURL )
133+ if proxyURL == "" {
134+ proxyURL = packageFirewallDefaultProxy
135+ }
136+ proxyHost , err := parseProxyHost (proxyURL )
137+ if err != nil {
138+ return err
139+ }
140+ apiURL := strings .TrimRight (proxyURL , "/" ) + "/go-dev/v1beta"
141+
142+ ctx .Logger .Info ("Configuring Vulnetix pkg.go.dev API proxy..." )
143+ orgID , apiKey , credentialSource , err := packageFirewallAPIKey (packageFirewallBaseURL )
144+ if err != nil {
145+ return err
146+ }
147+
148+ var actions []packageFirewallAction
149+ netrcPath , err := auth .NetrcPath ()
150+ if err != nil {
151+ return err
152+ }
153+ result , err := upsertNetrc (netrcPath , proxyHost , orgID , apiKey , packageFirewallDryRun )
154+ if err != nil {
155+ return err
156+ }
157+ actions = append (actions , packageFirewallAction {Target : netrcPath , Result : result })
158+
159+ var b strings.Builder
160+ if packageFirewallDryRun {
161+ b .WriteString (display .Bold (t , "Vulnetix pkg.go.dev API proxy dry run" ) + "\n " )
162+ } else {
163+ b .WriteString (display .Bold (t , "Vulnetix pkg.go.dev API proxy configured" ) + "\n " )
164+ }
165+ b .WriteString (display .KeyValue (t , []display.KVPair {
166+ {Key : "Credential source" , Value : credentialSource },
167+ {Key : "Organization" , Value : orgID },
168+ {Key : "API base URL" , Value : apiURL },
169+ {Key : "API key" , Value : maskSecret (apiKey )},
170+ }) + "\n " )
171+ b .WriteString ("\n " + display .Subheader (t , "Actions" ) + "\n " )
172+ for _ , action := range actions {
173+ b .WriteString (fmt .Sprintf (" %s: %s\n " , action .Target , action .Result ))
174+ }
175+ b .WriteString ("\n " + display .Subheader (t , "pkgsite-cli setup" ) + "\n " )
176+ b .WriteString (" pkgsite-cli does not persist a config file, so use one of the following:\n \n " )
177+ b .WriteString (" Shell alias:\n " )
178+ b .WriteString (fmt .Sprintf (" alias pkgsite-cli='pkgsite-cli -api %s'\n \n " , apiURL ))
179+ b .WriteString (" Or set for a single invocation:\n " )
180+ b .WriteString (fmt .Sprintf (" pkgsite-cli -api %s search uuid\n \n " , apiURL ))
181+ b .WriteString (" Your netrc credentials will be used automatically for Basic auth.\n " )
182+ ctx .Logger .Result (strings .TrimRight (b .String (), "\n " ))
183+ return nil
184+ }
185+
118186func runPackageFirewallEcosystem (cmd * cobra.Command , eco pfw.Ecosystem ) error {
119187 if err := pfw .RequireWriter (eco ); err != nil {
120188 return err
@@ -186,6 +254,26 @@ func runPackageFirewallEcosystem(cmd *cobra.Command, eco pfw.Ecosystem) error {
186254 for _ , action := range actions {
187255 b .WriteString (fmt .Sprintf (" %s: %s\n " , action .Target , action .Result ))
188256 }
257+
258+ if eco .ID == "homebrew" {
259+ b .WriteString ("\n " + display .Subheader (t , "Homebrew setup" ) + "\n " )
260+ b .WriteString (" Homebrew reads these settings from environment variables.\n " )
261+ if packageFirewallDryRun {
262+ b .WriteString (" After running without --dry-run, source the env file:\n " )
263+ } else {
264+ b .WriteString (" Source the env file to activate the firewall:\n " )
265+ }
266+ envFile := ""
267+ for _ , a := range actions {
268+ if strings .HasSuffix (a .Target , "homebrew.env" ) {
269+ envFile = a .Target
270+ break
271+ }
272+ }
273+ b .WriteString (fmt .Sprintf (" source %s\n " , envFile ))
274+ b .WriteString (" Add that line to your shell profile (e.g. ~/.zshrc or ~/.bashrc) to persist it.\n " )
275+ }
276+
189277 ctx .Logger .Result (strings .TrimRight (b .String (), "\n " ))
190278 return nil
191279}
@@ -579,6 +667,8 @@ func maskSecret(s string) string {
579667func init () {
580668 addPackageFirewallFlags (packageFirewallGoCmd , "Go" )
581669 packageFirewallCmd .AddCommand (packageFirewallGoCmd )
670+ addPackageFirewallFlags (packageFirewallGoDevCmd , "Go pkg.go.dev API" )
671+ packageFirewallCmd .AddCommand (packageFirewallGoDevCmd )
582672 for _ , eco := range pfw .All () {
583673 if eco .Command == "go" {
584674 continue
0 commit comments