Skip to content

Commit

Permalink
fix: rename appId to clientId (#155)
Browse files Browse the repository at this point in the history
* fix: rename appId to clientId

* fix: using clientID instead of clientId
  • Loading branch information
adilansari committed Sep 22, 2022
1 parent 91c39e1 commit 9caad1c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions config/config.go
Expand Up @@ -19,11 +19,11 @@ import "crypto/tls"

// Driver contains connection and transport configuration
type Driver struct {
TLS *tls.Config `json:"tls,omitempty"`
ApplicationId string `json:"application_id,omitempty"`
ApplicationSecret string `json:"application_secret,omitempty"`
Token string `json:"token,omitempty"`
URL string `json:"url,omitempty"`
TLS *tls.Config `json:"tls,omitempty"`
ClientID string `json:"client_id,omitempty"`
ClientSecret string `json:"client_secret,omitempty"`
Token string `json:"token,omitempty"`
URL string `json:"url,omitempty"`
}

// Database contains database and connection config
Expand Down
2 changes: 1 addition & 1 deletion driver/driver.go
Expand Up @@ -285,7 +285,7 @@ func initConfig(cfg *config.Driver) *config.Driver {
cfg = &config.Driver{}
}

if cfg.TLS == nil && (cfg.ApplicationId != "" || cfg.ApplicationSecret != "" || cfg.Token != "") {
if cfg.TLS == nil && (cfg.ClientID != "" || cfg.ClientSecret != "" || cfg.Token != "") {
cfg.TLS = &tls.Config{MinVersion: tls.VersionTLS12}
}

Expand Down
2 changes: 1 addition & 1 deletion driver/driver_test.go
Expand Up @@ -1009,7 +1009,7 @@ func TestNewDriver(t *testing.T) {
_, err = NewDriver(context.Background(), nil)
require.Error(t, err)

cfg1 := &config.Driver{URL: test.GRPCURL(4), ApplicationSecret: "aaaa"}
cfg1 := &config.Driver{URL: test.GRPCURL(4), ClientSecret: "aaaa"}
cfg1 = initConfig(cfg1)
require.NotNil(t, cfg1.TLS)
}
Expand Down
8 changes: 4 additions & 4 deletions driver/grpc.go
Expand Up @@ -464,7 +464,7 @@ func (c *grpcDriver) ListApplications(ctx context.Context) ([]*Application, erro
return applications, nil
}

func (c *grpcDriver) RotateApplicationSecret(ctx context.Context, id string) (*Application, error) {
func (c *grpcDriver) RotateClientSecret(ctx context.Context, id string) (*Application, error) {
r, err := c.mgmt.RotateApplicationSecret(ctx, &api.RotateApplicationSecretRequest{Id: id})
if err != nil {
return nil, GRPCError(err)
Expand All @@ -477,7 +477,7 @@ func (c *grpcDriver) RotateApplicationSecret(ctx context.Context, id string) (*A
return (*Application)(r.Application), nil
}

func (c *grpcDriver) GetAccessToken(ctx context.Context, applicationID string, applicationSecret string, refreshToken string) (*TokenResponse, error) {
func (c *grpcDriver) GetAccessToken(ctx context.Context, clientId string, clientSecret string, refreshToken string) (*TokenResponse, error) {
tp := api.GrantType_CLIENT_CREDENTIALS
if refreshToken != "" {
tp = api.GrantType_REFRESH_TOKEN
Expand All @@ -486,8 +486,8 @@ func (c *grpcDriver) GetAccessToken(ctx context.Context, applicationID string, a
r, err := c.auth.GetAccessToken(ctx, &api.GetAccessTokenRequest{
GrantType: tp,
RefreshToken: refreshToken,
ClientId: applicationID,
ClientSecret: applicationSecret,
ClientId: clientId,
ClientSecret: clientSecret,
})
if err != nil {
return nil, GRPCError(err)
Expand Down
14 changes: 7 additions & 7 deletions driver/http.go
Expand Up @@ -718,7 +718,7 @@ func (c *httpDriver) ListApplications(ctx context.Context) ([]*Application, erro
return apps.Applications, nil
}

func (c *httpDriver) RotateApplicationSecret(ctx context.Context, id string) (*Application, error) {
func (c *httpDriver) RotateClientSecret(ctx context.Context, id string) (*Application, error) {
resp, err := c.api.ManagementRotateApplicationSecret(ctx, apiHTTP.ManagementRotateApplicationSecretJSONBody{Id: &id})
if err := HTTPError(err, resp); err != nil {
return nil, err
Expand All @@ -735,21 +735,21 @@ func (c *httpDriver) RotateApplicationSecret(ctx context.Context, id string) (*A
return &app.Application, nil
}

func (c *httpDriver) GetAccessToken(ctx context.Context, applicationID string, applicationSecret string, refreshToken string) (*TokenResponse, error) {
return getAccessToken(ctx, c.tokenURL, c.cfg, applicationID, applicationSecret, refreshToken)
func (c *httpDriver) GetAccessToken(ctx context.Context, clientId string, clientSecret string, refreshToken string) (*TokenResponse, error) {
return getAccessToken(ctx, c.tokenURL, c.cfg, clientId, clientSecret, refreshToken)
}

func getAccessToken(ctx context.Context, tokenURL string, cfg *config.Driver, applicationID string, applicationSecret string, refreshToken string) (*TokenResponse, error) {
func getAccessToken(ctx context.Context, tokenURL string, cfg *config.Driver, clientId string, clientSecret string, refreshToken string) (*TokenResponse, error) {
data := url.Values{
"client_id": {applicationID},
"client_secret": {applicationSecret},
"client_id": {clientId},
"client_secret": {clientSecret},
"grant_type": {grantTypeClientCredentials},
"scope": {scope},
}
if refreshToken != "" {
data = url.Values{
"refresh_token": {refreshToken},
"client_id": {applicationID},
"client_id": {clientId},
"grant_type": {grantTypeRefreshToken},
"scope": {scope},
}
Expand Down
12 changes: 6 additions & 6 deletions driver/internal.go
Expand Up @@ -60,14 +60,14 @@ type txWithOptions interface {

//func configAuth(config *config.Driver) (*clientcredentials.Config, context.Context) {
func configAuth(config *config.Driver) (oauth2.TokenSource, *http.Client, string) {
appID := config.ApplicationId
clientId := config.ClientID
if os.Getenv(ApplicationID) != "" {
appID = os.Getenv(ApplicationID)
clientId = os.Getenv(ApplicationID)
}

appSecret := config.ApplicationSecret
clientSecret := config.ClientSecret
if os.Getenv(ApplicationSecret) != "" {
appSecret = os.Getenv(ApplicationSecret)
clientSecret = os.Getenv(ApplicationSecret)
}

token := config.Token
Expand Down Expand Up @@ -101,8 +101,8 @@ func configAuth(config *config.Driver) (oauth2.TokenSource, *http.Client, string
ocfg1 := &oauth2.Config{Endpoint: oauth2.Endpoint{TokenURL: tokenURL}}
client = ocfg1.Client(ctxClient, t)
ts = ocfg1.TokenSource(ctxClient, t)
} else if appID != "" || appSecret != "" {
oCfg := &clientcredentials.Config{TokenURL: tokenURL, ClientID: appID, ClientSecret: appSecret, AuthStyle: oauth2.AuthStyleInParams}
} else if clientId != "" || clientSecret != "" {
oCfg := &clientcredentials.Config{TokenURL: tokenURL, ClientID: clientId, ClientSecret: clientSecret, AuthStyle: oauth2.AuthStyleInParams}
client = oCfg.Client(ctxClient)
ts = oCfg.TokenSource(ctxClient)
}
Expand Down
4 changes: 2 additions & 2 deletions driver/management.go
Expand Up @@ -13,8 +13,8 @@ type Management interface {
DeleteApplication(ctx context.Context, id string) error
UpdateApplication(ctx context.Context, id string, name string, description string) (*Application, error)
ListApplications(ctx context.Context) ([]*Application, error)
RotateApplicationSecret(ctx context.Context, id string) (*Application, error)
GetAccessToken(ctx context.Context, applicationID string, applicationSecret string, refreshToken string) (*TokenResponse, error)
RotateClientSecret(ctx context.Context, id string) (*Application, error)
GetAccessToken(ctx context.Context, clientId string, clientSecret string, refreshToken string) (*TokenResponse, error)

Close() error
}
Expand Down
16 changes: 8 additions & 8 deletions driver/management_test.go
Expand Up @@ -52,7 +52,7 @@ func testDriverAuthNegative(t *testing.T, c Management, mc *mock.MockManagementS
pm(&api.RotateApplicationSecretRequest{Id: "ras_id1"})).Return(
&api.RotateApplicationSecretResponse{Application: nil}, nil)

_, err = c.RotateApplicationSecret(ctx, "ras_id1")
_, err = c.RotateClientSecret(ctx, "ras_id1")
require.Error(t, err)
}

Expand Down Expand Up @@ -117,7 +117,7 @@ func testDriverAuth(t *testing.T, c Management, mc *mock.MockManagementServer, m
pm(&api.RotateApplicationSecretRequest{Id: "ras_id1"})).Return(
&api.RotateApplicationSecretResponse{Application: lapp2}, nil)

app, err = c.RotateApplicationSecret(ctx, "ras_id1")
app, err = c.RotateClientSecret(ctx, "ras_id1")
require.NoError(t, err)

appEqual(t, lapp2, app)
Expand Down Expand Up @@ -208,9 +208,9 @@ func TestGRPCDriverCredentials(t *testing.T) {
t.Run("config", func(t *testing.T) {
TokenURLOverride = testTokenURLOverride
client, _, mockServers, cancel := SetupMgmtGRPCTests(t, &config.Driver{
URL: test.GRPCURL(0),
ApplicationId: "client_id_test",
ApplicationSecret: "client_secret_test",
URL: test.GRPCURL(0),
ClientID: "client_id_test",
ClientSecret: "client_secret_test",
})
defer cancel()

Expand Down Expand Up @@ -249,9 +249,9 @@ func TestHTTPDriverCredentials(t *testing.T) {
t.Run("config", func(t *testing.T) {
TokenURLOverride = ""
client, _, mockServers, cancel := SetupMgmtHTTPTests(t, &config.Driver{
URL: test.HTTPURL(2),
ApplicationId: "client_id_test",
ApplicationSecret: "client_secret_test",
URL: test.HTTPURL(2),
ClientID: "client_id_test",
ClientSecret: "client_secret_test",
})
defer cancel()

Expand Down

0 comments on commit 9caad1c

Please sign in to comment.