-
Notifications
You must be signed in to change notification settings - Fork 30
Pushing changes for Atlan backend #58
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
Closed
Pujathacker2210
wants to merge
6
commits into
redhat-data-and-ai:main
from
Pujathacker2210:pthacker_atlan_client
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f927eb6
Pushing changes for Atlan backend
Pujathacker2210 70d2b11
comments cleanup
Pujathacker2210 4785a79
moving appConfig pull at the start of the function
Pujathacker2210 281077c
Update internal/controller/group_controller.go
Pujathacker2210 a2464b0
updated CR check to current CR and added deletion status code validation
Pujathacker2210 7e4aeb7
Pushing sso-atlan group sync functions
Pujathacker2210 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
| /* | ||
| Copyright 2025. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package atlan | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
| "slices" | ||
| "time" | ||
|
|
||
| "github.com/gojek/heimdall/v7" | ||
| "github.com/redhat-data-and-ai/usernaut/pkg/request" | ||
| "github.com/redhat-data-and-ai/usernaut/pkg/request/httpclient" | ||
| "github.com/redhat-data-and-ai/usernaut/pkg/utils" | ||
| ) | ||
|
|
||
| // AtlanClient is a simple HTTP client for Atlan API | ||
| type AtlanClient struct { | ||
| client heimdall.Doer | ||
| url string | ||
| apiToken string | ||
| identityProviderAlias string | ||
| } | ||
|
|
||
| // AtlanConfig holds the configuration needed to connect to Atlan | ||
| type AtlanConfig struct { | ||
| URL string `json:"url"` | ||
| APIToken string `json:"api_token"` | ||
| IdentityProviderAlias string `json:"identity_provider_alias"` | ||
| } | ||
|
|
||
| // NewClient creates a new Atlan client with simple API token authentication | ||
| func NewClient(atlanAppConfig map[string]interface{}, | ||
| connectionPoolConfig httpclient.ConnectionPoolConfig, | ||
| hystrixResiliencyConfig httpclient.HystrixResiliencyConfig) (*AtlanClient, error) { | ||
|
|
||
| atlanConfig := AtlanConfig{} | ||
| if err := utils.MapToStruct(atlanAppConfig, &atlanConfig); err != nil { | ||
| return nil, fmt.Errorf("failed to parse atlan configuration: %w", err) | ||
| } | ||
|
|
||
| // Validate required fields | ||
| if atlanConfig.URL == "" { | ||
| return nil, fmt.Errorf("atlan configuration is missing required field: URL") | ||
| } | ||
| if atlanConfig.APIToken == "" { | ||
| return nil, fmt.Errorf("atlan configuration is missing required field: APIToken") | ||
| } | ||
|
|
||
| // Initialize HTTP client without certificates (Atlan uses API token, not certs) | ||
| client, err := httpclient.InitializeClient( | ||
| "atlan", | ||
| connectionPoolConfig, | ||
| hystrixResiliencyConfig, | ||
| heimdall.NewRetrier(heimdall.NewConstantBackoff(100*time.Millisecond, 50*time.Millisecond)), // retry logic | ||
| 3, | ||
| nil) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to initialize http client: %w", err) | ||
| } | ||
|
|
||
| return &AtlanClient{ | ||
| client: client, | ||
| url: atlanConfig.URL, | ||
| apiToken: atlanConfig.APIToken, | ||
| identityProviderAlias: atlanConfig.IdentityProviderAlias, | ||
| }, nil | ||
| } | ||
|
|
||
| // sendRequest makes an HTTP request to the Atlan API with proper authentication | ||
| func (aC *AtlanClient) sendRequest(ctx context.Context, url string, method string, body interface{}, | ||
| headers map[string]string, methodName string) ([]byte, int, error) { | ||
| requestBody, err := json.Marshal(body) | ||
| if err != nil { | ||
| return nil, 0, fmt.Errorf("failed to marshal request body: %w", err) | ||
| } | ||
|
|
||
| req, err := request.NewRequest(ctx, method, url, requestBody) | ||
| if err != nil { | ||
| return nil, 0, fmt.Errorf("failed to create request: %w", err) | ||
| } | ||
|
|
||
| if headers == nil { | ||
| headers = make(map[string]string) | ||
| } | ||
| headers["Authorization"] = "Bearer " + aC.apiToken | ||
| headers["Content-Type"] = "application/json" | ||
| headers["Accept"] = "application/json" | ||
|
|
||
| req.SetHeaders(headers) | ||
|
|
||
| response, statusCode, err := req.MakeRequest(aC.client, methodName, "atlan") | ||
| if err != nil { | ||
| return nil, statusCode, fmt.Errorf("request failed: %w", err) | ||
| } | ||
|
|
||
| if !slices.Contains([]int{http.StatusOK, http.StatusCreated, http.StatusNoContent}, statusCode) { | ||
| return nil, statusCode, fmt.Errorf("unexpected status code: %d", statusCode) | ||
| } | ||
|
|
||
| return response, statusCode, nil | ||
| } |
This file contains hidden or 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,22 @@ | ||
| package atlan | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/redhat-data-and-ai/usernaut/pkg/common/structs" | ||
| ) | ||
|
|
||
| func (ac *AtlanClient) FetchTeamMembersByTeamID(ctx context.Context, teamID string) (map[string]*structs.User, error) { | ||
| // Team membership is synced via LDAP, returning empty map | ||
| return make(map[string]*structs.User), nil | ||
| } | ||
|
|
||
| func (ac *AtlanClient) AddUserToTeam(ctx context.Context, teamID, userID string) error { | ||
| // Team membership is synced via LDAP, returning nil | ||
| return nil | ||
| } | ||
|
|
||
| func (ac *AtlanClient) RemoveUserFromTeam(ctx context.Context, teamID, userID string) error { | ||
| // Team membership is synced via LDAP, returning nil | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.