From 9a336a4c68d1d1fe9156fd718ce410c204115449 Mon Sep 17 00:00:00 2001 From: abdelDriowya Date: Tue, 6 Dec 2022 09:57:06 +0100 Subject: [PATCH 01/11] move ownership to devex team --- .github/CODEOWNERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 138eb5b32..5d57cd581 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1,5 @@ -* @CircleCI-Public/Extensibility -*orb*.go @CircleCI-Public/CPEng @CircleCI-Public/Extensibility +* @CircleCI-Public/developer-experience +*orb*.go @CircleCI-Public/CPEng @CircleCI-Public/developer-experience /api/runner @CircleCI-Public/runner /cmd/runner @CircleCI-Public/runner From a8d8a2edd7304034adaca7a380060864ceab3e9d Mon Sep 17 00:00:00 2001 From: rlegan Date: Tue, 24 Jan 2023 11:27:25 +0100 Subject: [PATCH 02/11] fix: make sure we're using token in every graphql request --- api/api.go | 9 +++++---- cmd/config_test.go | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/api.go b/api/api.go index a88272e85..75fd208a9 100644 --- a/api/api.go +++ b/api/api.go @@ -543,6 +543,7 @@ func ConfigQueryLegacy(cl *graphql.Client, configPath string, orgSlug string, pa fieldAddendums) request := graphql.NewRequest(query) + request.SetToken(cl.Token) request.Var("config", config) if values != nil { @@ -560,8 +561,6 @@ func ConfigQueryLegacy(cl *graphql.Client, configPath string, orgSlug string, pa request.Var("orgSlug", orgSlug) } - request.SetToken(cl.Token) - err = cl.Run(request, &response) if err != nil { return nil, errors.Wrap(err, "Unable to validate config") @@ -603,6 +602,7 @@ func ConfigQuery(cl *graphql.Client, configPath string, orgId string, params pip fieldAddendums) request := graphql.NewRequest(query) + request.SetToken(cl.Token) request.Var("config", config) if values != nil { @@ -619,7 +619,6 @@ func ConfigQuery(cl *graphql.Client, configPath string, orgId string, params pip if orgId != "" { request.Var("orgId", orgId) } - request.SetToken(cl.Token) err = cl.Run(request, &response) if err != nil { @@ -1634,6 +1633,7 @@ query namespaceOrbs ($namespace: String, $after: String!) { for { request := graphql.NewRequest(query) + request.SetToken(cl.Token) request.Var("after", currentCursor) request.Var("namespace", namespace) @@ -1813,7 +1813,7 @@ func OrbCategoryID(cl *graphql.Client, name string) (*OrbCategoryIDResponse, err }` request := graphql.NewRequest(query) - + request.SetToken(cl.Token) request.Var("name", name) err := cl.Run(request, &response) @@ -1917,6 +1917,7 @@ func ListOrbCategories(cl *graphql.Client) (*OrbCategoriesForListing, error) { for { request := graphql.NewRequest(query) + request.SetToken(cl.Token) request.Var("after", currentCursor) err := cl.Run(request, &result) diff --git a/cmd/config_test.go b/cmd/config_test.go index e03177f8d..85b6e8632 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -176,6 +176,7 @@ var _ = Describe("Config", func() { }` r := graphql.NewRequest(query) + r.SetToken(token) r.Variables["config"] = config r.Variables["pipelineValues"] = pipeline.PrepareForGraphQL(pipeline.LocalPipelineValues()) @@ -253,6 +254,7 @@ var _ = Describe("Config", func() { }` r := graphql.NewRequest(query) + r.SetToken(token) r.Variables["config"] = config r.Variables["pipelineValues"] = pipeline.PrepareForGraphQL(pipeline.LocalPipelineValues()) @@ -317,6 +319,7 @@ var _ = Describe("Config", func() { }` r := graphql.NewRequest(query) + r.SetToken(token) r.Variables["config"] = config r.Variables["orgId"] = orgId r.Variables["pipelineValues"] = pipeline.PrepareForGraphQL(pipeline.LocalPipelineValues()) @@ -379,6 +382,7 @@ var _ = Describe("Config", func() { }` r := graphql.NewRequest(query) + r.SetToken(token) r.Variables["config"] = config r.Variables["orgSlug"] = orgSlug r.Variables["pipelineValues"] = pipeline.PrepareForGraphQL(pipeline.LocalPipelineValues()) From 2fea0c67bcef33317703db61ec0ffa421f75cb5b Mon Sep 17 00:00:00 2001 From: Sujeet Kumar Date: Wed, 25 Jan 2023 21:03:32 -0500 Subject: [PATCH 03/11] update circle-policy-agent to v0.0.457 - pretty-print etal --- go.mod | 20 ++++++++++---------- go.sum | 52 +++++++++++++++++++++++++++------------------------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index 02bcf8e65..1114a1afc 100644 --- a/go.mod +++ b/go.mod @@ -2,18 +2,18 @@ module github.com/CircleCI-Public/circleci-cli require ( github.com/AlecAivazis/survey/v2 v2.1.1 - github.com/CircleCI-Public/circle-policy-agent v0.0.383 + github.com/CircleCI-Public/circle-policy-agent v0.0.457 github.com/Masterminds/semver v1.4.2 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/blang/semver v3.5.1+incompatible github.com/briandowns/spinner v1.18.1 - github.com/fatih/color v1.9.0 + github.com/fatih/color v1.13.0 github.com/go-git/go-git/v5 v5.1.0 github.com/google/go-github v15.0.0+incompatible // indirect github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect github.com/google/uuid v1.3.0 github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect github.com/mitchellh/mapstructure v1.4.1 github.com/olekukonko/tablewriter v0.0.5 github.com/onsi/ginkgo v1.16.4 @@ -35,7 +35,7 @@ require ( github.com/charmbracelet/lipgloss v0.5.0 github.com/erikgeiser/promptkit v0.7.0 github.com/hexops/gotextdiff v1.0.3 - golang.org/x/exp v0.0.0-20221114191408-850992195362 + golang.org/x/exp v0.0.0-20230118134722-a68e582fa157 ) require ( @@ -60,7 +60,7 @@ require ( github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/mattn/go-colorable v0.1.4 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mb0/diff v0.0.0-20131118162322-d8d9a906c24d // indirect github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect @@ -70,7 +70,7 @@ require ( github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.12.0 // indirect github.com/nxadm/tail v1.4.8 // indirect - github.com/open-policy-agent/opa v0.47.3 // indirect + github.com/open-policy-agent/opa v0.48.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect @@ -82,10 +82,10 @@ require ( github.com/yashtewari/glob-intersection v0.1.0 // indirect github.com/yazgazan/jaydiff v0.3.1 // indirect golang.org/x/crypto v0.3.0 // indirect - golang.org/x/net v0.4.0 // indirect - golang.org/x/sys v0.3.0 // indirect - golang.org/x/term v0.3.0 // indirect - golang.org/x/text v0.5.0 // indirect + golang.org/x/net v0.5.0 // indirect + golang.org/x/sys v0.4.0 // indirect + golang.org/x/term v0.4.0 // indirect + golang.org/x/text v0.6.0 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect diff --git a/go.sum b/go.sum index 2266e2ee9..45bf0f77d 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ github.com/AlecAivazis/survey/v2 v2.1.1 h1:LEMbHE0pLj75faaVEKClEX1TM4AJmmnOh9eim github.com/AlecAivazis/survey/v2 v2.1.1/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/CircleCI-Public/circle-policy-agent v0.0.383 h1:lgnCkN7GN1oFq9LtE3mY3fP8kkHkJXjC5eaFBbOuDzM= -github.com/CircleCI-Public/circle-policy-agent v0.0.383/go.mod h1:8tm87Gw46Jht5JNcvAaspjZt18fRvDkyL0/WRU41l0A= +github.com/CircleCI-Public/circle-policy-agent v0.0.457 h1:dsNC6/uo5Fk2Ji7wYAQ+H4ZOMVXhYxH3tDKFJ3Zazog= +github.com/CircleCI-Public/circle-policy-agent v0.0.457/go.mod h1:lsP7UOPtBj0+IYFdL46vdoPaPJitURRvhmhiE4uRpeg= github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= @@ -85,7 +85,7 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgraph-io/badger/v3 v3.2103.4 h1:WE1B07YNTTJTtG9xjBcSW2wn0RJLyiV99h959RKZqM4= +github.com/dgraph-io/badger/v3 v3.2103.5 h1:ylPa6qzbjYRQMU6jokoj4wzcaweHylt//CH0AKt0akg= github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= @@ -99,8 +99,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/erikgeiser/promptkit v0.7.0 h1:Yi28iN6JRs8/0x+wjQRPfWb+vWz1pFmZ5fu2uoFipD8= github.com/erikgeiser/promptkit v0.7.0/go.mod h1:Jj9bhN+N8RbMjB1jthkr9A4ydmczZ1WZJ8xTXnP12dg= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= -github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/foxcpp/go-mockdns v0.0.0-20210729171921-fb145fc6f897 h1:E52jfcE64UG42SwLmrW0QByONfGynWuzBvm86BoB9z8= @@ -214,7 +214,7 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:C github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY= github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= +github.com/klauspost/compress v1.15.14 h1:i7WCKDToww0wA+9qrUZ1xOjp218vfFo3nTU6UHp+gOc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -228,20 +228,22 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69 github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= +github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/mb0/diff v0.0.0-20131118162322-d8d9a906c24d h1:eAS2t2Vy+6psf9LZ4T5WXWsbkBt3Tu5PWekJy5AGyEU= github.com/mb0/diff v0.0.0-20131118162322-d8d9a906c24d/go.mod h1:3YMHqrw2Qu3Liy82v4QdAG17e9k91HZ7w3hqlpWqhDo= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= @@ -277,8 +279,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= -github.com/open-policy-agent/opa v0.47.3 h1:Uj8zw+q6Cvv1iiQFh704Q6sl3fKVvk35WZNJLsd6mgk= -github.com/open-policy-agent/opa v0.47.3/go.mod h1:I5DbT677OGqfk9gvu5i54oIt0rrVf4B5pedpqDquAXo= +github.com/open-policy-agent/opa v0.48.0 h1:s2K823yohAUu/HB4MOPWDhBh88JMKQv7uTr6S89fbM0= +github.com/open-policy-agent/opa v0.48.0/go.mod h1:CsQcksP+qGBxO9oEBj1NnZqKcjgjmTJbRNTzjZB/DXQ= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -343,7 +345,7 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= +go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -365,8 +367,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20221114191408-850992195362 h1:NoHlPRbyl1VFI6FjwHtPQCN7wAMXI6cKcqrmXhOOfBQ= -golang.org/x/exp v0.0.0-20221114191408-850992195362/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230118134722-a68e582fa157 h1:fiNkyhJPUvxbRPbCqY/D9qdjmPzfHcpK3P4bM4gioSY= +golang.org/x/exp v0.0.0-20230118134722-a68e582fa157/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -417,8 +419,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= -golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -452,11 +454,11 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -481,21 +483,21 @@ golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= -golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= +golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg= +golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= -golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 05d4308638b889499e635c547530aa8bfdb58792 Mon Sep 17 00:00:00 2001 From: Sujeet Kumar Date: Fri, 27 Jan 2023 11:10:31 -0500 Subject: [PATCH 04/11] trigger CI From 7f5868fba92a7ecac6fc949fa28d69d4eb81f42f Mon Sep 17 00:00:00 2001 From: Sujeet Kumar Date: Wed, 1 Feb 2023 13:24:47 -0500 Subject: [PATCH 05/11] trigger CI2 From b6e1c9ab65e96c310424036f8131619832327ffe Mon Sep 17 00:00:00 2001 From: Sujeet Kumar Date: Wed, 1 Feb 2023 13:27:09 -0500 Subject: [PATCH 06/11] trigger CI3 From 7c17232f84a1497aca6320e5f8fa4dd8b2d30592 Mon Sep 17 00:00:00 2001 From: rlegan Date: Wed, 1 Feb 2023 17:33:38 +0100 Subject: [PATCH 07/11] doc: Added doc about checksum verification --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index a90c85c92..3f9fdb9e4 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,22 @@ You can also set a specific version of the CLI to install with the `VERSION` env curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/main/install.sh | VERSION=0.1.5222 sudo bash ``` +#### Checksum verification + +If you would like to verify the checksum yourself, you can download the checksum file from the [GitHub releases page](https://github.com/CircleCI-Public/circleci-cli/releases) and verify the checksum of the archive using the `circleci-cli__checksums.txt` inside the assets of the release you'd like to install: + +On macOS and Linux: +```sh +shasum -a 256 circleci-cli__.tar.gz +``` + +and on Windows: +```powershell +Get-FileHash .\circleci-cli__.tar.gz -Algorithm SHA256 | Format-List +``` + +And compare it to the right checksum depending on the downloaded version in the `circleci-cli__checksums.txt` file. + ### Updating If you installed the CLI without a package manager, you can use its built-in update command to check for pending updates and download them: From c8491913c3a318eba0e90aefca2ef25c04e12900 Mon Sep 17 00:00:00 2001 From: Sagar Gupta Date: Mon, 6 Feb 2023 08:26:52 -0500 Subject: [PATCH 08/11] bump circle-policy-agent version (#837) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1114a1afc..594654606 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/CircleCI-Public/circleci-cli require ( github.com/AlecAivazis/survey/v2 v2.1.1 - github.com/CircleCI-Public/circle-policy-agent v0.0.457 + github.com/CircleCI-Public/circle-policy-agent v0.0.462 github.com/Masterminds/semver v1.4.2 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/blang/semver v3.5.1+incompatible diff --git a/go.sum b/go.sum index 45bf0f77d..eb5e66a96 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ github.com/AlecAivazis/survey/v2 v2.1.1 h1:LEMbHE0pLj75faaVEKClEX1TM4AJmmnOh9eim github.com/AlecAivazis/survey/v2 v2.1.1/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/CircleCI-Public/circle-policy-agent v0.0.457 h1:dsNC6/uo5Fk2Ji7wYAQ+H4ZOMVXhYxH3tDKFJ3Zazog= -github.com/CircleCI-Public/circle-policy-agent v0.0.457/go.mod h1:lsP7UOPtBj0+IYFdL46vdoPaPJitURRvhmhiE4uRpeg= +github.com/CircleCI-Public/circle-policy-agent v0.0.462 h1:WYSrA9MQGsqjjg19KJ3xve7CpH7KPiYg1JLD06SK/3k= +github.com/CircleCI-Public/circle-policy-agent v0.0.462/go.mod h1:lsP7UOPtBj0+IYFdL46vdoPaPJitURRvhmhiE4uRpeg= github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= From 5cbf90e58053271341e25c0142b044a77a96271f Mon Sep 17 00:00:00 2001 From: threepipes Date: Tue, 16 Aug 2022 00:57:37 +0900 Subject: [PATCH 09/11] Commands added: - `circleci project list-secrets` Other changes: - Replace a request header `Accept-Type` with `Accept` --- api/project/project.go | 13 +++ api/project/project_rest.go | 104 ++++++++++++++++++ api/project/project_rest_test.go | 160 ++++++++++++++++++++++++++++ cmd/project/environment_variable.go | 46 ++++++++ cmd/project/project.go | 34 ++++++ cmd/project/project_test.go | 138 ++++++++++++++++++++++++ cmd/root.go | 2 + cmd/root_test.go | 2 +- 8 files changed, 498 insertions(+), 1 deletion(-) create mode 100644 api/project/project.go create mode 100644 api/project/project_rest.go create mode 100644 api/project/project_rest_test.go create mode 100644 cmd/project/environment_variable.go create mode 100644 cmd/project/project.go create mode 100644 cmd/project/project_test.go diff --git a/api/project/project.go b/api/project/project.go new file mode 100644 index 000000000..442ea7576 --- /dev/null +++ b/api/project/project.go @@ -0,0 +1,13 @@ +package project + +// ProjectEnvironmentVariable is a Environment Variable of a Project +type ProjectEnvironmentVariable struct { + Name string + Value string +} + +// ProjectClient is the interface to interact with project and it's +// components. +type ProjectClient interface { + ListAllEnvironmentVariables(vcs, org, project string) ([]*ProjectEnvironmentVariable, error) +} diff --git a/api/project/project_rest.go b/api/project/project_rest.go new file mode 100644 index 000000000..1536f55ca --- /dev/null +++ b/api/project/project_rest.go @@ -0,0 +1,104 @@ +package project + +import ( + "fmt" + "net/url" + + "github.com/CircleCI-Public/circleci-cli/api/rest" + "github.com/CircleCI-Public/circleci-cli/settings" +) + +type projectRestClient struct { + token string + server string + client *rest.Client +} + +var _ ProjectClient = &projectRestClient{} + +type listProjectEnvVarsParams struct { + vcs string + org string + project string + pageToken string +} + +type projectEnvVarResponse struct { + Name string + Value string +} + +type listAllProjectEnvVarsResponse struct { + Items []projectEnvVarResponse + NextPageToken string `json:"next_page_token"` +} + +// NewProjectRestClient returns a new projectRestClient satisfying the api.ProjectInterface +// interface via the REST API. +func NewProjectRestClient(config settings.Config) (*projectRestClient, error) { + serverURL, err := config.ServerURL() + if err != nil { + return nil, err + } + + client := &projectRestClient{ + token: config.Token, + server: serverURL.String(), + client: rest.New(config.Host, &config), + } + + return client, nil +} + +// ListAllEnvironmentVariables returns all of the environment variables owned by the +// given project. Note that pagination is not supported - we get all +// pages of env vars and return them all. +func (p *projectRestClient) ListAllEnvironmentVariables(vcs, org, project string) ([]*ProjectEnvironmentVariable, error) { + res := make([]*ProjectEnvironmentVariable, 0) + var nextPageToken string + for { + resp, err := p.listEnvironmentVariables(&listProjectEnvVarsParams{ + vcs: vcs, + org: org, + project: project, + pageToken: nextPageToken, + }) + if err != nil { + return nil, err + } + + for _, ev := range resp.Items { + res = append(res, &ProjectEnvironmentVariable{ + Name: ev.Name, + Value: ev.Value, + }) + } + + if resp.NextPageToken == "" { + break + } + + nextPageToken = resp.NextPageToken + } + return res, nil +} + +func (c *projectRestClient) listEnvironmentVariables(params *listProjectEnvVarsParams) (*listAllProjectEnvVarsResponse, error) { + path := fmt.Sprintf("project/%s/%s/%s/envvar", params.vcs, params.org, params.project) + urlParams := url.Values{} + if params.pageToken != "" { + urlParams.Add("page-token", params.pageToken) + } + + req, err := c.client.NewRequest("GET", &url.URL{Path: path, RawQuery: urlParams.Encode()}, nil) + if err != nil { + return nil, err + } + + var resp listAllProjectEnvVarsResponse + _, err = c.client.DoRequest(req, &resp) + if err != nil { + return nil, err + } + return &resp, nil +} diff --git a/api/project/project_rest_test.go b/api/project/project_rest_test.go new file mode 100644 index 000000000..29d3305e1 --- /dev/null +++ b/api/project/project_rest_test.go @@ -0,0 +1,160 @@ +package project_test + +import ( + "fmt" + "net/http" + "net/http/httptest" + "net/url" + "reflect" + "testing" + + "github.com/CircleCI-Public/circleci-cli/api/project" + "github.com/CircleCI-Public/circleci-cli/settings" + "github.com/CircleCI-Public/circleci-cli/version" + "gotest.tools/v3/assert" +) + +func getProjectRestClient(server *httptest.Server) (project.ProjectClient, error) { + client := &http.Client{} + + return project.NewProjectRestClient(settings.Config{ + RestEndpoint: "api/v2", + Host: server.URL, + HTTPClient: client, + Token: "token", + }) +} + +func Test_projectRestClient_ListAllEnvironmentVariables(t *testing.T) { + const ( + vcsType = "github" + orgName = "test-org" + projName = "test-proj" + ) + tests := []struct { + name string + handler http.HandlerFunc + want []*project.ProjectEnvironmentVariable + wantErr bool + }{ + { + name: "Should handle a successful request with ListAllEnvironmentVariables", + handler: func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, r.Header.Get("circle-token"), "token") + assert.Equal(t, r.Header.Get("accept"), "application/json") + assert.Equal(t, r.Header.Get("user-agent"), version.UserAgent()) + + assert.Equal(t, r.Method, "GET") + assert.Equal(t, r.URL.Path, fmt.Sprintf("/api/v2/project/%s/%s/%s/envvar", vcsType, orgName, projName)) + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, err := w.Write([]byte(` + { + "items": [{ + "name": "foo", + "value": "xxxx1234" + }], + "next_page_token": "" + }`)) + assert.NilError(t, err) + }, + want: []*project.ProjectEnvironmentVariable{ + { + Name: "foo", + Value: "xxxx1234", + }, + }, + }, + { + name: "Should handle a request containing next_page_token with ListAllEnvironmentVariables", + handler: func(w http.ResponseWriter, r *http.Request) { + u, err := url.ParseQuery(r.URL.RawQuery) + assert.NilError(t, err) + + w.Header().Set("content-type", "application/json") + w.WriteHeader(http.StatusOK) + if tk := u.Get("page-token"); tk == "" { + _, err := w.Write([]byte(` + { + "items": [ + { + "name": "foo1", + "value": "xxxx1234" + }, + { + "name": "foo2", + "value": "xxxx2345" + } + ], + "next_page_token": "pagetoken" + }`)) + assert.NilError(t, err) + } else { + assert.Equal(t, tk, "pagetoken") + _, err := w.Write([]byte(` + { + "items": [ + { + "name": "bar1", + "value": "xxxxabcd" + }, + { + "name": "bar2", + "value": "xxxxbcde" + } + ], + "next_page_token": "" + }`)) + assert.NilError(t, err) + } + }, + want: []*project.ProjectEnvironmentVariable{ + { + Name: "foo1", + Value: "xxxx1234", + }, + { + Name: "foo2", + Value: "xxxx2345", + }, + { + Name: "bar1", + Value: "xxxxabcd", + }, + { + Name: "bar2", + Value: "xxxxbcde", + }, + }, + }, + { + name: "Should handle an error request with ListAllEnvironmentVariables", + handler: func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("content-type", "application/json") + w.WriteHeader(http.StatusInternalServerError) + _, err := w.Write([]byte(`{"message": "error"}`)) + assert.NilError(t, err) + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + server := httptest.NewServer(tt.handler) + defer server.Close() + + p, err := getProjectRestClient(server) + assert.NilError(t, err) + + got, err := p.ListAllEnvironmentVariables(vcsType, orgName, projName) + if (err != nil) != tt.wantErr { + t.Errorf("projectRestClient.ListAllEnvironmentVariables() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("projectRestClient.ListAllEnvironmentVariables() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/cmd/project/environment_variable.go b/cmd/project/environment_variable.go new file mode 100644 index 000000000..2d97cf7ef --- /dev/null +++ b/cmd/project/environment_variable.go @@ -0,0 +1,46 @@ +package project + +import ( + projectapi "github.com/CircleCI-Public/circleci-cli/api/project" + "github.com/CircleCI-Public/circleci-cli/cmd/validator" + "github.com/olekukonko/tablewriter" + "github.com/spf13/cobra" +) + +func newProjectEnvironmentVariableCommand(ops *projectOpts, preRunE validator.Validator) *cobra.Command { + cmd := &cobra.Command{ + Use: "secret", + Short: "Operate on environment variables of projects", + } + + listVarsCommand := &cobra.Command{ + Short: "List all environment variables of a project", + Use: "list ", + PreRunE: preRunE, + RunE: func(cmd *cobra.Command, args []string) error { + return listProjectEnvironmentVariables(cmd, ops.client, args[0], args[1], args[2]) + }, + Args: cobra.ExactArgs(3), + } + + cmd.AddCommand(listVarsCommand) + return cmd +} + +func listProjectEnvironmentVariables(cmd *cobra.Command, client projectapi.ProjectClient, vcsType, orgName, projName string) error { + envVars, err := client.ListAllEnvironmentVariables(vcsType, orgName, projName) + if err != nil { + return err + } + + table := tablewriter.NewWriter(cmd.OutOrStdout()) + + table.SetHeader([]string{"Environment Variable", "Value"}) + + for _, envVar := range envVars { + table.Append([]string{envVar.Name, envVar.Value}) + } + table.Render() + + return nil +} diff --git a/cmd/project/project.go b/cmd/project/project.go new file mode 100644 index 000000000..2d7b20f06 --- /dev/null +++ b/cmd/project/project.go @@ -0,0 +1,34 @@ +package project + +import ( + projectapi "github.com/CircleCI-Public/circleci-cli/api/project" + "github.com/CircleCI-Public/circleci-cli/cmd/validator" + + "github.com/CircleCI-Public/circleci-cli/settings" + "github.com/spf13/cobra" +) + +type projectOpts struct { + client projectapi.ProjectClient +} + +// NewProjectCommand generates a cobra command for managing projects +func NewProjectCommand(config *settings.Config, preRunE validator.Validator) *cobra.Command { + var opts projectOpts + command := &cobra.Command{ + Use: "project", + Short: "Operate on projects", + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + client, err := projectapi.NewProjectRestClient(*config) + if err != nil { + return err + } + opts.client = client + return nil + }, + } + + command.AddCommand(newProjectEnvironmentVariableCommand(&opts, preRunE)) + + return command +} diff --git a/cmd/project/project_test.go b/cmd/project/project_test.go new file mode 100644 index 000000000..1bf2674a7 --- /dev/null +++ b/cmd/project/project_test.go @@ -0,0 +1,138 @@ +package project_test + +import ( + "bytes" + "fmt" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/CircleCI-Public/circleci-cli/cmd/project" + "github.com/CircleCI-Public/circleci-cli/cmd/validator" + "github.com/CircleCI-Public/circleci-cli/settings" + "github.com/olekukonko/tablewriter" + "github.com/spf13/cobra" + "gotest.tools/v3/assert" +) + +const ( + vcsType = "github" + orgName = "test-org" + projectName = "test-project" +) + +func tableString(header []string, rows [][]string) string { + res := &strings.Builder{} + table := tablewriter.NewWriter(res) + table.SetHeader(header) + for _, r := range rows { + table.Append(r) + } + table.Render() + return res.String() +} + +func getListProjectsArg() []string { + return []string{ + "secret", + "list", + vcsType, + orgName, + projectName, + } +} + +func TestListSecrets(t *testing.T) { + var handler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, r.Method, "GET") + assert.Equal(t, r.URL.String(), fmt.Sprintf("/project/%s/%s/%s/envvar", vcsType, orgName, projectName)) + response := `{ + "items": [{ + "name": "foo", + "value": "xxxx1234" + }], + "next_page_token": "" + }` + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, err := w.Write([]byte(response)) + assert.NilError(t, err) + } + server := httptest.NewServer(handler) + defer server.Close() + + cmd, stdout, _ := scaffoldCMD( + server.URL, + func(cmd *cobra.Command, args []string) error { + return nil + }, + ) + cmd.SetArgs(getListProjectsArg()) + err := cmd.Execute() + assert.NilError(t, err) + + expect := tableString( + []string{"Environment Variable", "Value"}, + [][]string{{"foo", "xxxx1234"}}, + ) + res := stdout.String() + assert.Equal(t, res, expect) +} + +func TestListSecretsErrorWithValidator(t *testing.T) { + const errorMsg = "validator error" + var handler http.HandlerFunc = func(_ http.ResponseWriter, _ *http.Request) {} + server := httptest.NewServer(handler) + defer server.Close() + + cmd, _, _ := scaffoldCMD( + server.URL, + func(_ *cobra.Command, _ []string) error { + return fmt.Errorf(errorMsg) + }, + ) + cmd.SetArgs(getListProjectsArg()) + err := cmd.Execute() + assert.Error(t, err, errorMsg) +} + +func TestListSecretsErrorWithAPIResponse(t *testing.T) { + const errorMsg = "api error" + var handler http.HandlerFunc = func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusInternalServerError) + _, err := w.Write([]byte(fmt.Sprintf(`{"message": "%s"}`, errorMsg))) + assert.NilError(t, err) + } + server := httptest.NewServer(handler) + defer server.Close() + + cmd, _, _ := scaffoldCMD( + server.URL, + func(cmd *cobra.Command, args []string) error { + return nil + }, + ) + cmd.SetArgs(getListProjectsArg()) + err := cmd.Execute() + assert.Error(t, err, errorMsg) +} + +func scaffoldCMD( + baseURL string, + validator validator.Validator, +) (*cobra.Command, *bytes.Buffer, *bytes.Buffer) { + config := &settings.Config{ + Token: "testtoken", + HTTPClient: http.DefaultClient, + Host: baseURL, + } + cmd := project.NewProjectCommand(config, validator) + + stdout := new(bytes.Buffer) + stderr := new(bytes.Buffer) + cmd.SetOut(stdout) + cmd.SetErr(stderr) + + return cmd, stdout, stderr +} diff --git a/cmd/root.go b/cmd/root.go index f47ff96ea..6a636cd0c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,6 +9,7 @@ import ( "github.com/CircleCI-Public/circleci-cli/api/header" "github.com/CircleCI-Public/circleci-cli/cmd/info" "github.com/CircleCI-Public/circleci-cli/cmd/policy" + "github.com/CircleCI-Public/circleci-cli/cmd/project" "github.com/CircleCI-Public/circleci-cli/cmd/runner" "github.com/CircleCI-Public/circleci-cli/data" "github.com/CircleCI-Public/circleci-cli/md_docs" @@ -138,6 +139,7 @@ func MakeCommands() *cobra.Command { rootCmd.AddCommand(newOpenCommand()) rootCmd.AddCommand(newTestsCommand()) rootCmd.AddCommand(newContextCommand(rootOptions)) + rootCmd.AddCommand(project.NewProjectCommand(rootOptions, validator)) rootCmd.AddCommand(newQueryCommand(rootOptions)) rootCmd.AddCommand(newConfigCommand(rootOptions)) rootCmd.AddCommand(newOrbCommand(rootOptions)) diff --git a/cmd/root_test.go b/cmd/root_test.go index 01fbd7205..6ea4c5667 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -16,7 +16,7 @@ var _ = Describe("Root", func() { Describe("subcommands", func() { It("can create commands", func() { commands := cmd.MakeCommands() - Expect(len(commands.Commands())).To(Equal(22)) + Expect(len(commands.Commands())).To(Equal(23)) }) }) From 8d5e0a2646481355be248ff0f44b4540fff33a45 Mon Sep 17 00:00:00 2001 From: JulesFaucherre Date: Tue, 14 Feb 2023 17:54:38 +0100 Subject: [PATCH 10/11] update dependencies for /api/policy (#843) --- go.mod | 6 +++--- go.sum | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 594654606..3585f3c1f 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/CircleCI-Public/circleci-cli require ( github.com/AlecAivazis/survey/v2 v2.1.1 - github.com/CircleCI-Public/circle-policy-agent v0.0.462 + github.com/CircleCI-Public/circle-policy-agent v0.0.469 github.com/Masterminds/semver v1.4.2 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/blang/semver v3.5.1+incompatible @@ -35,7 +35,7 @@ require ( github.com/charmbracelet/lipgloss v0.5.0 github.com/erikgeiser/promptkit v0.7.0 github.com/hexops/gotextdiff v1.0.3 - golang.org/x/exp v0.0.0-20230118134722-a68e582fa157 + golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb ) require ( @@ -70,7 +70,7 @@ require ( github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.12.0 // indirect github.com/nxadm/tail v1.4.8 // indirect - github.com/open-policy-agent/opa v0.48.0 // indirect + github.com/open-policy-agent/opa v0.49.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect diff --git a/go.sum b/go.sum index eb5e66a96..b1a6e90a2 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CircleCI-Public/circle-policy-agent v0.0.462 h1:WYSrA9MQGsqjjg19KJ3xve7CpH7KPiYg1JLD06SK/3k= github.com/CircleCI-Public/circle-policy-agent v0.0.462/go.mod h1:lsP7UOPtBj0+IYFdL46vdoPaPJitURRvhmhiE4uRpeg= +github.com/CircleCI-Public/circle-policy-agent v0.0.469 h1:qsMuMObnT+LVYra1ekK25ayot4qQ8j7WGv0IInT2heI= +github.com/CircleCI-Public/circle-policy-agent v0.0.469/go.mod h1:lsP7UOPtBj0+IYFdL46vdoPaPJitURRvhmhiE4uRpeg= github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= @@ -281,6 +283,8 @@ github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/open-policy-agent/opa v0.48.0 h1:s2K823yohAUu/HB4MOPWDhBh88JMKQv7uTr6S89fbM0= github.com/open-policy-agent/opa v0.48.0/go.mod h1:CsQcksP+qGBxO9oEBj1NnZqKcjgjmTJbRNTzjZB/DXQ= +github.com/open-policy-agent/opa v0.49.0 h1:TIlpCT1B5FSm8Dqo/a4t23gKmHkQysC3+7W77F99P4k= +github.com/open-policy-agent/opa v0.49.0/go.mod h1:WTLWtu498/QNTDkiHx76Xj7jaJUPvLJAPtdMkCcst0w= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -369,6 +373,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20230118134722-a68e582fa157 h1:fiNkyhJPUvxbRPbCqY/D9qdjmPzfHcpK3P4bM4gioSY= golang.org/x/exp v0.0.0-20230118134722-a68e582fa157/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb h1:PaBZQdo+iSDyHT053FjUCgZQ/9uqVwPOcl7KSWhKn6w= +golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= From 901243e2ba1206e85a52f795a06748e8a951f559 Mon Sep 17 00:00:00 2001 From: JulesFaucherre Date: Tue, 14 Feb 2023 18:08:40 +0100 Subject: [PATCH 11/11] fix: Fix the github pages ASCII art (#840) --- md_docs/md_docs.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/md_docs/md_docs.go b/md_docs/md_docs.go index dc2aae99a..36cef982a 100644 --- a/md_docs/md_docs.go +++ b/md_docs/md_docs.go @@ -170,6 +170,15 @@ func GenMarkdownTree(cmd *cobra.Command, dir string) error { // GenMarkdownTreeCustom is the the same as GenMarkdownTree, but // with custom filePrepender and linkHandler. func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error { + // There is a problem with the tool transforming the markdown into html, the tool transforms the + // circleci ascii art bad. By forcing it into a codeblock the formatting problem disappear + if cmd.Root() == cmd { + oldLong := cmd.Long + cmd.Long = fmt.Sprintf("```%s\n```", oldLong) + defer func() { + cmd.Long = oldLong + }() + } for _, c := range cmd.Commands() { if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() { continue