Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/awx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type AWX struct {
CredentialTypeService *CredentialTypeService
CredentialInputSourceService *CredentialInputSourceService
InventorySourcesService *InventorySourcesService
InventorySourcesSchedulesService *InventorySourcesSchedulesService
InventoryGroupService *InventoryGroupService
InstanceGroupsService *InstanceGroupsService
NotificationTemplatesService *NotificationTemplatesService
Expand Down Expand Up @@ -173,6 +174,9 @@ func newAWX(c *Client) *AWX {
InventorySourcesService: &InventorySourcesService{
client: c,
},
InventorySourcesSchedulesService: &InventorySourcesSchedulesService{
client: c,
},
InventoryGroupService: &InventoryGroupService{
client: c,
},
Expand Down
65 changes: 65 additions & 0 deletions client/inventory_sources_schedule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package awx

import (
"bytes"
"encoding/json"
"fmt"
"log"
)

const inventorySourcesSchedulesAPIEndpoint = "/api/v2/inventory_sources/%d/schedules/"

// InventorySourcesSchedulesService implements awx inventory sources schedules apis.
type InventorySourcesSchedulesService struct {
client *Client
}

// ListInventorySourcesSchedules shows a list of schedules for a given inventory_source
func (is *InventorySourcesSchedulesService) ListInventorySourcesSchedules(id int, params map[string]string) ([]*Schedule, *ListSchedulesResponse, error) {
result := new(ListSchedulesResponse)
resp, err := is.client.Requester.GetJSON(
fmt.Sprintf(inventorySourcesSchedulesAPIEndpoint, id),
result, params)
if err != nil {
return nil, result, err
}

if err := CheckResponse(resp); err != nil {
return nil, result, err
}

return result.Results, result, nil
}

// CreateInventorySourcesSchedule will create a schedule for an existing inventory_source
func (is *InventorySourcesSchedulesService) CreateInventorySourcesSchedule(id int, data map[string]interface{}, params map[string]string) (*Schedule, error) {
mandatoryFields = []string{"name", "rrule"}
validate, status := ValidateParams(data, mandatoryFields)
if !status {
err := fmt.Errorf("mandatory input arguments are absent: %s", validate)
return nil, err
}

result := new(Schedule)
payload, err := json.Marshal(data)
if err != nil {
return nil, err
}

resp, err := is.client.Requester.PostJSON(
fmt.Sprintf(inventorySourcesSchedulesAPIEndpoint, id),
bytes.NewReader(payload), result, params,
)

log.Println("OK")

if err != nil {
return nil, err
}

if err := CheckResponse(resp); err != nil {
return nil, err
}

return result, nil
}
40 changes: 30 additions & 10 deletions client/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,33 @@ func (p *OrganizationsService) DeleteOrganization(id int) (*Organization, error)
return result, nil
}

// DisAssociateGalaxyCredentials remove Credentials form an awx job template
// DisAssociateGalaxyCredentials remove Credentials from an organization
func (p *OrganizationsService) DisAssociateGalaxyCredentials(id int, data map[string]interface{}, params map[string]string) (*Organization, error) {
return p.disAssociate(id, "galaxy_credentials", data, params)
}

// AssociateGalaxyCredentials adding credentials to Organization.
func (p *OrganizationsService) AssociateGalaxyCredentials(id int, data map[string]interface{}, params map[string]string) (*Organization, error) {
return p.associate(id, "galaxy_credentials", data, params)
}

// DisAssociateInstanceGroups remove instance_groups from an organization
func (p *OrganizationsService) DisAssociateInstanceGroups(id int, data map[string]interface{}, params map[string]string) (*Organization, error) {
return p.disAssociate(id, "instance_groups", data, params)
}

// AssociateInstanceGroups adding instance_groups to Organization.
func (p *OrganizationsService) AssociateInstanceGroups(id int, data map[string]interface{}, params map[string]string) (*Organization, error) {
return p.associate(id, "instance_groups", data, params)
}

// Associate associate an element to Organization.
func (p *OrganizationsService) associate(id int, typ string, data map[string]interface{}, params map[string]string) (*Organization, error) {
result := new(Organization)
endpoint := fmt.Sprintf("%s%d/galaxy_credentials/", organizationsAPIEndpoint, id)
data["disassociate"] = true
mandatoryFields = []string{"id", "disassociate"}

endpoint := fmt.Sprintf("%s%d/%s/", organizationsAPIEndpoint, id, typ)
data["associate"] = true
mandatoryFields = []string{"id"}
validate, status := ValidateParams(data, mandatoryFields)
if !status {
err := fmt.Errorf("mandatory input arguments are absent: %s", validate)
Expand All @@ -136,13 +157,12 @@ func (p *OrganizationsService) DisAssociateGalaxyCredentials(id int, data map[st
return result, nil
}

// AssociateGalaxyCredentials adding credentials to Organization.
func (p *OrganizationsService) AssociateGalaxyCredentials(id int, data map[string]interface{}, params map[string]string) (*Organization, error) {
// DisAssociate remove element from an organization
func (p *OrganizationsService) disAssociate(id int, typ string, data map[string]interface{}, params map[string]string) (*Organization, error) {
result := new(Organization)

endpoint := fmt.Sprintf("%s%d/galaxy_credentials/", organizationsAPIEndpoint, id)
data["associate"] = true
mandatoryFields = []string{"id"}
endpoint := fmt.Sprintf("%s%d/%s/", organizationsAPIEndpoint, id, typ)
data["disassociate"] = true
mandatoryFields = []string{"id", "disassociate"}
validate, status := ValidateParams(data, mandatoryFields)
if !status {
err := fmt.Errorf("mandatory input arguments are absent: %s", validate)
Expand Down
102 changes: 55 additions & 47 deletions client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ type Credential struct {
OrganizationID int `json:"organization"`
CredentialTypeID int `json:"credential_type"`
Inputs map[string]interface{} `json:"inputs"`
SummaryFields map[string]interface{} `json:"summary_fields"`
SummaryFields *Summary `json:"summary_fields"`
}

type CredentialType struct {
Expand Down Expand Up @@ -361,52 +361,60 @@ type Ping struct {

// JobTemplate represents the awx api job template.
type JobTemplate struct {
ID int `json:"id"`
Type string `json:"type"`
URL string `json:"url"`
Related *Related `json:"related"`
SummaryFields *Summary `json:"summary_fields"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
Name string `json:"name"`
Description string `json:"description"`
JobType string `json:"job_type"`
Inventory int `json:"inventory"`
Project int `json:"project"`
Playbook string `json:"playbook"`
Forks int `json:"forks"`
JobSliceCount int `json:"job_slice_count"`
Limit string `json:"limit"`
Verbosity int `json:"verbosity"`
ExtraVars string `json:"extra_vars"`
JobTags string `json:"job_tags"`
ForceHandlers bool `json:"force_handlers"`
SkipTags string `json:"skip_tags"`
StartAtTask string `json:"start_at_task"`
Timeout int `json:"timeout"`
UseFactCache bool `json:"use_fact_cache"`
LastJobRun interface{} `json:"last_job_run"`
LastJobFailed bool `json:"last_job_failed"`
NextJobRun interface{} `json:"next_job_run"`
Status string `json:"status"`
HostConfigKey string `json:"host_config_key"`
AskDiffModeOnLaunch bool `json:"ask_diff_mode_on_launch"`
AskVariablesOnLaunch bool `json:"ask_variables_on_launch"`
AskLimitOnLaunch bool `json:"ask_limit_on_launch"`
AskTagsOnLaunch bool `json:"ask_tags_on_launch"`
AskSkipTagsOnLaunch bool `json:"ask_skip_tags_on_launch"`
AskJobTypeOnLaunch bool `json:"ask_job_type_on_launch"`
AskVerbosityOnLaunch bool `json:"ask_verbosity_on_launch"`
AskInventoryOnLaunch bool `json:"ask_inventory_on_launch"`
AskCredentialOnLaunch bool `json:"ask_credential_on_launch"`
SurveyEnabled bool `json:"survey_enabled"`
BecomeEnabled bool `json:"become_enabled"`
DiffMode bool `json:"diff_mode"`
AllowSimultaneous bool `json:"allow_simultaneous"`
CustomVirtualenv interface{} `json:"custom_virtualenv"`
Credential int `json:"credential"`
VaultCredential interface{} `json:"vault_credential"`
ExecutionEnvironment int `json:"execution_environment"`
ID int `json:"id"`
Type string `json:"type"`
URL string `json:"url"`
Related *Related `json:"related"`
SummaryFields *Summary `json:"summary_fields"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
Name string `json:"name"`
Description string `json:"description"`
JobType string `json:"job_type"`
Inventory int `json:"inventory"`
Project int `json:"project"`
Playbook string `json:"playbook"`
ScmBranch string `json:"scm_branch"`
Forks int `json:"forks"`
Limit string `json:"limit"`
Verbosity int `json:"verbosity"`
ExtraVars string `json:"extra_vars"`
JobTags string `json:"job_tags"`
ForceHandlers bool `json:"force_handlers"`
SkipTags string `json:"skip_tags"`
StartAtTask string `json:"start_at_task"`
Timeout int `json:"timeout"`
UseFactCache bool `json:"use_fact_cache"`
LastJobRun interface{} `json:"last_job_run"`
LastJobFailed bool `json:"last_job_failed"`
NextJobRun interface{} `json:"next_job_run"`
Status string `json:"status"`
ExecutionEnvironment string `json:"execution_environment"`
HostConfigKey string `json:"host_config_key"`
AskScmBranchOnLaunch bool `json:"ask_scm_branch_on_launch"`
AskDiffModeOnLaunch bool `json:"ask_diff_mode_on_launch"`
AskVariablesOnLaunch bool `json:"ask_variables_on_launch"`
AskLimitOnLaunch bool `json:"ask_limit_on_launch"`
AskTagsOnLaunch bool `json:"ask_tags_on_launch"`
AskSkipTagsOnLaunch bool `json:"ask_skip_tags_on_launch"`
AskJobTypeOnLaunch bool `json:"ask_job_type_on_launch"`
AskVerbosityOnLaunch bool `json:"ask_verbosity_on_launch"`
AskInventoryOnLaunch bool `json:"ask_inventory_on_launch"`
AskCredentialOnLaunch bool `json:"ask_credential_on_launch"`
AskExecutionEnvironmentOnLaunch bool `json:"ask_execution_environment_on_launch"`
AskLabelsOnLaunch bool `json:"ask_labels_on_launch"`
AskForksOnLaunch bool `json:"ask_forks_on_launch"`
AskJobSliceCountOnLaunch bool `json:"ask_job_slice_count_on_launch"`
AskTimeoutOnLaunch bool `json:"ask_timeout_on_launch"`
AskInstanceGroupsOnLaunch bool `json:"ask_instance_groups_on_launch"`
SurveyEnabled bool `json:"survey_enabled"`
BecomeEnabled bool `json:"become_enabled"`
DiffMode bool `json:"diff_mode"`
AllowSimultaneous bool `json:"allow_simultaneous"`
CustomVirtualenv interface{} `json:"custom_virtualenv"`
JobSliceCount int `json:"job_slice_count"`
Credential int `json:"credential"`
VaultCredential interface{} `json:"vault_credential"`
}

// JobLaunch represents the awx api job launch.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/denouche/goawx

go 1.14
go 1.20