Skip to content

Commit

Permalink
Test publish (#1)
Browse files Browse the repository at this point in the history
* OCM-4962 | Feat | Add OAuth login using PKCE (openshift-online#590)

* OCM-5759 | feat: Add Device Code Flow (openshift-online#591)

* OCM-5281 | Feat | Add region validation from ocm-shards and list regions command (openshift-online#586)

* Add region validation from ocm-shards and list regions command

* Fixed mior debug changes

* Marked rh region list flag hidden in cmd

* Formatting change in example section in cmd file

* OCM-4964: Secure store config

* OCM-4964: Go mod tidy

* OCM-4964: go mod tidy

* OCM-4964: Secure store updates

* OCM-4965: Use keyring for oauth flows

* Temp: modify pub/release for testing

* Add auth method password

* Missed auth method test

---------

Co-authored-by: tirthct <[email protected]>
  • Loading branch information
tylercreller and tirthct authored Feb 6, 2024
1 parent fab7ccf commit 6ad3fab
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 85 deletions.
118 changes: 59 additions & 59 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,62 +93,62 @@ jobs:
build("linux", "s390x")
build("windows", "amd64")
# Calculate the SHA256 digests:
for asset in os.listdir(assets):
digest = os.path.join(assets, f"{asset}.sha256")
with open(digest, "wb") as stream:
args = ["sha256sum", asset]
subprocess.run(check=True, cwd=assets, stdout=stream, args=args)
# Get the list of changes:
body = ""
with open("CHANGES.md", "r") as stream:
while True:
line = stream.readline()
if line == "" or line.startswith("## " + version):
break
while True:
line = stream.readline()
if line == "" or line.startswith("## "):
break
body += line
# Send the request to create the release:
response = requests.post(
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
"Accept": "application/json",
},
json={
"tag_name": f"v{version}",
"name": f"Release {version}",
"body": body,
},
url=(
"https://api.github.com"
f"/repos/{repository}/releases"
),
)
response.raise_for_status()
# Get the release identifier:
release = response.json()["id"]
# Upload the assets:
for asset in os.listdir(assets):
file = os.path.join(assets, asset)
with open(file, "rb") as stream:
response = requests.post(
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/octet-stream",
"Accept": "application/json",
},
data=stream,
url=(
"https://uploads.github.com"
f"/repos/{repository}/releases/{release}/assets?name={asset}"
),
)
response.raise_for_status()
# # Calculate the SHA256 digests:
# for asset in os.listdir(assets):
# digest = os.path.join(assets, f"{asset}.sha256")
# with open(digest, "wb") as stream:
# args = ["sha256sum", asset]
# subprocess.run(check=True, cwd=assets, stdout=stream, args=args)
# # Get the list of changes:
# body = ""
# with open("CHANGES.md", "r") as stream:
# while True:
# line = stream.readline()
# if line == "" or line.startswith("## " + version):
# break
# while True:
# line = stream.readline()
# if line == "" or line.startswith("## "):
# break
# body += line
# # Send the request to create the release:
# response = requests.post(
# headers={
# "Authorization": f"Bearer {token}",
# "Content-Type": "application/json",
# "Accept": "application/json",
# },
# json={
# "tag_name": f"v{version}",
# "name": f"Release {version}",
# "body": body,
# },
# url=(
# "https://api.github.com"
# f"/repos/{repository}/releases"
# ),
# )
# response.raise_for_status()
# # Get the release identifier:
# release = response.json()["id"]
# # Upload the assets:
# for asset in os.listdir(assets):
# file = os.path.join(assets, asset)
# with open(file, "rb") as stream:
# response = requests.post(
# headers={
# "Authorization": f"Bearer {token}",
# "Content-Type": "application/octet-stream",
# "Accept": "application/json",
# },
# data=stream,
# url=(
# "https://uploads.github.com"
# f"/repos/{repository}/releases/{release}/assets?name={asset}"
# ),
# )
# response.raise_for_status()
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ cmds:
install:
go install ./cmd/ocm

# CGO_ENABLED=1 is required for Keychain support on macOS
.PHONY: install-cgo
install-cgo:
CGO_ENABLED=1 go install ./cmd/ocm

.PHONY: test tests
test tests: cmds
ginkgo run -r
Expand Down
2 changes: 2 additions & 0 deletions cmd/ocm/config/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/spf13/cobra"

"github.com/openshift-online/ocm-cli/cmd/ocm/config/delete"
"github.com/openshift-online/ocm-cli/cmd/ocm/config/get"
"github.com/openshift-online/ocm-cli/cmd/ocm/config/set"
"github.com/openshift-online/ocm-cli/pkg/config"
Expand Down Expand Up @@ -73,4 +74,5 @@ var Cmd = &cobra.Command{
func init() {
Cmd.AddCommand(get.Cmd)
Cmd.AddCommand(set.Cmd)
Cmd.AddCommand(delete.Cmd)
}
56 changes: 56 additions & 0 deletions cmd/ocm/config/delete/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright (c) 2024 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package delete

import (
"fmt"

"github.com/spf13/cobra"

"github.com/openshift-online/ocm-sdk-go/authentication/securestore"
)

var args struct {
debug bool
}

var Cmd = &cobra.Command{
Use: "delete",
Short: "Deletes the existing configuration from the OS keyring",
Long: "Deletes the existing configuration from the OS keyring",
Args: cobra.ExactArgs(0),
RunE: run,
Hidden: true,
}

func init() {
flags := Cmd.Flags()
flags.BoolVar(
&args.debug,
"debug",
false,
"Enable debug mode.",
)
}

func run(cmd *cobra.Command, argv []string) error {
err := securestore.RemoveConfigFromKeyring()
if err != nil {
return fmt.Errorf("can't delete config from keyring: %v", err)
}
return nil
}
11 changes: 11 additions & 0 deletions cmd/ocm/config/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/spf13/cobra"

"github.com/openshift-online/ocm-cli/pkg/config"
"github.com/openshift-online/ocm-sdk-go/authentication/securestore"
)

var args struct {
Expand Down Expand Up @@ -83,9 +84,19 @@ func run(cmd *cobra.Command, argv []string) error {
fmt.Fprintf(os.Stdout, "%s\n", cfg.URL)
case "pager":
fmt.Fprintf(os.Stdout, "%s\n", cfg.Pager)
case "keyrings":
fmt.Fprintf(os.Stdout, "%s\n", getKeyrings())
default:
return fmt.Errorf("Unknown setting")
}

return nil
}

func getKeyrings() []string {
backends := securestore.AvailableBackends()
if len(backends) == 0 {
fmt.Printf("No keyrings available: %s\n", securestore.ErrNoBackendsAvailable)
}
return backends
}
32 changes: 24 additions & 8 deletions cmd/ocm/login/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ func run(cmd *cobra.Command, argv []string) error {

// Check that we have some kind of credentials:
havePassword := args.user != "" && args.password != ""
haveSecret := args.clientID != "" && args.clientSecret != ""
haveClientCreds := args.clientID != "" && args.clientSecret != ""
haveToken := args.token != ""
if !havePassword && !haveSecret && !haveToken {
if !havePassword && !haveClientCreds && !haveToken {
// Allow bare `ocm login` to suggest the token page without noise of full help.
fmt.Fprintf(
os.Stderr,
Expand All @@ -246,15 +246,31 @@ func run(cmd *cobra.Command, argv []string) error {
)
}

// Load the configuration file:
cfg, err := config.Load()
// Set the authentication method:
var authMethod config.AuthMethodType
if args.useAuthCode {
authMethod = config.AuthCode
} else if args.useDeviceCode {
authMethod = config.DeviceCode
} else if haveClientCreds {
authMethod = config.ClientAuth
} else if havePassword {
authMethod = config.Password
} else {
authMethod = config.TokenAuth
}

// Load the configuration:
cfg, err := config.LoginLoad(authMethod)
if err != nil {
return fmt.Errorf("Can't load config file: %v", err)
return fmt.Errorf("Can't load config: %v", err)
}
if cfg == nil {
cfg = new(config.Config)
}

cfg.AuthMethod = string(authMethod)

if haveToken {
// Encrypted tokens are assumed to be refresh tokens:
if config.IsEncryptedToken(args.token) {
Expand Down Expand Up @@ -342,7 +358,7 @@ func run(cmd *cobra.Command, argv []string) error {

err = config.Save(cfg)
if err != nil {
return fmt.Errorf("Can't save config file: %v", err)
return fmt.Errorf("can't save config: %v", err)
}

if args.useAuthCode || args.useDeviceCode {
Expand All @@ -353,8 +369,8 @@ func run(cmd *cobra.Command, argv []string) error {
ssoHost := ssoURL.Scheme + "://" + ssoURL.Hostname()

fmt.Println("Login successful")
fmt.Printf("To switch accounts, logout from %s and run `ocm logout` "+
"before attempting to login again", ssoHost)
fmt.Println(fmt.Sprintf("To switch accounts, logout from %s and run `ocm logout` "+
"before attempting to login again", ssoHost))
}

return nil
Expand Down
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/nwidger/jsoncolor v0.3.2
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.8
github.com/openshift-online/ocm-sdk-go v0.1.398
github.com/openshift-online/ocm-sdk-go v0.1.399
github.com/openshift/rosa v1.2.24
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/spf13/cobra v1.7.0
Expand All @@ -25,22 +25,28 @@ require (
)

require (
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/aws/aws-sdk-go v1.44.110 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/briandowns/spinner v1.19.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/gojq v0.12.9 // indirect
github.com/itchyny/timefmt-go v0.1.4 // indirect
Expand All @@ -62,13 +68,13 @@ require (
github.com/microcosm-cc/bluemonday v1.0.23 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
github.com/zgalor/weberr v0.7.0 // indirect
Expand Down
Loading

0 comments on commit 6ad3fab

Please sign in to comment.