Skip to content

Commit

Permalink
fix(pkg): Flatten package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
spbsoluble committed Oct 24, 2024
1 parent df84e89 commit ae2aaf9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 64 deletions.
8 changes: 3 additions & 5 deletions auth_providers/auth_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"net/http"
"os"
"strings"

"github.com/Keyfactor/keyfactor-auth-client-go/auth_config"
)

const (
Expand Down Expand Up @@ -237,8 +235,8 @@ func (a *CommandAuthConfigBasic) parseUsernameDomain() error {
}

// GetServerConfig returns the server configuration
func (a *CommandAuthConfigBasic) GetServerConfig() *auth_config.Server {
server := auth_config.Server{
func (a *CommandAuthConfigBasic) GetServerConfig() *Server {
server := Server{
Host: a.CommandHostName,
Port: a.CommandPort,
Username: a.Username,
Expand All @@ -248,7 +246,7 @@ func (a *CommandAuthConfigBasic) GetServerConfig() *auth_config.Server {
ClientSecret: "",
OAuthTokenUrl: "",
APIPath: a.CommandAPIPath,
//AuthProvider: auth_config.AuthProvider{},
//AuthProvider: AuthProvider{},
SkipTLSVerify: a.SkipVerify,
CACertPath: a.CommandCACert,
AuthType: "basic",
Expand Down
14 changes: 6 additions & 8 deletions auth_providers/auth_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"strconv"
"strings"
"time"

authconfig "github.com/Keyfactor/keyfactor-auth-client-go/auth_config"
)

const (
Expand Down Expand Up @@ -77,7 +75,7 @@ type CommandAuthConfig struct {
ConfigFilePath string

// FileConfig
FileConfig *authconfig.Server
FileConfig *Server

// AuthHeader is the header to be used for authentication to Keyfactor Command API
AuthHeader string `json:"auth_header"`
Expand Down Expand Up @@ -519,7 +517,7 @@ func DecodePEMBytes(buf []byte) ([]*pem.Block, []byte, error) {

// LoadConfig loads the configuration file and returns the server configuration.
func (c *CommandAuthConfig) LoadConfig(profile string, configFilePath string, silentLoad bool) (
*authconfig.Server,
*Server,
error,
) {
if configFilePath == "" {
Expand Down Expand Up @@ -555,7 +553,7 @@ func (c *CommandAuthConfig) LoadConfig(profile string, configFilePath string, si
}
defer file.Close()

var config authconfig.Config
var config Config
decoder := json.NewDecoder(file)
if jErr := decoder.Decode(&config); jErr != nil {
if !silentLoad {
Expand Down Expand Up @@ -622,8 +620,8 @@ func expandPath(path string) (string, error) {
return path, nil
}

func (c *CommandAuthConfig) GetServerConfig() *authconfig.Server {
server := authconfig.Server{
func (c *CommandAuthConfig) GetServerConfig() *Server {
server := Server{
Host: c.CommandHostName,
Port: c.CommandPort,
Username: "",
Expand All @@ -633,7 +631,7 @@ func (c *CommandAuthConfig) GetServerConfig() *authconfig.Server {
ClientSecret: "",
OAuthTokenUrl: "",
APIPath: c.CommandAPIPath,
AuthProvider: authconfig.AuthProvider{},
AuthProvider: AuthProvider{},
SkipTLSVerify: c.SkipVerify,
CACertPath: c.CommandCACert,
AuthType: "",
Expand Down
9 changes: 4 additions & 5 deletions auth_providers/auth_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"time"

authconfig "github.com/Keyfactor/keyfactor-auth-client-go/auth_config"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
)
Expand Down Expand Up @@ -216,7 +215,7 @@ func (b *CommandConfigOauth) Build() (Authenticator, error) {
return &OAuthAuthenticator{Client: client}, nil
}

func (b *CommandConfigOauth) LoadConfig(profile, path string, silentLoad bool) (*authconfig.Server, error) {
func (b *CommandConfigOauth) LoadConfig(profile, path string, silentLoad bool) (*Server, error) {
serverConfig, sErr := b.CommandAuthConfig.LoadConfig(profile, path, silentLoad)
if sErr != nil {
if !silentLoad {
Expand Down Expand Up @@ -373,15 +372,15 @@ func (b *CommandConfigOauth) Authenticate() error {
return nil
}

func (b *CommandConfigOauth) GetServerConfig() *authconfig.Server {
server := authconfig.Server{
func (b *CommandConfigOauth) GetServerConfig() *Server {
server := Server{
Host: b.CommandHostName,
Port: b.CommandPort,
ClientID: b.ClientID,
ClientSecret: b.ClientSecret,
OAuthTokenUrl: b.TokenURL,
APIPath: b.CommandAPIPath,
//AuthProvider: authconfig.AuthProvider{},
//AuthProvider: AuthProvider{},
SkipTLSVerify: b.SkipVerify,
CACertPath: b.CommandCACert,
AuthType: "oauth",
Expand Down
7 changes: 3 additions & 4 deletions auth_providers/auth_oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strings"
"testing"

auth_config "github.com/Keyfactor/keyfactor-auth-client-go/auth_config"
"github.com/Keyfactor/keyfactor-auth-client-go/auth_providers"
)

Expand Down Expand Up @@ -98,7 +97,7 @@ func TestCommandConfigOauth_Authenticate(t *testing.T) {
}

configFilePath := fmt.Sprintf("%s/%s", userHome, auth_providers.DefaultConfigFilePath)
configFromFile, cErr := auth_config.ReadConfigFromJSON(configFilePath)
configFromFile, cErr := auth_providers.ReadConfigFromJSON(configFilePath)
if cErr != nil {
t.Errorf("unable to load auth config from file %s: %v", configFilePath, cErr)
}
Expand All @@ -114,7 +113,7 @@ func TestCommandConfigOauth_Authenticate(t *testing.T) {
defer func() {
// Write the config file back
t.Logf("Writing config file: %s", configFilePath)
fErr := auth_config.WriteConfigToJSON(configFilePath, configFromFile)
fErr := auth_providers.WriteConfigToJSON(configFilePath, configFromFile)
if fErr != nil {
t.Errorf("unable to write auth config to file %s: %v", configFilePath, fErr)
}
Expand Down Expand Up @@ -195,7 +194,7 @@ func TestCommandConfigOauth_Authenticate(t *testing.T) {

// Write the config file back
t.Logf("Writing config file: %s", configFilePath)
fErr := auth_config.WriteConfigToJSON(configFilePath, configFromFile)
fErr := auth_providers.WriteConfigToJSON(configFilePath, configFromFile)
if fErr != nil {
t.Errorf("unable to write auth config to file %s: %v", configFilePath, fErr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package auth_config
package auth_providers

import (
"encoding/json"
"fmt"
"os"

"gopkg.in/yaml.v2"

"github.com/Keyfactor/keyfactor-auth-client-go/auth_providers"
)

// Server represents the server configuration for authentication.
Expand Down Expand Up @@ -229,21 +227,21 @@ func (s *Server) GetAuthType() string {
}

// GetBasicAuthClientConfig returns the basic auth configuration for the client.
func (s *Server) GetBasicAuthClientConfig() (*auth_providers.CommandAuthConfigBasic, error) {
func (s *Server) GetBasicAuthClientConfig() (*CommandAuthConfigBasic, error) {
configType := s.GetAuthType()
if configType != "basic" {
return nil, fmt.Errorf("invalid auth type: %s", configType)
}

baseConfig := auth_providers.CommandAuthConfig{}
baseConfig := CommandAuthConfig{}
baseConfig.
WithCommandHostName(s.Host).
WithCommandPort(s.Port).
WithCommandAPIPath(s.APIPath).
WithCommandCACert(s.CACertPath).
WithSkipVerify(s.SkipTLSVerify)

basicConfig := auth_providers.CommandAuthConfigBasic{
basicConfig := CommandAuthConfigBasic{
CommandAuthConfig: baseConfig,
}
basicConfig.
Expand All @@ -260,20 +258,20 @@ func (s *Server) GetBasicAuthClientConfig() (*auth_providers.CommandAuthConfigBa
}

// GetOAuthClientConfig returns the OAuth configuration for the client.
func (s *Server) GetOAuthClientConfig() (*auth_providers.CommandConfigOauth, error) {
func (s *Server) GetOAuthClientConfig() (*CommandConfigOauth, error) {
configType := s.GetAuthType()
if configType != "oauth" {
return nil, fmt.Errorf("invalid auth type: %s", configType)
}
baseConfig := auth_providers.CommandAuthConfig{}
baseConfig := CommandAuthConfig{}
baseConfig.
WithCommandHostName(s.Host).
WithCommandPort(s.Port).
WithCommandAPIPath(s.APIPath).
WithCommandCACert(s.CACertPath).
WithSkipVerify(s.SkipTLSVerify)

oauthConfig := auth_providers.CommandConfigOauth{
oauthConfig := CommandConfigOauth{
CommandAuthConfig: baseConfig,
}
oauthConfig.
Expand Down
Loading

0 comments on commit ae2aaf9

Please sign in to comment.