Skip to content

Commit

Permalink
Feat: Add config SSO option (#377) and bump version (#396)
Browse files Browse the repository at this point in the history
* Feat: Add config SSO option (#377)

* added sso style entry

* style to type for SSO

* setBasicAuth

* Win unit test (#355)

* Fixed unit tests so they work in windows environments

* Removed dead imports

* adding Connection close header in http requests of our golang client (#372)

Co-authored-by: Anupam Pokharel <[email protected]>

* Adds PrintCsv() function and unit tests to bluemix/terminal/table (#352)

* added PrintCsv() function and unit tests to bluemix/terminal/table

* Added handled errors to function PrintCsv

* Added unit test for empty table in function PrintCsv

* Added translations for error message and returned it

---------

Co-authored-by: Aerex <[email protected]>

* chore: add csv messages to i18n (#373)

* chore: bump version to 1.1.0 (#374)

* Add recommendation to use Cobra (#368)

* Add recommendation to use Cobra

* dummy commit

---------

Co-authored-by: steveclay <[email protected]>

* chore: bump packages for vulnerabilities (#376)

* docs: added building section for building architectures

* docs: improved description on building architectures

* docs: Removed extraneous info for  architecture requirements

* chore(security): resolved vulnerability by updating golang.org/x/net

* chore: bumped to 1.1.1 (#380)

---------

Co-authored-by: Anupam Pokharel <[email protected]>
Co-authored-by: Christopher Gallo <[email protected]>
Co-authored-by: edsonarios <[email protected]>
Co-authored-by: Aerex <[email protected]>
Co-authored-by: steveclay <[email protected]>
Co-authored-by: lmosca <[email protected]>

* bump version (#398)

---------

Co-authored-by: Anupam Pokharel <[email protected]>
Co-authored-by: Christopher Gallo <[email protected]>
Co-authored-by: edsonarios <[email protected]>
Co-authored-by: Aerex <[email protected]>
Co-authored-by: steveclay <[email protected]>
Co-authored-by: lmosca <[email protected]>
  • Loading branch information
7 people authored Mar 14, 2024
1 parent 2346bb3 commit 3328259
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 33 deletions.
14 changes: 14 additions & 0 deletions bluemix/configuration/core_config/bx_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type BXConfigData struct {
Trace string
ColorEnabled string
HTTPTimeout int
TypeOfSSO string
CLIInfoEndpoint string // overwrite the cli info endpoint
CheckCLIVersionDisabled bool
UsageStatsDisabled bool // deprecated: use UsageStatsEnabled
Expand Down Expand Up @@ -412,6 +413,13 @@ func (c *bxConfig) ColorEnabled() (enabled string) {
return
}

func (c *bxConfig) TypeOfSSO() (style string) {
c.read(func() {
style = c.data.TypeOfSSO
})
return
}

func (c *bxConfig) HTTPTimeout() (timeout int) {
c.read(func() {
timeout = c.data.HTTPTimeout
Expand Down Expand Up @@ -639,6 +647,12 @@ func (c *bxConfig) SetHTTPTimeout(timeout int) {
})
}

func (c *bxConfig) SetTypeOfSSO(style string) {
c.write(func() {
c.data.TypeOfSSO = style
})
}

func (c *bxConfig) SetCheckCLIVersionDisabled(disabled bool) {
c.write(func() {
c.data.CheckCLIVersionDisabled = disabled
Expand Down
2 changes: 2 additions & 0 deletions bluemix/configuration/core_config/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Repository interface {
PluginRepos() []models.PluginRepo
PluginRepo(string) (models.PluginRepo, bool)
IsSSLDisabled() bool
TypeOfSSO() string
HTTPTimeout() int
CLIInfoEndpoint() string
CheckCLIVersionDisabled() bool
Expand Down Expand Up @@ -99,6 +100,7 @@ type Repository interface {
SetPluginRepo(models.PluginRepo)
UnsetPluginRepo(string)
SetSSLDisabled(bool)
SetTypeOfSSO(string)
SetHTTPTimeout(int)
// SetUsageSatsDisabled disable or enable usage statistics data collection
// Deprecated: use SetUsageSatsEnabled instead
Expand Down
2 changes: 1 addition & 1 deletion bluemix/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bluemix
import "fmt"

// Version is the SDK version
var Version = VersionType{Major: 1, Minor: 2, Build: 0}
var Version = VersionType{Major: 1, Minor: 3, Build: 0}

// VersionType describe version info
type VersionType struct {
Expand Down
84 changes: 52 additions & 32 deletions common/rest/request.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
// Request examples:
// // create a simple GET request
// req := GetRequest("http://www.example.com")
//
// // set header
// req.Set("Accept", "application/json")
// // create a simple GET request
// req := GetRequest("http://www.example.com")
//
// // set query parameters
// req.Query("foo1", "bar1")
// req.Query("foo2", "bar2")
// // set header
// req.Set("Accept", "application/json")
//
// // Build to a HTTP request
// req.Build()
// // set query parameters
// req.Query("foo1", "bar1")
// req.Query("foo2", "bar2")
//
// // method chaining is also supported
// // the above is equal to:
// GetRequest("http://www.example.com").
// Set("Accept", "application/json").
// Query("foo1", "bar1").
// Query("foo2", "bar2").
// Build()
// // Build to a HTTP request
// req.Build()
//
// // struct body
// foo = Foo{Bar: "val"}
// PostRequest("http://www.example.com").
// Body(foo)
// // method chaining is also supported
// // the above is equal to:
// GetRequest("http://www.example.com").
// Set("Accept", "application/json").
// Query("foo1", "bar1").
// Query("foo2", "bar2").
// Build()
//
// // String body
// PostRequest("http://www.example.com").
// Body("{\"bar\": \"val\"}")
// // struct body
// foo = Foo{Bar: "val"}
// PostRequest("http://www.example.com").
// Body(foo)
//
// // Stream body
// PostRequest("http://www.example.com").
// Body(strings.NewReader("abcde"))
// // String body
// PostRequest("http://www.example.com").
// Body("{\"bar\": \"val\"}")
//
// // Multipart POST request
// var f *os.File
// PostRequest("http://www.example.com").
// Field("foo", "bar").
// File("file1", File{Name: f.Name(), Content: f}).
// File("file2", File{Name: "1.txt", Content: []byte("abcde"), Type: "text/plain"})
// // Stream body
// PostRequest("http://www.example.com").
// Body(strings.NewReader("abcde"))
//
// // Multipart POST request
// var f *os.File
// PostRequest("http://www.example.com").
// Field("foo", "bar").
// File("file1", File{Name: f.Name(), Content: f}).
// File("file2", File{Name: "1.txt", Content: []byte("abcde"), Type: "text/plain"})
package rest

import (
Expand Down Expand Up @@ -79,13 +80,20 @@ type Request struct {
queryParams url.Values
formParams url.Values

basicAuthn *BasicAuthInfo

// files to upload
files map[string][]File

// custom request body
body interface{}
}

type BasicAuthInfo struct {
user string
pass string
}

// NewRequest creates a new request with a given rawUrl.
func NewRequest(rawUrl string) *Request {
return &Request{
Expand Down Expand Up @@ -165,6 +173,14 @@ func (r *Request) Set(key string, value string) *Request {
return r
}

func (r *Request) SetBasicAuth(user string, pass string) *Request {
r.basicAuthn = &BasicAuthInfo{
user: user,
pass: pass,
}
return r
}

// Query appends the key, value pair to the request query which will be
// encoded as url query parameters on HTTP request's url.
func (r *Request) Query(key string, value string) *Request {
Expand Down Expand Up @@ -210,6 +226,10 @@ func (r *Request) Build() (*http.Request, error) {
return req, err
}

if r.basicAuthn != nil {
req.SetBasicAuth(r.basicAuthn.user, r.basicAuthn.pass)
}

for k, vs := range r.header {
for _, v := range vs {
req.Header.Add(k, v)
Expand Down

0 comments on commit 3328259

Please sign in to comment.