-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for dynamic config url (#1565)
- Loading branch information
Showing
12 changed files
with
148 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
pkg/cmd/serviceaccount/svcaccountcmdutil/svcaccount_util.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
package svcaccountcmdutil | ||
|
||
import "github.com/redhat-developer/app-services-cli/pkg/cmd/serviceaccount/svcaccountcmdutil/credentials" | ||
import ( | ||
"context" | ||
|
||
"github.com/redhat-developer/app-services-cli/pkg/cmd/serviceaccount/svcaccountcmdutil/credentials" | ||
"github.com/redhat-developer/app-services-cli/pkg/shared/connection" | ||
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client" | ||
) | ||
|
||
var ( | ||
CredentialsOutputFormats = []string{credentials.EnvFormat, credentials.JSONFormat, credentials.PropertiesFormat} | ||
) | ||
|
||
// Method fetches authentication details for providers | ||
func GetProvidersDetails(conn connection.Connection, context context.Context) (*kafkamgmtclient.SsoProvider, error) { | ||
providers, httpRes, err := conn.API(). | ||
ServiceAccountMgmt().GetSsoProviders(context).Execute() | ||
|
||
if httpRes != nil { | ||
defer httpRes.Body.Close() | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &providers, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package hacks | ||
|
||
// Temporary hack package | ||
// Nothing to see here | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/redhat-developer/app-services-cli/pkg/core/logging" | ||
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client" | ||
) | ||
|
||
// Temporary hack that we use to determine if | ||
// Our CLI needs to use mas-sso token | ||
func ShouldUseMasSSO(logger logging.Logger, apiUrl string) bool { | ||
req, err := http.NewRequest("GET", apiUrl+"/api/kafkas_mgmt/v1/sso_providers", nil) | ||
if err != nil { | ||
logger.Debug("Error when fetching auth config", err) | ||
return true | ||
} | ||
|
||
req = req.WithContext(context.Background()) | ||
|
||
req.Header.Set("Accept", "application/json") | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
logger.Debug("Error when fetching auth config", err) | ||
return true | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
b, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
logger.Debug("Error when fetching auth config", err) | ||
return true | ||
} | ||
|
||
response := string(b) | ||
|
||
// defining a struct instance | ||
var provider *kafkamgmtclient.SsoProvider | ||
|
||
responseBytes := []byte(fmt.Sprintf("%v", response)) | ||
err = json.Unmarshal(responseBytes, &provider) | ||
if err != nil { | ||
logger.Debug("Error when fetching auth config", err) | ||
return true | ||
} | ||
|
||
if provider.GetBaseUrl() == "" { | ||
logger.Debug("Error when fetching auth config", err) | ||
return true | ||
} | ||
|
||
return provider.GetName() == "mas_sso" | ||
} |