-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PLT-1259: SDK Cut over with 4.3 changes #114
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ import ( | |
) | ||
|
||
type V1Client struct { | ||
|
||
Client clientV1.ClientService | ||
|
||
ctx context.Context | ||
|
@@ -73,6 +72,12 @@ func WithHubbleURI(hubbleUri string) func(*V1Client) { | |
} | ||
} | ||
|
||
func SetProjectUID(projectUid string) func(*V1Client) { | ||
return func(v *V1Client) { | ||
v.projectUid = projectUid | ||
} | ||
} | ||
|
||
func WithInsecureSkipVerify(insecureSkipVerify bool) func(*V1Client) { | ||
return func(v *V1Client) { | ||
v.insecureSkipVerify = insecureSkipVerify | ||
|
@@ -202,6 +207,11 @@ func (h *V1Client) baseTransport() *transport.Runtime { | |
return httpTransport | ||
} | ||
|
||
func (h *V1Client) SetProjectContextForResource() *V1Client { | ||
h.ctx = ContextWithProject(h.ctx, h.projectUid) | ||
return h | ||
} | ||
|
||
func (h *V1Client) httpClient() *http.Client { | ||
return &http.Client{ | ||
Transport: &http.Transport{ | ||
|
@@ -234,3 +244,10 @@ func (h *V1Client) ValidateTenantAdmin() error { | |
} | ||
return nil | ||
} | ||
|
||
func ContextWithProject(c context.Context, projectUid string) context.Context { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above comment. This function should not be required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required because in Terraform, we have the provision to set resource-level context. During provider initialization, we use project scope or tenant scope based on the user settings during initialization. Later on, the user can also set the context at the resource level (if user have right access). For example, a user can initialize the client with project scope and then switch to create a resource at the tenant level as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. Let's discuss. |
||
return context.WithValue(c, transport.CUSTOM_HEADERS, transport.Values{ | ||
HeaderMap: map[string]string{ | ||
"ProjectUid": projectUid, | ||
}}) | ||
} |
SivaanandM marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be accomplished by calling
WithScopeProject
. Please remove.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required because in Terraform, we have the provision to set resource-level context.
During provider initialization, we use project scope or tenant scope based on the user settings during initialization. Later on, the user can also set the context at the resource level (if user have right access).
For example, a user can initialize the client with project scope and then switch to create a resource at the tenant level as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that, but there's already a way that you can handle the requirement without introducing a new method on the V1Client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ping me and we can discuss.