Skip to content
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

added user and organization data structures, resources and examples #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion awx/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"regexp"
"strings"

"./internal/data"
"github.com/golang/glog"
"github.com/moolitayer/awx-client-go/awx/internal/data"
)

// Version is the version of the client.
Expand Down Expand Up @@ -249,6 +249,7 @@ func (b *ConnectionBuilder) Build() (c *Connection, err error) {
c.base = b.url
c.username = b.username
c.password = b.password
c.bearer = b.bearer
c.version = "v2"
c.client = client

Expand Down Expand Up @@ -278,6 +279,18 @@ func (c *Connection) Projects() *ProjectsResource {
return NewProjectsResource(c, "projects")
}

// Users returns a reference to the resource that manages the collection of users.
//
func (c *Connection) Users() *UsersResource {
return NewUsersResource(c, "users")
}

// Organizations returns a reference to the resource that manages the collection of Organizations.
//
func (c *Connection) Organizations() *OrganizationsResource {
return NewOrganizationsResource(c, "organizations")
}

func (c *Connection) Close() {
c.token = ""
}
Expand Down
42 changes: 42 additions & 0 deletions awx/internal/data/organization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (c) 2018 Red Hat, Inc.

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.
*/

// This file contains the data structures used for sending and receiving Organizations.

package data

type ExecuteRoles struct {
Id int `json:"id,omitempty"`
}

//Results []*Organization `json:"results,omitempty"`
type ObjectRoles struct {
Executeroles ExecuteRoles `json:"execute_role,omitempty"`
}

type SummaryFields struct {
Objectroles ObjectRoles `json:"object_roles,omitempty"`
}
type Organization struct {
Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
//Execute_role_Id int `json:"id,omitempty"` //`json:"summary_fields.object_roles.execute_role.id,omitempty"`
Summaryfields SummaryFields `json:"summary_fields,omitempty"`
}

type OrganizationGetResponse struct {
Organization
}
25 changes: 25 additions & 0 deletions awx/internal/data/organizations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2018 Red Hat, Inc.

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.
*/

// This file contains the data structures used to receive lists of organization templates.

package data

type OrganizationsGetResponse struct {
ListGetResponse

Results []*Organization `json:"results,omitempty"`
}
29 changes: 29 additions & 0 deletions awx/internal/data/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright (c) 2018 Red Hat, Inc.

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.
*/

// This file contains the data structures used for sending and receiving users.

package data

type User struct {
Id int `json:"id,omitempty"`
Username string `json:"username,omitempty"`
Is_superuser bool `json:"is_superuser,omitempty"`
}

type UserGetResponse struct {
User
}
25 changes: 25 additions & 0 deletions awx/internal/data/users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2018 Red Hat, Inc.

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.
*/

// This file contains the data structures used to receive lists of job templates.

package data

type UsersGetResponse struct {
ListGetResponse

Results []*User `json:"results,omitempty"`
}
2 changes: 1 addition & 1 deletion awx/job_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
package awx

import (
"github.com/moolitayer/awx-client-go/awx/internal/data"
"./internal/data"
)

type JobResource struct {
Expand Down
2 changes: 1 addition & 1 deletion awx/job_template_launch_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package awx
import (
"encoding/json"

"github.com/moolitayer/awx-client-go/awx/internal/data"
"./internal/data"
)

type JobTemplateLaunchResource struct {
Expand Down
2 changes: 1 addition & 1 deletion awx/job_template_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
package awx

import (
"github.com/moolitayer/awx-client-go/awx/internal/data"
"./internal/data"
)

type JobTemplateResource struct {
Expand Down
2 changes: 1 addition & 1 deletion awx/job_templates_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package awx
import (
"fmt"

"github.com/moolitayer/awx-client-go/awx/internal/data"
"./internal/data"
)

type JobTemplatesResource struct {
Expand Down
2 changes: 1 addition & 1 deletion awx/jobs_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package awx
import (
"fmt"

"github.com/moolitayer/awx-client-go/awx/internal/data"
"./internal/data"
)

type JobsResource struct {
Expand Down
45 changes: 45 additions & 0 deletions awx/organization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright (c) 2018 Red Hat, Inc.

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.
*/

// This file contains the implementation of the Organization type.

package awx

// Organization represents an AWX Organization.
//
type Organization struct {
id int
name string
execute_role_id int
}

// Id returns the unique identifier of the Organization.
//
func (p *Organization) Id() int {
return p.id
}

// Name returns the name of the Organization.
//
func (p *Organization) Name() string {
return p.name
}

// Name returns the name of the Organization.
//
func (p *Organization) Execute_role_Id() int {
return p.execute_role_id
}
67 changes: 67 additions & 0 deletions awx/organization_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright (c) 2018 Red Hat, Inc.

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.
*/

// This file contains the implementation of the resource that manages a specific Organization.

package awx

import (
//"github.com/moolitayer/awx-client-go/awx/internal/data"
"./internal/data"
)

type OrganizationResource struct {
Resource
}

func NewOrganizationResource(connection *Connection, path string) *OrganizationResource {
resource := new(OrganizationResource)
resource.connection = connection
resource.path = path
return resource
}

func (r *OrganizationResource) Get() *OrganizationGetRequest {
request := new(OrganizationGetRequest)
request.resource = &r.Resource
return request
}

type OrganizationGetRequest struct {
Request
}

func (r *OrganizationGetRequest) Send() (response *OrganizationGetResponse, err error) {
output := new(data.OrganizationGetResponse)
err = r.get(output)
if err != nil {
return
}
response = new(OrganizationGetResponse)
response.result = new(Organization)
response.result.id = output.Id
response.result.name = output.Name
response.result.execute_role_id = output.Summaryfields.Objectroles.Executeroles.Id
return
}

type OrganizationGetResponse struct {
result *Organization
}

func (r *OrganizationGetResponse) Result() *Organization {
return r.result
}
Loading