Skip to content

Commit 5d111f2

Browse files
committed
printlns
1 parent 27a7d20 commit 5d111f2

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

go.mod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ replace github.com/gliderlabs/ssh => github.com/coder/ssh v0.0.0-20230621095435-
88

99
require (
1010
cdr.dev/slog v1.6.2-0.20230929193652-f0c466fabe10
11-
github.com/coder/coder/v2 v2.6.1-0.20240124004842-3c9f7e892945
11+
github.com/coder/coder/v2 v2.6.1-0.20240125021520-d9f5cdda9bae
1212
github.com/google/go-containerregistry v0.14.0
1313
github.com/jfrog/jfrog-client-go v1.31.6
1414
github.com/spf13/cobra v1.8.0
@@ -54,10 +54,12 @@ require (
5454
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.1 // indirect
5555
github.com/aws/aws-sdk-go-v2/service/sts v1.21.1 // indirect
5656
github.com/aws/smithy-go v1.19.0 // indirect
57+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
5758
github.com/benbjohnson/clock v1.3.5 // indirect
5859
github.com/beorn7/perks v1.0.1 // indirect
5960
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
6061
github.com/cespare/xxhash/v2 v2.2.0 // indirect
62+
github.com/charmbracelet/lipgloss v0.8.0 // indirect
6163
github.com/cloudflare/circl v1.3.7 // indirect
6264
github.com/coder/retry v1.5.1 // indirect
6365
github.com/coder/terraform-provider-coder v0.13.0 // indirect
@@ -112,6 +114,7 @@ require (
112114
github.com/hashicorp/yamux v0.1.1 // indirect
113115
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
114116
github.com/illarion/gonotify v1.0.1 // indirect
117+
github.com/imdario/mergo v0.3.15 // indirect
115118
github.com/inconshreveable/mousetrap v1.1.0 // indirect
116119
github.com/insomniacslk/dhcp v0.0.0-20231206064809-8c70d406f6d2 // indirect
117120
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
@@ -127,9 +130,11 @@ require (
127130
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
128131
github.com/klauspost/pgzip v1.2.5 // indirect
129132
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
133+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
130134
github.com/mailru/easyjson v0.7.7 // indirect
131135
github.com/mattn/go-colorable v0.1.13 // indirect
132136
github.com/mattn/go-isatty v0.0.20 // indirect
137+
github.com/mattn/go-runewidth v0.0.15 // indirect
133138
github.com/mdlayher/genetlink v1.3.2 // indirect
134139
github.com/mdlayher/netlink v1.7.2 // indirect
135140
github.com/mdlayher/sdnotify v1.0.0 // indirect
@@ -145,6 +150,8 @@ require (
145150
github.com/mitchellh/reflectwalk v1.0.2 // indirect
146151
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
147152
github.com/modern-go/reflect2 v1.0.2 // indirect
153+
github.com/muesli/reflow v0.3.0 // indirect
154+
github.com/muesli/termenv v0.15.2 // indirect
148155
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
149156
github.com/nwaples/rardecode v1.1.0 // indirect
150157
github.com/opencontainers/go-digest v1.0.0 // indirect

go.sum

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ github.com/cilium/ebpf v0.11.0/go.mod h1:WE7CZAnqOL2RouJ4f1uyNhqr2P4CCvXFIqdRDUg
146146
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
147147
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
148148
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
149-
github.com/coder/coder/v2 v2.6.1-0.20240124004842-3c9f7e892945 h1:xFhm+pRkoAbWNrDxHybdca9V2XhMtloIhsgtTSWEiko=
150-
github.com/coder/coder/v2 v2.6.1-0.20240124004842-3c9f7e892945/go.mod h1:jSDTCnwDgcqPUcP17SJsDs/HW18pfQj4WEE3AAE+8o4=
149+
github.com/coder/coder/v2 v2.6.1-0.20240125021520-d9f5cdda9bae h1:k3mhC2/RtoVon6NCljR9wY6u322Zib1CnNZ9GMyQZCk=
150+
github.com/coder/coder/v2 v2.6.1-0.20240125021520-d9f5cdda9bae/go.mod h1:jSDTCnwDgcqPUcP17SJsDs/HW18pfQj4WEE3AAE+8o4=
151151
github.com/coder/retry v1.5.1 h1:iWu8YnD8YqHs3XwqrqsjoBTAVqT9ml6z9ViJ2wlMiqc=
152152
github.com/coder/retry v1.5.1/go.mod h1:blHMk9vs6LkoRT9ZHyuZo360cufXEhrxqvEzeMtRGoY=
153153
github.com/coder/ssh v0.0.0-20230621095435-9a7e23486f1c h1:TI7TzdFI0UvQmwgyQhtI1HeyYNRxAQpr8Tw/rjT8VSA=
@@ -492,6 +492,7 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
492492
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
493493
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
494494
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
495+
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
495496
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
496497
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
497498
github.com/mdlayher/genetlink v1.3.2 h1:KdrNKe+CTu+IbZnm/GVUMXSqBBLqcGpRDa0xkQy56gw=
@@ -600,6 +601,8 @@ github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5X
600601
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
601602
github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052 h1:Qp27Idfgi6ACvFQat5+VJvlYToylpM/hcyLBI3WaKPA=
602603
github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052/go.mod h1:uvX/8buq8uVeiZiFht+0lqSLBHF+uGV8BrTv8W/SIwk=
604+
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
605+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
603606
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
604607
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
605608
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=

jfrog/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func ParseImage(image string) (Image, error) {
115115

116116
func root(path string) string {
117117
dir := filepath.Dir(path)
118-
if dir == path {
118+
if dir == "." {
119119
return path
120120
}
121121
return root(dir)

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package main
22

3-
func main() {
3+
import (
4+
"os"
5+
)
46

7+
func main() {
8+
err := root().Execute()
9+
if err != nil {
10+
os.Exit(1)
11+
}
512
}

root.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ import (
1010
"k8s.io/client-go/kubernetes"
1111
"k8s.io/client-go/tools/clientcmd"
1212

13+
"cdr.dev/slog"
14+
"cdr.dev/slog/sloggers/sloghuman"
15+
1316
"github.com/coder/xray/jfrog"
17+
reporter "github.com/coder/xray/k8s"
1418
)
1519

1620
func root() *cobra.Command {
1721
var (
1822
coderURL string
23+
coderToken string
1924
artifactoryURL string
2025
artifactoryUser string
2126
artifactoryToken string
@@ -64,22 +69,41 @@ func root() *cobra.Command {
6469
return xerrors.Errorf("create kubernetes config: %w", err)
6570
}
6671

67-
jClient, err := jfrog.XRayClient(artifactoryURL, artifactoryUser, artifactoryToken)
72+
jclient, err := jfrog.XRayClient(artifactoryURL, artifactoryUser, artifactoryToken)
6873
if err != nil {
6974
return xerrors.Errorf("create artifactory client: %w", err)
7075
}
7176

77+
kr := reporter.K8sReporter{
78+
Client: kclient,
79+
JFrogClient: jclient,
80+
Namespace: namespace,
81+
CoderURL: coderParsed,
82+
Logger: slog.Make(sloghuman.Sink(cmd.ErrOrStderr())),
83+
CoderToken: coderToken,
84+
}
85+
86+
err = kr.Init(cmd.Context())
87+
if err != nil {
88+
return xerrors.Errorf("initialize reporter: %w", err)
89+
}
90+
91+
stopCh := make(chan struct{})
92+
defer close(stopCh)
93+
go kr.Start(stopCh)
94+
<-cmd.Context().Done()
95+
7296
return nil
7397
},
7498
}
75-
cmd.Flags().StringVarP(&coderURL, "coder-url", "cu", os.Getenv("CODER_URL"), "URL of the Coder instance")
99+
cmd.Flags().StringVarP(&coderURL, "coder-url", "", os.Getenv("CODER_URL"), "URL of the Coder instance")
100+
cmd.Flags().StringVarP(&coderToken, "coder-token", "", os.Getenv("CODER_TOKEN"), "Access Token for the Coder instance. Requires Template Admin privileges.")
76101
cmd.Flags().StringVarP(&artifactoryURL, "artifactory-url", "", os.Getenv("ARTIFACTORY_URL"), "URL of the JFrog Artifactory instance")
77102
cmd.Flags().StringVarP(&artifactoryToken, "artifactory-token", "", os.Getenv("ARTIFACTORY_TOKEN"), "Access Token for JFrog Artifactory instance")
78103
cmd.Flags().StringVarP(&artifactoryUser, "artifactory-user", "", os.Getenv("ARTIFACTORY_USER"), "User to interface with JFrog Artifactory instance")
79-
cmd.Flags().StringVarP(&kubeConfig, "kubeconfig", "k", "~/.kube/config", "Path to the kubeconfig file")
104+
cmd.Flags().StringVarP(&kubeConfig, "kubeconfig", "k", "/home/coder/.kube/config", "Path to the kubeconfig file")
80105
cmd.Flags().StringVarP(&namespace, "namespace", "n", os.Getenv("CODER_NAMESPACE"), "Namespace to use when listing pods")
81106
cmd.Flags().StringVarP(&fieldSelector, "field-selector", "f", "", "Field selector to use when listing pods")
82107
cmd.Flags().StringVarP(&labelSelector, "label-selector", "l", "", "Label selector to use when listing pods")
83-
cmd.Flags().StringVarP(&artifactoryToken, "artifactory-token", "", "", "Token to use to fetch scan results for an image")
84108
return cmd
85109
}

0 commit comments

Comments
 (0)