Skip to content

Commit

Permalink
Merge branch 'main' into feature/bitbucket-phase-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreminiom authored Aug 16, 2024
2 parents 23906b9 + 2b05f85 commit a0dd946
Show file tree
Hide file tree
Showing 149 changed files with 1,151 additions and 622 deletions.
40 changes: 35 additions & 5 deletions admin/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,94 @@ import (

const defaultApiEndpoint = "https://api.atlassian.com/"

// New creates a new instance of Client.
// It takes a common.HttpClient as input and returns a pointer to Client and an error.
func New(httpClient common.HttpClient) (*Client, error) {

// If no HTTP client is provided, use the default HTTP client.
if httpClient == nil {
httpClient = http.DefaultClient
}

// Parse the default API endpoint URL.
u, err := url.Parse(defaultApiEndpoint)
if err != nil {
return nil, err
}

// Initialize the Client struct with the provided HTTP client and parsed URL.
client := &Client{
HTTP: httpClient,
Site: u,
}

// Initialize the Authentication service.
client.Auth = internal.NewAuthenticationService(client)

// Initialize the SCIM service with user, group, and schema services.
client.SCIM = &internal.SCIMService{
User: internal.NewSCIMUserService(client),
Group: internal.NewSCIMGroupService(client),
Schema: internal.NewSCIMSchemaService(client),
}

// Initialize the Organization service with policy and directory services.
client.Organization = internal.NewOrganizationService(
client,
internal.NewOrganizationPolicyService(client),
internal.NewOrganizationDirectoryService(client))

// Initialize the User service with a user token service.
client.User = internal.NewUserService(client, internal.NewUserTokenService(client))

return client, nil
}

// Client represents a client for interacting with the Atlassian Administration API.
type Client struct {
HTTP common.HttpClient
Site *url.URL
Auth common.Authentication
// HTTP is the HTTP client used for making requests.
HTTP common.HttpClient
// Site is the base URL for the API.
Site *url.URL
// Auth is the authentication service.
Auth common.Authentication
// Organization is the service for organization-related operations.
Organization *internal.OrganizationService
User *internal.UserService
SCIM *internal.SCIMService
// User is the service for user-related operations.
User *internal.UserService
// SCIM is the service for SCIM-related operations.
SCIM *internal.SCIMService
}

// NewRequest creates a new HTTP request with the given context, method, URL string, content type, and body.
// It returns an HTTP request and an error.
func (c *Client) NewRequest(ctx context.Context, method, urlStr, type_ string, body interface{}) (*http.Request, error) {

// Parse the relative URL.
rel, err := url.Parse(urlStr)
if err != nil {
return nil, err
}

// Resolve the relative URL to an absolute URL.
u := c.Site.ResolveReference(rel)

// Encode the body to JSON if provided.
buf := new(bytes.Buffer)
if body != nil {
if err = json.NewEncoder(buf).Encode(body); err != nil {
return nil, err
}
}

// Create a new HTTP request with the given context, method, and URL.
req, err := http.NewRequestWithContext(ctx, method, u.String(), buf)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")

// Set the Content-Type header if a body is provided.
if body != nil && type_ == "" {
req.Header.Set("Content-Type", "application/json")
}
Expand All @@ -88,24 +111,31 @@ func (c *Client) NewRequest(ctx context.Context, method, urlStr, type_ string, b
req.Header.Set("Content-Type", type_)
}

// Add the Authorization header if a bearer token is available.
if c.Auth.GetBearerToken() != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %v", c.Auth.GetBearerToken()))
}

// Set the User-Agent header if available.
if c.Auth.HasUserAgent() {
req.Header.Set("User-Agent", c.Auth.GetUserAgent())
}

return req, nil
}

// Call sends an HTTP request and processes the response.
// It takes an *http.Request and a structure to unmarshal the response into.
// It returns a pointer to model.ResponseScheme and an error.
func (c *Client) Call(request *http.Request, structure interface{}) (*model.ResponseScheme, error) {

// Perform the HTTP request.
response, err := c.HTTP.Do(request)
if err != nil {
return nil, err
}

// Process the HTTP response.
return c.processResponse(response, structure)
}

