Skip to content

Commit

Permalink
feat: allow specifying port and url in go-sdk, update readme in all s…
Browse files Browse the repository at this point in the history
…dks (#248)
  • Loading branch information
rhamzeh authored Dec 6, 2023
2 parents fd1873b + 86af2cd commit e548df8
Show file tree
Hide file tree
Showing 17 changed files with 349 additions and 272 deletions.
34 changes: 17 additions & 17 deletions config/clients/dotnet/template/README_initializing.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Example {
public static async Task Main() {
try {
var configuration = new ClientConfiguration() {
ApiScheme = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_SCHEME"), // optional, defaults to "https"
ApiHost = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_HOST"), // required, define without the scheme (e.g. api.fga.example instead of https://api.fga.example)
StoreId = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
AuthorizationModelId = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_AUTHORIZATION_MODEL_ID"), // Optional, can be overridden per request
ApiScheme = Environment.GetEnvironmentVariable("FGA_API_SCHEME"), // optional, defaults to "https"
ApiHost = Environment.GetEnvironmentVariable("FGA_API_HOST"), // required, define without the scheme (e.g. api.{{sampleApiDomain}} instead of https://api.{{sampleApiDomain}})
StoreId = Environment.GetEnvironmentVariable("FGA_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
AuthorizationModelId = Environment.GetEnvironmentVariable("FGA_AUTHORIZATION_MODEL_ID"), // Optional, can be overridden per request
};
var fgaClient = new {{appShortName}}Client(configuration);
var response = await fgaClient.ReadAuthorizationModels();
Expand All @@ -41,14 +41,14 @@ namespace Example {
public static async Task Main() {
try {
var configuration = new ClientConfiguration() {
ApiScheme = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_SCHEME"), // optional, defaults to "https"
ApiHost = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_HOST"), // required, define without the scheme (e.g. api.fga.example instead of https://api.fga.example)
StoreId = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
AuthorizationModelId = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_AUTHORIZATION_MODEL_ID"), // Optional, can be overridden per request
ApiScheme = Environment.GetEnvironmentVariable("FGA_API_SCHEME"), // optional, defaults to "https"
ApiHost = Environment.GetEnvironmentVariable("FGA_API_HOST"), // required, define without the scheme (e.g. api.{{sampleApiDomain}} instead of https://api.{{sampleApiDomain}})
StoreId = Environment.GetEnvironmentVariable("FGA_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
AuthorizationModelId = Environment.GetEnvironmentVariable("FGA_AUTHORIZATION_MODEL_ID"), // Optional, can be overridden per request
Credentials = new Credentials() {
Method = CredentialsMethod.ApiToken,
Config = new CredentialsConfig() {
ApiToken = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_TOKEN"), // will be passed as the "Authorization: Bearer ${ApiToken}" request header
ApiToken = Environment.GetEnvironmentVariable("FGA_API_TOKEN"), // will be passed as the "Authorization: Bearer ${ApiToken}" request header
}
}
};
Expand All @@ -74,17 +74,17 @@ namespace Example {
public static async Task Main() {
try {
var configuration = new ClientConfiguration() {
ApiScheme = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_SCHEME"), // optional, defaults to "https"
ApiHost = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_HOST"), // required, define without the scheme (e.g. api.fga.example instead of https://api.fga.example)
StoreId = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
AuthorizationModelId = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_AUTHORIZATION_MODEL_ID"), // Optional, can be overridden per request
ApiScheme = Environment.GetEnvironmentVariable("FGA_API_SCHEME"), // optional, defaults to "https"
ApiHost = Environment.GetEnvironmentVariable("FGA_API_HOST"), // required, define without the scheme (e.g. api.{{sampleApiDomain}} instead of https://api.{{sampleApiDomain}})
StoreId = Environment.GetEnvironmentVariable("FGA_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
AuthorizationModelId = Environment.GetEnvironmentVariable("FGA_AUTHORIZATION_MODEL_ID"), // Optional, can be overridden per request
Credentials = new Credentials() {
Method = CredentialsMethod.ClientCredentials,
Config = new CredentialsConfig() {
ApiTokenIssuer = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_TOKEN_ISSUER"),
ApiAudience = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_API_AUDIENCE"),
ClientId = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_CLIENT_ID"),
ClientSecret = Environment.GetEnvironmentVariable("{{appUpperCaseName}}_CLIENT_SECRET"),
ApiTokenIssuer = Environment.GetEnvironmentVariable("FGA_API_TOKEN_ISSUER"),
ApiAudience = Environment.GetEnvironmentVariable("FGA_API_AUDIENCE"),
ClientId = Environment.GetEnvironmentVariable("FGA_CLIENT_ID"),
ClientSecret = Environment.GetEnvironmentVariable("FGA_CLIENT_SECRET"),
}
}
};
Expand Down
27 changes: 12 additions & 15 deletions config/clients/go/template/README_initializing.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import (

func main() {
fgaClient, err := NewSdkClient(&ClientConfiguration{
ApiScheme: os.Getenv("{{appUpperCaseName}}_API_SCHEME"), // optional, defaults to "https"
ApiHost: os.Getenv("{{appUpperCaseName}}_API_HOST"), // required, define without the scheme (e.g. api.fga.example instead of https://api.fga.example)
StoreId: os.Getenv("{{appUpperCaseName}}_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
ApiUrl: os.Getenv("FGA_API_URL"), // required, e.g. https://api.{{sampleApiDomain}}
StoreId: os.Getenv("FGA_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
})

if err != nil {
Expand All @@ -34,13 +33,12 @@ import (

func main() {
fgaClient, err := NewSdkClient(&ClientConfiguration{
ApiScheme: os.Getenv("{{appUpperCaseName}}_API_SCHEME"), // optional, defaults to "https"
ApiHost: os.Getenv("{{appUpperCaseName}}_API_HOST"), // required, define without the scheme (e.g. api.fga.example instead of https://api.fga.example)
StoreId: os.Getenv("{{appUpperCaseName}}_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
ApiUrl: os.Getenv("FGA_API_URL"), // required, e.g. https://api.{{sampleApiDomain}}
StoreId: os.Getenv("FGA_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
Credentials: &credentials.Credentials{
Method: credentials.CredentialsMethodApiToken,
Config: &credentials.Config{
ApiToken: os.Getenv("{{appUpperCaseName}}_API_TOKEN"), // will be passed as the "Authorization: Bearer ${ApiToken}" request header
ApiToken: os.Getenv("FGA_API_TOKEN"), // will be passed as the "Authorization: Bearer ${ApiToken}" request header
},
},
})
Expand All @@ -63,17 +61,16 @@ import (

func main() {
fgaClient, err := NewSdkClient(&ClientConfiguration{
ApiScheme: os.Getenv("{{appUpperCaseName}}_API_SCHEME"), // optional, defaults to "https"
ApiHost: os.Getenv("{{appUpperCaseName}}_API_HOST"), // required, define without the scheme (e.g. api.fga.example instead of https://api.fga.example)
StoreId: os.Getenv("{{appUpperCaseName}}_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
AuthorizationModelId: {{packageName}}.PtrString("{{appUpperCaseName}}_AUTHORIZATION_MODEL_ID"),
ApiUrl: os.Getenv("FGA_API_URL"), // required, e.g. https://api.{{sampleApiDomain}}
StoreId: os.Getenv("FGA_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
AuthorizationModelId: {{packageName}}.PtrString("{{appUpperCaseName}}_AUTHORIZATION_MODEL_ID"),
Credentials: &credentials.Credentials{
Method: credentials.CredentialsMethodClientCredentials,
Config: &credentials.Config{
ClientCredentialsClientId: os.Getenv("{{appUpperCaseName}}_CLIENT_ID"),
ClientCredentialsClientSecret: os.Getenv("{{appUpperCaseName}}_CLIENT_SECRET"),
ClientCredentialsApiAudience: os.Getenv("{{appUpperCaseName}}_API_AUDIENCE"),
ClientCredentialsApiTokenIssuer: os.Getenv("{{appUpperCaseName}}_API_TOKEN_ISSUER"),
ClientCredentialsClientId: os.Getenv("FGA_CLIENT_ID"),
ClientCredentialsClientSecret: os.Getenv("FGA_CLIENT_SECRET"),
ClientCredentialsApiAudience: os.Getenv("FGA_API_AUDIENCE"),
ClientCredentialsApiTokenIssuer: os.Getenv("FGA_API_TOKEN_ISSUER"),
},
},
})
Expand Down
20 changes: 5 additions & 15 deletions config/clients/go/template/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -242,37 +242,27 @@ func (c *APIClient) prepareRequest(
}

// Setup path and query parameters
url, err := url.Parse(path)
uri, err := url.Parse(c.cfg.ApiUrl + path)
if err != nil {
return nil, err
}

// Override request host, if applicable
if c.cfg.ApiHost != "" {
url.Host = c.cfg.ApiHost
}

// Override request scheme, if applicable
if c.cfg.ApiScheme != "" {
url.Scheme = c.cfg.ApiScheme
}

// Adding Query Param
query := url.Query()
query := uri.Query()
for k, v := range queryParams {
for _, iv := range v {
query.Add(k, iv)
}
}

// Encode the parameters.
url.RawQuery = query.Encode()
uri.RawQuery = query.Encode()

// Generate a new request
if body != nil {
localVarRequest, err = http.NewRequest(method, url.String(), body)
localVarRequest, err = http.NewRequest(method, uri.String(), body)
} else {
localVarRequest, err = http.NewRequest(method, url.String(), nil)
localVarRequest, err = http.NewRequest(method, uri.String(), nil)
}
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions config/clients/go/template/api_doc.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ func main() {
{{/allParams}}

configuration, err := {{packageName}}.NewConfiguration({{packageName}}.Configuration{
ApiScheme: os.Getenv("{{appUpperCaseName}}_API_SCHEME"), // optional, defaults to "https"
ApiHost: os.Getenv("{{appUpperCaseName}}_API_HOST"), // required, define without the scheme (e.g. api.{{sampleApiDomain}} instead of https://api.{{sampleApiDomain}})
ApiUrl: os.Getenv("FGA_API_URL"), // required, e.g. https://api.{{sampleApiDomain}}
StoreId: os.Getenv("{{appUpperCaseName}}_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
})

Expand Down
Loading

0 comments on commit e548df8

Please sign in to comment.