Skip to content

Commit

Permalink
feat(strm-1258 + strm-1238): use client_credentials grant for simulat…
Browse files Browse the repository at this point in the history
…or and websocket; remove billing id
  • Loading branch information
trietsch authored Jul 14, 2022
1 parent ea11ce1 commit a6bad5b
Show file tree
Hide file tree
Showing 38 changed files with 200 additions and 493 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:
make
- name: Run CLI tests
env:
STRM_TEST_USER_BILLING_ID: ${{ secrets.STRM_TEST_USER_BILLING_ID }}
STRM_TEST_USER_EMAIL: ${{ secrets.STRM_TEST_USER_EMAIL }}
STRM_TEST_USER_PASSWORD: ${{ secrets.STRM_TEST_USER_PASSWORD }}
STRM_TEST_S3_USER_NAME: ${{ secrets.STRM_TEST_S3_USER_NAME }}
STRM_TEST_S3_ACCESS_KEY_ID: ${{ secrets.STRM_TEST_S3_ACCESS_KEY_ID }}
STRM_TEST_S3_SECRET_ACCESS_KEY: ${{ secrets.STRM_TEST_S3_SECRET_ACCESS_KEY }}
STRM_TEST_PROJECT_ID: ${{ secrets.STRM_TEST_PROJECT_ID }}
run: |
go test ./test -v
- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/spf13/cobra v1.3.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.0
github.com/strmprivacy/api-definitions-go/v2 v2.38.0
github.com/strmprivacy/api-definitions-go/v2 v2.43.1
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/grpc v1.46.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/strmprivacy/api-definitions-go/v2 v2.38.0 h1:/d6oh2xc0N249j0LSAjbi2nLfY30dcaA6BYcprHMWYk=
github.com/strmprivacy/api-definitions-go/v2 v2.38.0/go.mod h1:3uFjMuBEQSzrRQzaKEgIrLbBWRdya9DTYCQZqyS7nEw=
github.com/strmprivacy/api-definitions-go/v2 v2.43.1 h1:saiY1lAElmviKOv8e0IjQGpoitypMFHqglWjp1Za3DU=
github.com/strmprivacy/api-definitions-go/v2 v2.43.1/go.mod h1:3uFjMuBEQSzrRQzaKEgIrLbBWRdya9DTYCQZqyS7nEw=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var longDocPrintToken = `
Print the current (JWT) access token to the terminal that can be used in a http header. Note that the token is printed
on ` + "`stdout`" + `, and the Expiry and billing-id are on ` + "`stderr`" + ` so it’s easy to capture the token for scripting use with
on ` + "`stdout`" + `, and the Expiry on ` + "`stderr`" + ` so it’s easy to capture the token for scripting use with
` + "```" + `bash
export token=$(strm auth access-token)
Expand Down
72 changes: 0 additions & 72 deletions pkg/auth/event.go

This file was deleted.

13 changes: 0 additions & 13 deletions pkg/auth/stored_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type storedToken struct {
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
ExpiresAt int64 `json:"expiresAt"`
BillingId string `json:"billingId"`
Email string `json:"email"`
}

Expand Down Expand Up @@ -52,7 +51,6 @@ func (authenticator *Authenticator) LoadLogin() error {
func (authenticator *Authenticator) populateValues(storedToken storedToken) {
authenticator.storedToken = storedToken
authenticator.tokenSource = createTokenSource(authenticator.storedToken)
authenticator.billingId = &authenticator.storedToken.BillingId
authenticator.Email = authenticator.storedToken.Email
}

Expand Down Expand Up @@ -98,14 +96,3 @@ func createTokenSource(storedToken storedToken) oauth2.TokenSource {
tokenSource := oAuth2Config.TokenSource(ctx, oauth2Token)
return tokenSource
}

func GetBillingId() (string, error) {
filename := (&Authenticator{}).getSaveFilename()
b, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
token := unmarshalStoredToken(err, b)
billingId := token.BillingId
return billingId, err
}
26 changes: 0 additions & 26 deletions pkg/auth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/int128/oauth2cli"
"github.com/pkg/browser"
log "github.com/sirupsen/logrus"
"github.com/strmprivacy/api-definitions-go/v2/api/account/v1"
"golang.org/x/oauth2"
"golang.org/x/sync/errgroup"
"net"
Expand All @@ -23,7 +22,6 @@ var Auth = Authenticator{}
type Authenticator struct {
storedToken storedToken
tokenSource oauth2.TokenSource
billingId *string
Email string
}

Expand All @@ -38,23 +36,10 @@ func oAuth2Config() oauth2.Config {
}
}

// Todo: remove (eventually, in STRM-1238), first add projectId from context to most places it's currently used
func (authenticator *Authenticator) BillingId() string {
if authenticator.billingId == nil {
common.MissingIdTokenError()
}

return *authenticator.billingId
}

func (authenticator *Authenticator) GetToken() *string {
return authenticator.accessToken()
}

func (authenticator *Authenticator) BillingIdAbsent() bool {
return authenticator.billingId == nil
}

func (authenticator *Authenticator) printAccessToken() {
accessToken := authenticator.accessToken()

Expand Down Expand Up @@ -135,7 +120,6 @@ func oauthTokenToStoredToken(t oauth2.Token) storedToken {
AccessToken: t.AccessToken,
RefreshToken: t.RefreshToken,
ExpiresAt: t.Expiry.Unix(),
BillingId: getLegacyBillingId(t.AccessToken),
Email: getEmailFromClaims(t),
}
}
Expand Down Expand Up @@ -169,16 +153,6 @@ func startBrowserLoginFlow(ready chan string, ctx context.Context) func() error
}
}

// Todo: we can leave this for now for backwards compatibility, to be removed in STRM-1238
func getLegacyBillingId(accessToken string) string {
clientConnection, ctx := common.SetupGrpc(common.ApiHost, &accessToken)
accountClient := account.NewAccountServiceClient(clientConnection)

response, err := accountClient.GetLegacyBillingId(ctx, &account.GetLegacyBillingIdRequest{})
common.CliExit(err)
return response.BillingId
}

func getEmailFromClaims(t oauth2.Token) string {
parsedAccessToken, _ := jwt.Parse(t.AccessToken, func(t *jwt.Token) (interface{}, error) {
return nil, nil
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var ContextCommand = &cobra.Command{
func init() {
ContextCommand.AddCommand(context.Configuration())
ContextCommand.AddCommand(context.EntityInfo())
ContextCommand.AddCommand(context.BillingIdInfo())
ContextCommand.AddCommand(context.Account())
ContextCommand.AddCommand(context.Project())
}
5 changes: 2 additions & 3 deletions pkg/cmd/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/spf13/cobra"
"strmprivacy/strm/pkg/simulator"
"strmprivacy/strm/pkg/simulator/random_events"
)

Expand All @@ -14,8 +13,8 @@ var SimulateCmd = &cobra.Command{

func init() {
flags := SimulateCmd.PersistentFlags()
flags.String(sim.SchemaFlag, "strmprivacy/demo/1.0.2", "Which schema to use for creating simulated events")
_ = SimulateCmd.RegisterFlagCompletionFunc(sim.SchemaFlag, schemaCompletion)
flags.String(random_events.SchemaFlag, "strmprivacy/demo/1.0.2", "Which schema to use for creating simulated events")
_ = SimulateCmd.RegisterFlagCompletionFunc(random_events.SchemaFlag, schemaCompletion)
SimulateCmd.AddCommand(random_events.RunCmd())
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ func MissingIdTokenError() {
CliExit(errors.New(fmt.Sprintf("No login information found. Use: `%v auth login` first.", RootCommandName)))
}

func MissingBillingIdCompletionError(commandPath string) ([]string, cobra.ShellCompDirective) {
log.Infoln(fmt.Sprintf("Called '%v' without login info", commandPath))
cobra.CompErrorln(fmt.Sprintf("No login information found. Use: `%v auth login` first.", RootCommandName))

return nil, cobra.ShellCompDirectiveNoFileComp
}

func GrpcRequestCompletionError(err error) ([]string, cobra.ShellCompDirective) {
errorMessage := fmt.Sprintf("%v", err)
log.Errorln(errorMessage)
Expand Down
3 changes: 0 additions & 3 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ var ContextOutputFormatFlagAllowedValuesText = strings.Join(ContextOutputFormatF
var ConfigOutputFormatFlagAllowedValues = []string{OutputFormatPlain, OutputFormatJson}
var ConfigOutputFormatFlagAllowedValuesText = strings.Join(ConfigOutputFormatFlagAllowedValues, ", ")

var BillingIdOutputFormatFlagAllowedValues = []string{OutputFormatPlain}
var BillingIdOutputFormatFlagAllowedValuesText = strings.Join(BillingIdOutputFormatFlagAllowedValues, ", ")

var AccountOutputFormatFlagAllowedValues = []string{OutputFormatPlain, OutputFormatJsonRaw}
var AccountOutputFormatFlagAllowedValuesText = strings.Join(AccountOutputFormatFlagAllowedValues, ", ")

Expand Down
29 changes: 0 additions & 29 deletions pkg/context/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"fmt"
"github.com/spf13/cobra"
"path"
"strmprivacy/strm/pkg/auth"
"strmprivacy/strm/pkg/common"
)

const (
configCommandName = "config"
entityInfoCommandName = "info"
billingIdInfoCommandName = "billing-id"
accountCommandName = "account"
projectCommandName = "project"
)
Expand Down Expand Up @@ -44,33 +42,6 @@ func Configuration() *cobra.Command {
return configuration
}

func BillingIdInfo() *cobra.Command {
cmd := &cobra.Command{
Use: billingIdInfoCommandName,
Short: "Show the billing id.",
DisableAutoGenTag: true,
PreRun: func(cmd *cobra.Command, args []string) {
printer = configurePrinter(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
_ = auth.Auth.BillingId()
billingIdInfo()
},
}
cmd.Flags().StringP(
common.OutputFormatFlag,
common.OutputFormatFlagShort,
common.OutputFormatPlain,
common.BillingIdOutputFormatFlagAllowedValuesText,
)
err := cmd.RegisterFlagCompletionFunc(common.OutputFormatFlag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return common.BillingIdOutputFormatFlagAllowedValues, cobra.ShellCompDirectiveNoFileComp
})

common.CliExit(err)
return cmd
}

func Account() *cobra.Command {
cmd := &cobra.Command{
Use: accountCommandName,
Expand Down
13 changes: 0 additions & 13 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package context

import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"path"
"strings"
Expand Down Expand Up @@ -66,17 +64,6 @@ func showAccountDetails() {
printer.Print(details)
}

func billingIdInfo() {
b, err := auth.GetBillingId()
if err != nil {
if fileError, ok := err.(*fs.PathError); ok {
common.CliExit(errors.New(fmt.Sprintf("Can't %s %s", fileError.Op, fileError.Path)))
}
}
common.CliExit(err)
printer.Print(b)
}

func listSavedEntities(p string) []string {
files, err := ioutil.ReadDir(p)

Expand Down
9 changes: 0 additions & 9 deletions pkg/context/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ func configurePrinter(command *cobra.Command) util.Printer {
allowedValues = common.ContextOutputFormatFlagAllowedValuesText
case configCommandName:
allowedValues = common.ConfigOutputFormatFlagAllowedValuesText
case billingIdInfoCommandName:
allowedValues = common.ConfigOutputFormatFlagAllowedValuesText
case accountCommandName:
allowedValues = common.ConfigOutputFormatFlagAllowedValuesText
case projectCommandName:
Expand All @@ -50,7 +48,6 @@ func availablePrinters() map[string]util.Printer {
common.OutputFormatFilepath + entityInfoCommandName: filepathPrinter{},
common.OutputFormatPlain + configCommandName: configPlainPrinter{},
common.OutputFormatJson + configCommandName: configJsonPrinter{},
common.OutputFormatPlain + billingIdInfoCommandName: billingIdPrinter{},
common.OutputFormatJsonRaw + accountCommandName: accountJsonPrinter{},
common.OutputFormatPlain + accountCommandName: accountPlainPrinter{},
common.OutputFormatPlain + projectCommandName: projectPrinter{},
Expand All @@ -64,7 +61,6 @@ type configPlainPrinter struct{}
type accountJsonPrinter struct{}
type accountPlainPrinter struct{}
type configJsonPrinter struct{}
type billingIdPrinter struct{}
type projectPrinter struct{}

func (p filepathPrinter) Print(data interface{}) {
Expand Down Expand Up @@ -94,7 +90,6 @@ func (p accountJsonPrinter) Print(data interface{}) {

func (p accountPlainPrinter) Print(data interface{}) {
entity, _ := (data).(*account.GetAccountDetailsResponse)
fmt.Println(fmt.Sprintf("billing_id: %v", entity.BillingId))
fmt.Println(fmt.Sprintf("max_input_streams: %v", entity.MaxInputStreams))
fmt.Println(fmt.Sprintf("handle: %v", entity.Handle))
fmt.Println(fmt.Sprintf("subscription: %v", entity.Subscription))
Expand Down Expand Up @@ -128,10 +123,6 @@ func (p configJsonPrinter) Print(data interface{}) {
fmt.Println(string(rawJson.Bytes()))
}

func (p billingIdPrinter) Print(data interface{}) {
fmt.Println(data)
}

func (p projectPrinter) Print(data interface{}) {
fmt.Println(data)
}
Loading

0 comments on commit a6bad5b

Please sign in to comment.