From e7ead18bf497a64000c17e996d0f9398fcbeeae2 Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Mon, 18 Sep 2023 08:15:32 -0400 Subject: [PATCH] fix(config): use api-url instead of server-url to maintain consistency w/ sdks --- README.md | 4 ++-- cmd/root.go | 1 + internal/cmdutils/get-client-config.go | 8 ++++++-- internal/fga/fga.go | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 05110d2e..04d84cb1 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ For any command that interacts with an OpenFGA server, these configuration value | Name | Flag | CLI | ~/.fga.yaml | |------------------------|----------------------|------------------------|--------------------| -| Server Url | `--server-url` | `FGA_SERVER_URL` | `server-url` | +| API Url | `--api-url` | `FGA_API_URL` | `api-url` | | Shared Secret | `--api-token` | `FGA_API_TOKEN` | `api-token` | | Client ID | `--client-id` | `FGA_CLIENT_ID` | `client-id` | | Client Secret | `--client-secret` | `FGA_CLIENT_SECRET` | `client-secret` | @@ -148,7 +148,7 @@ If you are authenticating with a shared secret, you should specify the API Token ``` # Note: This example is for Auth0 FGA -server-url: https://api.us1.fga.dev +api-url: https://api.us1.fga.dev client-id: 4Zb..UYjaHreLKOJuU8 client-secret: J3...2pBwiauD api-audience: https://api.us1.fga.dev/ diff --git a/cmd/root.go b/cmd/root.go index 3e04b694..f8a635ee 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -56,6 +56,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.fga.yaml)") rootCmd.PersistentFlags().String("server-url", "http://localhost:8080", "OpenFGA API URI e.g. https://api.fga.example:8080") //nolint:lll + rootCmd.PersistentFlags().String("api-url", "", "OpenFGA API URI e.g. https://api.fga.example:8080") //nolint:lll rootCmd.PersistentFlags().String("api-token", "", "API Token. Will be sent in as a Bearer in the Authorization header") rootCmd.PersistentFlags().String("api-token-issuer", "", "API Token Issuer. API responsible for issuing the API Token. Used in the Client Credentials flow") //nolint:lll rootCmd.PersistentFlags().String("api-audience", "", "API Audience. Used when performing the Client Credentials flow") diff --git a/internal/cmdutils/get-client-config.go b/internal/cmdutils/get-client-config.go index 6d625e5d..ff1bf323 100644 --- a/internal/cmdutils/get-client-config.go +++ b/internal/cmdutils/get-client-config.go @@ -22,7 +22,11 @@ import ( ) func GetClientConfig(cmd *cobra.Command) fga.ClientConfig { - serverURL, _ := cmd.Flags().GetString("server-url") + apiURL, _ := cmd.Flags().GetString("api-url") + if apiURL == "" { + apiURL, _ = cmd.Flags().GetString("server-url") + } + storeID, _ := cmd.Flags().GetString("store-id") authorizationModelID, _ := cmd.Flags().GetString("model-id") apiToken, _ := cmd.Flags().GetString("api-token") @@ -32,7 +36,7 @@ func GetClientConfig(cmd *cobra.Command) fga.ClientConfig { clientCredentialsClientSecret, _ := cmd.Flags().GetString("client-secret") return fga.ClientConfig{ - ServerURL: serverURL, + ApiURL: apiURL, StoreID: storeID, AuthorizationModelID: authorizationModelID, APIToken: apiToken, diff --git a/internal/fga/fga.go b/internal/fga/fga.go index b0d9c313..6439c7f1 100644 --- a/internal/fga/fga.go +++ b/internal/fga/fga.go @@ -29,6 +29,7 @@ import ( var userAgent = "openfga-cli/" + build.Version type ClientConfig struct { + ApiURL string `json:"api_url,omitempty"` ServerURL string `json:"server_url,omitempty"` StoreID string `json:"store_id,omitempty"` AuthorizationModelID string `json:"authorization_model_id,omitempty"` @@ -67,7 +68,7 @@ func (c ClientConfig) getCredentials() *credentials.Credentials { } func (c ClientConfig) getClientConfig() (*client.ClientConfiguration, error) { - apiURIParts, err := url.Parse(c.ServerURL) + apiURIParts, err := url.Parse(c.ApiURL) if err != nil { return nil, err //nolint:wrapcheck }