Skip to content

Commit

Permalink
Merge pull request #2983 from vmware/jenkins_sync_30.2.2_go
Browse files Browse the repository at this point in the history
Auto updated assets for go models and clients 30.2.2
  • Loading branch information
mkhachane authored Sep 9, 2024
2 parents 58fcdf2 + 1e12bb2 commit c0250d4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go/models/c_c_vnic_info.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/models/server_auto_scale_failed_info.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/models/server_auto_scale_in_complete_info.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/models/server_auto_scale_in_info.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/models/server_auto_scale_out_complete_info.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/models/server_auto_scale_out_info.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/models/v_center_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type VCenterConfiguration struct {
// Datacenter for virtual infrastructure discovery. Allowed in Enterprise edition with any value, Essentials, Basic, Enterprise with Cloud Services edition.
Datacenter *string `json:"datacenter,omitempty"`

// Managed object id of the datacenter. Field introduced in 30.2.1. Allowed in Enterprise edition with any value, Enterprise with Cloud Services edition.
// Managed object id of the datacenter. Field introduced in 30.2.1. Allowed in Enterprise edition with any value, Essentials edition with any value, Enterprise with Cloud Services edition.
DatacenterManagedObjectID *string `json:"datacenter_managed_object_id,omitempty"`

// If true, VM's on the vCenter will not be discovered.Set it to true if there are more than 10000 VMs in the datacenter. Field deprecated in 30.1.1. Field introduced in 20.1.5. Allowed in Enterprise edition with any value, Enterprise with Cloud Services edition.
Expand Down
39 changes: 28 additions & 11 deletions go/session/avisession.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ type AviSession struct {

// internal: variable to store generated csp access token
CSP_ACCESS_TOKEN string

// Defines the protocol to be used by the session
scheme string
}

const DEFAULT_AVI_VERSION = "18.2.6"
Expand All @@ -314,15 +317,9 @@ func NewAviSession(host string, username string, options ...func(*AviSession) er
avisess.sessionid = ""
avisess.csrfToken = ""

avisess.prefix = "https://" + avisess.host + "/"

ip := GetIPVersion(avisess.host)
if ip != nil && ip.To4() == nil {
avisess.prefix = fmt.Sprintf("https://[%s]/", avisess.host)
}

avisess.tenant = ""
avisess.insecure = false
avisess.scheme = "https"
// The default behaviour was for 10 iterations, if client does not init session with specific retry
// count option the controller status will be checked 10 times.
avisess.ctrlStatusCheckRetryCount = 10
Expand All @@ -333,6 +330,13 @@ func NewAviSession(host string, username string, options ...func(*AviSession) er
}
}

avisess.prefix = fmt.Sprintf("%s://%s/", avisess.scheme, avisess.host)

ip := GetIPVersion(avisess.host)
if ip != nil && ip.To4() == nil {
avisess.prefix = fmt.Sprintf("%s://[%s]/", avisess.scheme, avisess.host)
}

if avisess.tenant == "" {
avisess.tenant = DEFAULT_API_TENANT
}
Expand Down Expand Up @@ -399,7 +403,7 @@ func requestForAccessToken(retries int, url string, payload *strings.Reader) (*h
}

func (avisess *AviSession) getCSPAccessToken() error {
url := "https://" + avisess.CSP_HOST + "/csp/gateway/am/api/auth/api-tokens/authorize"
url := avisess.scheme + "://" + avisess.CSP_HOST + "/csp/gateway/am/api/auth/api-tokens/authorize"
payload := strings.NewReader("api_token=" + avisess.CSP_TOKEN)
var (
retries int = 0
Expand Down Expand Up @@ -662,6 +666,17 @@ func (avisess *AviSession) setCSPHost(csphost string) error {
return nil
}

func SetScheme(scheme string) func(*AviSession) error {
return func(sess *AviSession) error {
return sess.setScheme(scheme)
}
}

func (avisess *AviSession) setScheme(scheme string) error {
avisess.scheme = scheme
return nil
}

func (avisess *AviSession) isTokenAuth() bool {
return avisess.authToken != "" || avisess.refreshAuthToken != nil || avisess.refreshAuthTokenV2 != nil
}
Expand Down Expand Up @@ -729,6 +744,10 @@ func (avisess *AviSession) newAviRequest(verb string, url string, payload io.Rea
}
req.Header.Set("Content-Type", "application/json")

if avisess.prefix != "" {
req.Header.Set("Referer", avisess.prefix)
}

if avisess.user_headers != nil {
for k, v := range avisess.user_headers {
req.Header.Set(k, v)
Expand All @@ -744,9 +763,7 @@ func (avisess *AviSession) newAviRequest(verb string, url string, payload io.Rea
req.Header["X-CSRFToken"] = []string{avisess.csrfToken}
req.AddCookie(&http.Cookie{Name: "csrftoken", Value: avisess.csrfToken})
}
if avisess.prefix != "" {
req.Header.Set("Referer", avisess.prefix)
}

if tenant != "" {
req.Header.Set("X-Avi-Tenant", tenant)
}
Expand Down

0 comments on commit c0250d4

Please sign in to comment.