From 619c12cc640823047bb3f582ec76fac4b9509120 Mon Sep 17 00:00:00 2001 From: sellskin Date: Mon, 25 Mar 2024 12:53:53 +0800 Subject: [PATCH 1/8] remove code that will not be executed Signed-off-by: sellskin --- management/middleware_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/management/middleware_test.go b/management/middleware_test.go index 5af7e8f3..0023536e 100644 --- a/management/middleware_test.go +++ b/management/middleware_test.go @@ -52,13 +52,11 @@ func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io req, err := http.NewRequest(method, ts.URL+path, body) if err != nil { t.Fatal(err) - return nil, nil } resp, err := ts.Client().Do(req) if err != nil { t.Fatal(err) - return nil, nil } var claims managementErrorResponse err = json.NewDecoder(resp.Body).Decode(&claims) From ae7f7fa7e814cae8f4f6b000a2b6f3e27db99c35 Mon Sep 17 00:00:00 2001 From: lneto Date: Thu, 1 Aug 2024 09:36:59 +0100 Subject: [PATCH 2/8] TUN-8546: remove call to non existant make target --- cfsetup.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/cfsetup.yaml b/cfsetup.yaml index 953a80a1..613cb0f8 100644 --- a/cfsetup.yaml +++ b/cfsetup.yaml @@ -209,7 +209,6 @@ buster: &buster - pip3 install pygithub==1.55 post-cache: - make github-release - - make github-message r2-linux-release: build_dir: *build_dir builddeps: From b03ea055b0bb42d21941fe9c7ef8b367de86db47 Mon Sep 17 00:00:00 2001 From: lneto Date: Thu, 1 Aug 2024 16:26:45 +0100 Subject: [PATCH 3/8] TUN-8581: create dry run for github release --- Makefile | 4 ++++ cfsetup.yaml | 16 +++++++++++++++- github_release.py | 12 ++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1d044ac9..46fee2a9 100644 --- a/Makefile +++ b/Makefile @@ -218,6 +218,10 @@ cloudflared-pkg: cloudflared cloudflared.1 cloudflared-msi: wixl --define Version=$(VERSION) --define Path=$(EXECUTABLE_PATH) --output cloudflared-$(VERSION)-$(TARGET_ARCH).msi cloudflared.wxs +.PHONY: github-release-dryrun +github-release-dryrun: + python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION) --dry-run + .PHONY: github-release github-release: python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION) diff --git a/cfsetup.yaml b/cfsetup.yaml index 613cb0f8..62e8de5d 100644 --- a/cfsetup.yaml +++ b/cfsetup.yaml @@ -195,9 +195,23 @@ buster: &buster - component-tests/requirements.txt pre-cache: *component_test_pre_cache post-cache: *component_test_post_cache + github-release-dryrun: + build_dir: *build_dir + builddeps: + - *pinned_go + - build-essential + - python3-dev + - libffi-dev + - python3-setuptools + - python3-pip + pre-cache: + - pip3 install pynacl==1.4.0 + - pip3 install pygithub==1.55 + post-cache: + - make github-release-dryrun github-release: build_dir: *build_dir - builddeps: + builddeps: - *pinned_go - build-essential - python3-dev diff --git a/github_release.py b/github_release.py index e28a89cc..db612086 100755 --- a/github_release.py +++ b/github_release.py @@ -17,7 +17,7 @@ import re from github import Github, GithubException, UnknownObjectException FORMAT = "%(levelname)s - %(asctime)s: %(message)s" -logging.basicConfig(format=FORMAT) +logging.basicConfig(format=FORMAT, level=logging.INFO) CLOUDFLARED_REPO = os.environ.get("GITHUB_REPO", "cloudflare/cloudflared") GITHUB_CONFLICT_CODE = "already_exists" @@ -219,7 +219,15 @@ def main(): release = get_or_create_release(repo, args.release_version, args.dry_run) if args.dry_run: - logging.info("Skipping asset upload because of dry-run") + if os.path.isdir(args.path): + onlyfiles = [f for f in listdir(args.path) if isfile(join(args.path, f))] + for filename in onlyfiles: + binary_path = os.path.join(args.path, filename) + logging.info("binary: " + binary_path) + elif os.path.isfile(args.path): + logging.info("binary: " + binary_path) + else: + logging.error("dryrun failed") return if os.path.isdir(args.path): From bd9e020df93206ef32d35229d91349526f2e10e8 Mon Sep 17 00:00:00 2001 From: lneto Date: Mon, 5 Aug 2024 10:44:33 +0100 Subject: [PATCH 4/8] TUN-8583: change final directory of artifacts --- .teamcity/package-windows.sh | 10 ++++++---- build-packages-fips.sh | 4 ++-- build-packages.sh | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.teamcity/package-windows.sh b/.teamcity/package-windows.sh index 0139a51b..a4b91d93 100755 --- a/.teamcity/package-windows.sh +++ b/.teamcity/package-windows.sh @@ -3,14 +3,16 @@ echo $VERSION export TARGET_OS=windows # This controls the directory the built artifacts go into -export ARTIFACT_DIR=built_artifacts/ -mkdir -p $ARTIFACT_DIR +export BUILT_ARTIFACT_DIR=built_artifacts/ +export FINAL_ARTIFACT_DIR=artifacts/ +mkdir -p $BUILT_ARTIFACT_DIR +mkdir -p $FINAL_ARTIFACT_DIR windowsArchs=("amd64" "386") for arch in ${windowsArchs[@]}; do export TARGET_ARCH=$arch # Copy exe into final directory - cp $ARTIFACT_DIR/cloudflared-windows-$arch.exe ./cloudflared.exe + cp $BUILT_ARTIFACT_DIR/cloudflared-windows-$arch.exe ./cloudflared.exe make cloudflared-msi # Copy msi into final directory - mv cloudflared-$VERSION-$arch.msi $ARTIFACT_DIR/cloudflared-windows-$arch.msi + mv cloudflared-$VERSION-$arch.msi $FINAL_ARTIFACT_DIR/cloudflared-windows-$arch.msi done diff --git a/build-packages-fips.sh b/build-packages-fips.sh index a7401eab..0ec3b3c9 100755 --- a/build-packages-fips.sh +++ b/build-packages-fips.sh @@ -3,7 +3,7 @@ VERSION=$(git describe --tags --always --match "[0-9][0-9][0-9][0-9].*.*") echo $VERSION # This controls the directory the built artifacts go into -export ARTIFACT_DIR=built_artifacts/ +export ARTIFACT_DIR=artifacts/ mkdir -p $ARTIFACT_DIR arch=("amd64") @@ -23,4 +23,4 @@ make cloudflared-rpm mv cloudflared-fips-$RPMVERSION-1.$RPMARCH.rpm $ARTIFACT_DIR/cloudflared-fips-linux-$RPMARCH.rpm # finally move the linux binary as well. -mv ./cloudflared $ARTIFACT_DIR/cloudflared-fips-linux-$arch \ No newline at end of file +mv ./cloudflared $ARTIFACT_DIR/cloudflared-fips-linux-$arch diff --git a/build-packages.sh b/build-packages.sh index 9570dab0..df5dc7bb 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -7,7 +7,7 @@ export GOEXPERIMENT=noboringcrypto export CGO_ENABLED=0 # This controls the directory the built artifacts go into -export ARTIFACT_DIR=built_artifacts/ +export ARTIFACT_DIR=artifacts/ mkdir -p $ARTIFACT_DIR linuxArchs=("386" "amd64" "arm" "armhf" "arm64") From 86f33005b98ec2a21534f82bdf76a9e2bf667dfd Mon Sep 17 00:00:00 2001 From: lneto Date: Mon, 5 Aug 2024 14:27:56 +0100 Subject: [PATCH 5/8] TUN-8585: Avoid creating GH client when dry-run is true - copy exe files from windows build --- .teamcity/package-windows.sh | 1 + github_release.py | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.teamcity/package-windows.sh b/.teamcity/package-windows.sh index a4b91d93..6715af92 100755 --- a/.teamcity/package-windows.sh +++ b/.teamcity/package-windows.sh @@ -15,4 +15,5 @@ for arch in ${windowsArchs[@]}; do make cloudflared-msi # Copy msi into final directory mv cloudflared-$VERSION-$arch.msi $FINAL_ARTIFACT_DIR/cloudflared-windows-$arch.msi + cp $BUILT_ARTIFACT_DIR/cloudflared-windows-$arch.exe $FINAL_ARTIFACT_DIR/cloudflared-windows-$arch.exe done diff --git a/github_release.py b/github_release.py index db612086..8773fc43 100755 --- a/github_release.py +++ b/github_release.py @@ -214,9 +214,6 @@ def main(): """ Attempts to upload Asset to Github Release. Creates Release if it doesn't exist """ try: args = parse_args() - client = Github(args.api_key) - repo = client.get_repo(CLOUDFLARED_REPO) - release = get_or_create_release(repo, args.release_version, args.dry_run) if args.dry_run: if os.path.isdir(args.path): @@ -229,17 +226,21 @@ def main(): else: logging.error("dryrun failed") return - - if os.path.isdir(args.path): - onlyfiles = [f for f in listdir(args.path) if isfile(join(args.path, f))] - for filename in onlyfiles: - binary_path = os.path.join(args.path, filename) - upload_asset(release, binary_path, filename, args.release_version, args.kv_account_id, args.namespace_id, - args.kv_api_token) - move_asset(binary_path, filename) else: - upload_asset(release, args.path, args.name, args.release_version, args.kv_account_id, args.namespace_id, - args.kv_api_token) + client = Github(args.api_key) + repo = client.get_repo(CLOUDFLARED_REPO) + release = get_or_create_release(repo, args.release_version, args.dry_run) + + if os.path.isdir(args.path): + onlyfiles = [f for f in listdir(args.path) if isfile(join(args.path, f))] + for filename in onlyfiles: + binary_path = os.path.join(args.path, filename) + upload_asset(release, binary_path, filename, args.release_version, args.kv_account_id, args.namespace_id, + args.kv_api_token) + move_asset(binary_path, filename) + else: + upload_asset(release, args.path, args.name, args.release_version, args.kv_account_id, args.namespace_id, + args.kv_api_token) except Exception as e: logging.exception(e) From 9f0002db4053de1e9792df526c4fc5d16aaf5150 Mon Sep 17 00:00:00 2001 From: lneto Date: Mon, 5 Aug 2024 18:25:12 +0100 Subject: [PATCH 6/8] Release 2024.8.2 --- RELEASE_NOTES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 200a04bd..a40a0251 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,3 +1,7 @@ +2024.8.2 +- 2024-08-05 TUN-8583: change final directory of artifacts +- 2024-08-05 TUN-8585: Avoid creating GH client when dry-run is true + 2024.7.3 - 2024-07-31 TUN-8546: Fix final artifacts paths From 30c435fee6eb55b44eaf3edbac805d395149bae4 Mon Sep 17 00:00:00 2001 From: sellskin Date: Mon, 25 Mar 2024 12:53:53 +0800 Subject: [PATCH 7/8] remove code that will not be executed Signed-off-by: sellskin --- management/middleware_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/management/middleware_test.go b/management/middleware_test.go index 5af7e8f3..0023536e 100644 --- a/management/middleware_test.go +++ b/management/middleware_test.go @@ -52,13 +52,11 @@ func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io req, err := http.NewRequest(method, ts.URL+path, body) if err != nil { t.Fatal(err) - return nil, nil } resp, err := ts.Client().Do(req) if err != nil { t.Fatal(err) - return nil, nil } var claims managementErrorResponse err = json.NewDecoder(resp.Body).Decode(&claims) From a9365296aeeda82635610a4a356173cb4a190b13 Mon Sep 17 00:00:00 2001 From: Kornel Date: Thu, 15 Aug 2024 23:04:08 +0100 Subject: [PATCH 8/8] TUN-8591 login command without extra text Also unifies `access token` and `access login` interface --- cmd/cloudflared/access/cmd.go | 48 +++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/cmd/cloudflared/access/cmd.go b/cmd/cloudflared/access/cmd.go index b1770f1b..d1490ef7 100644 --- a/cmd/cloudflared/access/cmd.go +++ b/cmd/cloudflared/access/cmd.go @@ -26,6 +26,7 @@ import ( ) const ( + appURLFlag = "app" loginQuietFlag = "quiet" sshHostnameFlag = "hostname" sshDestinationFlag = "destination" @@ -83,9 +84,10 @@ func Commands() []*cli.Command { applications from the command line.`, Subcommands: []*cli.Command{ { - Name: "login", - Action: cliutil.Action(login), - Usage: "login ", + Name: "login", + Action: cliutil.Action(login), + Usage: "login ", + ArgsUsage: "url of Access application", Description: `The login subcommand initiates an authentication flow with your identity provider. The subcommand will launch a browser. For headless systems, a url is provided. Once authenticated with your identity provider, the login command will generate a JSON Web Token (JWT) @@ -97,6 +99,13 @@ func Commands() []*cli.Command { Aliases: []string{"q"}, Usage: "do not print the jwt to the command line", }, + &cli.BoolFlag{ + Name: "no-verbose", + Usage: "print only the jwt to stdout", + }, + &cli.StringFlag{ + Name: appURLFlag, + }, }, }, { @@ -111,12 +120,12 @@ func Commands() []*cli.Command { { Name: "token", Action: cliutil.Action(generateToken), - Usage: "token -app=", + Usage: "token ", ArgsUsage: "url of Access application", Description: `The token subcommand produces a JWT which can be used to authenticate requests.`, Flags: []cli.Flag{ &cli.StringFlag{ - Name: "app", + Name: appURLFlag, }, }, }, @@ -232,9 +241,8 @@ func login(c *cli.Context) error { log := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog) - args := c.Args() - appURL, err := parseURL(args.First()) - if args.Len() < 1 || err != nil { + appURL, err := getAppURLFromArgs(c) + if err != nil { log.Error().Msg("Please provide the url of the Access application") return err } @@ -261,7 +269,14 @@ func login(c *cli.Context) error { if c.Bool(loginQuietFlag) { return nil } - fmt.Fprintf(os.Stdout, "Successfully fetched your token:\n\n%s\n\n", cfdToken) + + // Chatty by default for backward compat. The new --app flag + // is an implicit opt-out of the backwards-compatible chatty output. + if c.Bool("no-verbose") || c.IsSet(appURLFlag) { + fmt.Fprint(os.Stdout, cfdToken) + } else { + fmt.Fprintf(os.Stdout, "Successfully fetched your token:\n\n%s\n\n", cfdToken) + } return nil } @@ -340,6 +355,17 @@ func run(cmd string, args ...string) error { return c.Run() } +func getAppURLFromArgs(c *cli.Context) (*url.URL, error) { + var appURLStr string + args := c.Args() + if args.Len() < 1 { + appURLStr = c.String(appURLFlag) + } else { + appURLStr = args.First() + } + return parseURL(appURLStr) +} + // token dumps provided token to stdout func generateToken(c *cli.Context) error { err := sentry.Init(sentry.ClientOptions{ @@ -349,8 +375,8 @@ func generateToken(c *cli.Context) error { if err != nil { return err } - appURL, err := parseURL(c.String("app")) - if err != nil || c.NumFlags() < 1 { + appURL, err := getAppURLFromArgs(c) + if err != nil { fmt.Fprintln(os.Stderr, "Please provide a url.") return err }