This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #17 from bored-engineer/program
Add ProgramService and update related structs
- Loading branch information
Showing
16 changed files
with
675 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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,63 @@ | ||
// Copyright (c) 2016 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/uber-go/hackeroni/h1" | ||
|
||
"golang.org/x/crypto/ssh/terminal" | ||
|
||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
|
||
fmt.Print("HackerOne API Identifier: ") | ||
r := bufio.NewReader(os.Stdin) | ||
identifier, _ := r.ReadString('\n') | ||
|
||
fmt.Print("HackerOne API Token: ") | ||
token, _ := terminal.ReadPassword(int(syscall.Stdin)) | ||
fmt.Print("\n") | ||
|
||
tp := h1.APIAuthTransport{ | ||
APIIdentifier: strings.TrimSpace(identifier), | ||
APIToken: strings.TrimSpace(string(token)), | ||
} | ||
|
||
client := h1.NewClient(tp.Client()) | ||
|
||
fmt.Print("Program ID: ") | ||
programID, _ := r.ReadString('\n') | ||
fmt.Print("\n") | ||
|
||
program, _, err := client.Program.Get(strings.TrimSpace(programID)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("Program: %#v\n", program) | ||
|
||
} |
This file contains 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 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 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 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 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,70 @@ | ||
// Copyright (c) 2016 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package h1 | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// MemberPermission represent possible permissions sizes for a member | ||
// | ||
// HackerOne API docs: https://api.hackerone.com/docs/v1#member | ||
const ( | ||
MemberPermissionRewardManagement string = "reward_management" | ||
MemberPermissionProgramManagement string = "program_management" | ||
MemberPermissionUserManagement string = "user_management" | ||
MemberPermissionReportManagement string = "report_management" | ||
) | ||
|
||
// Member represents a user in a program | ||
// | ||
// HackerOne API docs: https://api.hackerone.com/docs/v1#member | ||
type Member struct { | ||
ID *string `json:"id"` | ||
Type *string `json:"type"` | ||
Permissions []*string `json:"permissions"` | ||
CreatedAt *Timestamp `json:"created_at"` | ||
User *User `json:"user"` | ||
} | ||
|
||
// Helper types for JSONUnmarshal | ||
type member Member // Used to avoid recursion of JSONUnmarshal | ||
type memberUnmarshalHelper struct { | ||
member | ||
Attributes *member `json:"attributes"` | ||
Relationships struct { | ||
User struct { | ||
Data *User `json:"data"` | ||
} `json:"user"` | ||
} `json:"relationships"` | ||
} | ||
|
||
// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly. | ||
func (m *Member) UnmarshalJSON(b []byte) error { | ||
var helper memberUnmarshalHelper | ||
helper.Attributes = &helper.member | ||
if err := json.Unmarshal(b, &helper); err != nil { | ||
return err | ||
} | ||
*m = Member(helper.member) | ||
m.User = helper.Relationships.User.Data | ||
return nil | ||
} |
This file contains 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,58 @@ | ||
// Copyright (c) 2016 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package h1 | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
|
||
"testing" | ||
) | ||
|
||
func Test_Member(t *testing.T) { | ||
var actual Member | ||
loadResource(t, &actual, "tests/resources/member.json") | ||
expected := Member{ | ||
ID: String("1337"), | ||
Type: String(MemberType), | ||
Permissions: []*string{ | ||
String(MemberPermissionProgramManagement), | ||
String(MemberPermissionReportManagement), | ||
String(MemberPermissionRewardManagement), | ||
String(MemberPermissionUserManagement), | ||
}, | ||
CreatedAt: NewTimestamp("2016-02-02T04:05:06.000Z"), | ||
User: &User{ | ||
ID: String("1337"), | ||
Type: String(UserType), | ||
Disabled: Bool(false), | ||
Username: String("api-example"), | ||
Name: String("API Example"), | ||
ProfilePicture: UserProfilePicture{ | ||
Size62x62: String("/assets/avatars/default.png"), | ||
Size82x82: String("/assets/avatars/default.png"), | ||
Size110x110: String("/assets/avatars/default.png"), | ||
Size260x260: String("/assets/avatars/default.png"), | ||
}, | ||
CreatedAt: NewTimestamp("2016-02-02T04:05:06.000Z"), | ||
}, | ||
} | ||
assert.Equal(t, expected, actual) | ||
} |
This file contains 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 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,44 @@ | ||
// Copyright (c) 2016 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package h1 | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// ProgramService handles communication with the program related methods of the H1 API. | ||
type ProgramService service | ||
|
||
// Get fetches a Program by ID | ||
func (s *ProgramService) Get(ID string) (*Program, *Response, error) { | ||
req, err := s.client.NewRequest("GET", fmt.Sprintf("programs/%s", ID), nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
rResp := new(Program) | ||
resp, err := s.client.Do(req, rResp) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return rResp, resp, err | ||
} |
Oops, something went wrong.