Expand Down
24 changes: 21 additions & 3 deletions admin/internal/authentication_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,75 @@ import (
"github.com/ctreminiom/go-atlassian/service/common"
)

// NewAuthenticationService creates a new instance of AuthenticationService.
// It takes a service.Connector as input and returns a common.Authentication interface.
func NewAuthenticationService(client service.Connector) common.Authentication {
return &AuthenticationService{c: client}
}

// AuthenticationService provides methods for setting and getting authentication details.
type AuthenticationService struct {
c service.Connector

// basicAuthProvided indicates if basic authentication details have been provided.
basicAuthProvided bool
mail, token string
// mail is the email address used for basic authentication.
// token is the token used for basic authentication.
mail, token string

// userAgentProvided indicates if a user agent has been provided.
userAgentProvided bool
agent string
// agent is the user agent string.
agent string
}

// SetBearerToken sets the bearer token for authentication.
func (a *AuthenticationService) SetBearerToken(token string) {
a.token = token
}

// GetBearerToken returns the bearer token used for authentication.
func (a *AuthenticationService) GetBearerToken() string {
return a.token
}

// SetExperimentalFlag is a placeholder method for setting an experimental flag.
func (a *AuthenticationService) SetExperimentalFlag() {}

// HasSetExperimentalFlag is a placeholder method that returns false.
func (a *AuthenticationService) HasSetExperimentalFlag() bool {
return false
}

// SetBasicAuth sets the email and token for basic authentication.
func (a *AuthenticationService) SetBasicAuth(mail, token string) {
a.mail = mail
a.token = token

a.basicAuthProvided = true
}

// GetBasicAuth returns the email and token used for basic authentication.
func (a *AuthenticationService) GetBasicAuth() (string, string) {
return a.mail, a.token
}

// HasBasicAuth returns true if basic authentication details have been provided.
func (a *AuthenticationService) HasBasicAuth() bool {
return a.basicAuthProvided
}

// SetUserAgent sets the user agent string.
func (a *AuthenticationService) SetUserAgent(agent string) {
a.agent = agent
a.userAgentProvided = true
}

// GetUserAgent returns the user agent string.
func (a *AuthenticationService) GetUserAgent() string {
return a.agent
}

// HasUserAgent returns true if a user agent has been provided.
func (a *AuthenticationService) HasUserAgent() bool {
return a.userAgentProvided
}
4 changes: 4 additions & 0 deletions admin/internal/organization_directory_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"net/http"
)

// NewOrganizationDirectoryService creates a new instance of OrganizationDirectoryService.
// It takes a service.Connector as input and returns a pointer to OrganizationDirectoryService.
func NewOrganizationDirectoryService(client service.Connector) *OrganizationDirectoryService {
return &OrganizationDirectoryService{internalClient: &internalOrganizationDirectoryServiceImpl{c: client}}
}

// OrganizationDirectoryService provides methods to interact with the organization directory in Atlassian Administration.
type OrganizationDirectoryService struct {
// internalClient is the connector interface for organization directory operations.
internalClient admin.OrganizationDirectoryConnector
}

Expand Down
4 changes: 4 additions & 0 deletions admin/internal/organization_policy_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import (
"strings"
)

// NewOrganizationPolicyService creates a new instance of OrganizationPolicyService.
// It takes a service.Connector as input and returns a pointer to OrganizationPolicyService.
func NewOrganizationPolicyService(client service.Connector) *OrganizationPolicyService {
return &OrganizationPolicyService{internalClient: &internalOrganizationPolicyImpl{c: client}}
}

// OrganizationPolicyService provides methods to interact with organization policies in Atlassian Administration.
type OrganizationPolicyService struct {
// internalClient is the connector interface for organization policy operations.
internalClient admin.OrganizationPolicyConnector
}

