Skip to content

Commit

Permalink
fix(config): use api-url instead of server-url to maintain consistenc…
Browse files Browse the repository at this point in the history
…y w/ sdks
  • Loading branch information
rhamzeh committed Sep 18, 2023
1 parent db6f866 commit e7ead18
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand All @@ -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/
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions internal/cmdutils/get-client-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion internal/fga/fga.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
var userAgent = "openfga-cli/" + build.Version

type ClientConfig struct {
ApiURL string `json:"api_url,omitempty"`

Check warning on line 32 in internal/fga/fga.go

View workflow job for this annotation

GitHub Actions / Lints

var-naming: struct field ApiURL should be APIURL (revive)

Check warning on line 32 in internal/fga/fga.go

View workflow job for this annotation

GitHub Actions / Lints

var-naming: struct field ApiURL should be APIURL (revive)
ServerURL string `json:"server_url,omitempty"`
StoreID string `json:"store_id,omitempty"`
AuthorizationModelID string `json:"authorization_model_id,omitempty"`
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit e7ead18

Please sign in to comment.