Expand Down
4 changes: 4 additions & 0 deletions admin/internal/scim_group_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import (
"strconv"
)

// NewSCIMGroupService creates a new instance of SCIMGroupService.
// It takes a service.Connector as input and returns a pointer to SCIMGroupService.
func NewSCIMGroupService(client service.Connector) *SCIMGroupService {
return &SCIMGroupService{internalClient: &internalSCIMGroupImpl{c: client}}
}

// SCIMGroupService provides methods to interact with SCIM groups in Atlassian Administration.
type SCIMGroupService struct {
// internalClient is the connector interface for SCIM group operations.
internalClient admin.SCIMGroupConnector
}

Expand Down
14 changes: 12 additions & 2 deletions admin/internal/scim_impl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package internal

// SCIMService encapsulates various SCIM-related services within a single structure.
// It provides a convenient way to access and manage different SCIM functionalities.
type SCIMService struct {
User *SCIMUserService
Group *SCIMGroupService
// User is a pointer to an instance of SCIMUserService.
// It handles operations related to SCIM users.
User *SCIMUserService

// Group is a pointer to an instance of SCIMGroupService.
// It manages SCIM group operations.
Group *SCIMGroupService

// Schema is a pointer to an instance of SCIMSchemaService.
// It deals with SCIM schema operations.
Schema *SCIMSchemaService
}
4 changes: 4 additions & 0 deletions admin/internal/scim_schema_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"net/http"
)

// NewSCIMSchemaService creates a new instance of SCIMSchemaService.
// It takes a service.Connector as input and returns a pointer to SCIMSchemaService.
func NewSCIMSchemaService(client service.Connector) *SCIMSchemaService {
return &SCIMSchemaService{internalClient: &internalSCIMSchemaImpl{c: client}}
}

// SCIMSchemaService provides methods to interact with SCIM schemas in Atlassian Administration.
type SCIMSchemaService struct {
// internalClient is the connector interface for SCIM schema operations.
internalClient admin.SCIMSchemaConnector
}

Expand Down
4 changes: 4 additions & 0 deletions admin/internal/scim_user_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ import (
"strings"
)

// NewSCIMUserService creates a new instance of SCIMUserService.
// It takes a service.Connector as input and returns a pointer to SCIMUserService.
func NewSCIMUserService(client service.Connector) *SCIMUserService {
return &SCIMUserService{internalClient: &internalSCIMUserImpl{c: client}}
}

// SCIMUserService provides methods to interact with SCIM users in Atlassian Administration.
type SCIMUserService struct {
// internalClient is the connector interface for SCIM user operations.
internalClient admin.SCIMUserConnector
}

Expand Down
7 changes: 6 additions & 1 deletion admin/internal/user_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import (
"strings"
)

// NewUserService creates a new instance of UserService.
// It takes a service.Connector and a UserTokenService as inputs and returns a pointer to UserService.
func NewUserService(client service.Connector, token *UserTokenService) *UserService {
return &UserService{
internalClient: &internalUserImpl{c: client},
Token: token,
}
}

// UserService provides methods to interact with user-related operations in Atlassian Administration.
type UserService struct {
// internalClient is the connector interface for user operations.
internalClient admin.UserConnector
Token *UserTokenService
// Token is a service for managing user tokens.
Token *UserTokenService
}

// Permissions returns the set of permissions you have for managing the specified Atlassian account
Expand Down
4 changes: 4 additions & 0 deletions admin/internal/user_token_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"net/http"
)

// NewUserTokenService creates a new instance of UserTokenService.
// It takes a service.Connector as input and returns a pointer to UserTokenService.
func NewUserTokenService(client service.Connector) *UserTokenService {
return &UserTokenService{internalClient: &internalUserTokenImpl{c: client}}
}

// UserTokenService provides methods to interact with user token operations in Atlassian Administration.
type UserTokenService struct {
// internalClient is the connector interface for user token operations.
internalClient admin.UserTokenConnector
}

Expand Down
Loading

0 comments on commit a0dd946

Please sign in to comment.