This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Support notifications to users with private email ( using fabric8 service account ) #54
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3598b0a
start using latest auth
sbose78 458aaa3
fix tests
sbose78 c89add7
get sa token
sbose78 8a0e7d3
add error check;
sbose78 cceda60
inject service account token on startup
sbose78 800f29c
remove the WITs user api call
sbose78 28bd7c1
remove the WITs user api call
sbose78 edbd9f2
remove the WITs user api call
sbose78 616543e
delete the right stuff during make clean
sbose78 d07b361
add custom code for user api client
sbose78 6dbc3e3
remove unused import
sbose78 1959cb8
Merge remote-tracking branch 'upstream/master' into use-service-ac
sbose78 11e52e1
cleanup
sbose78 cc35683
remove unused import
sbose78 b5330b8
Merge remote-tracking branch 'upstream/master' into use-service-ac
sbose78 3205a12
oauth --> externalToken
sbose78 1d9bfd1
fix comment, and add nil check
sbose78 e9c93e6
fix test
sbose78 37b3c4a
check error before response nil
sbose78 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 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,50 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/url" | ||
|
||
"fmt" | ||
|
||
"github.com/fabric8-services/fabric8-notification/auth/api" | ||
"github.com/fabric8-services/fabric8-wit/goasupport" | ||
goaclient "github.com/goadesign/goa/client" | ||
"github.com/goadesign/goa/uuid" | ||
"github.com/gregjones/httpcache" | ||
) | ||
|
||
func NewCachedClient(hostURL string) (*api.Client, error) { | ||
|
||
u, err := url.Parse(hostURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tp := httpcache.NewMemoryCacheTransport() | ||
client := http.Client{Transport: tp} | ||
|
||
c := api.New(goaclient.HTTPClientDoer(&client)) | ||
c.Host = u.Host | ||
c.Scheme = u.Scheme | ||
return c, nil | ||
} | ||
|
||
func GetSpaceCollaborators(ctx context.Context, client *api.Client, spaceID uuid.UUID) (*api.UserList, error) { | ||
pageLimit := 100 | ||
pageOffset := "0" | ||
resp, err := client.ListCollaborators(goasupport.ForwardContextRequestID(ctx), api.ListCollaboratorsPath(spaceID), &pageLimit, &pageOffset, nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if resp != nil { | ||
defer resp.Body.Close() | ||
} else { | ||
return nil, fmt.Errorf("failed to make request to get list of collaborators") | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("non %v status code for %v, returned %v", http.StatusOK, "GET collaborators", resp.StatusCode) | ||
} | ||
return client.DecodeUserList(resp) | ||
} |
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,36 @@ | ||
package auth_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/fabric8-services/fabric8-notification/auth" | ||
"github.com/fabric8-services/fabric8-notification/auth/api" | ||
"github.com/goadesign/goa/uuid" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const ( | ||
openshiftIOAPI = "http://auth.openshift.io" | ||
) | ||
|
||
func createClient(t *testing.T) *api.Client { | ||
c, err := auth.NewCachedClient(openshiftIOAPI) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return c | ||
} | ||
|
||
func TestSpaceCollaborators(t *testing.T) { | ||
|
||
c := createClient(t) | ||
id, _ := uuid.FromString("020f756e-b51a-4b43-b113-45cec16b9ce9") | ||
|
||
u, err := auth.GetSpaceCollaborators(context.Background(), c, id) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assert.True(t, len(u.Data) > 10) | ||
} |
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,77 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/url" | ||
|
||
"fmt" | ||
|
||
"github.com/fabric8-services/fabric8-notification/auth/api" | ||
"github.com/fabric8-services/fabric8-wit/goasupport" | ||
"github.com/goadesign/goa/uuid" | ||
) | ||
|
||
/* | ||
Took out the auth api client code relevant to User API in order to add a custom | ||
client.JWTSigner.Sign(req) before the http request is made. | ||
|
||
This wasn't present in the auto-generated client for GET /api/users/ID | ||
because we don't set "a.Security("jwt")" in auth's design/account.go | ||
for the `Show Users` action. | ||
*/ | ||
|
||
func GetUser(ctx context.Context, client *api.Client, uID uuid.UUID) (*api.User, error) { | ||
resp, err := showUsers(goasupport.ForwardContextRequestID(ctx), client, api.ShowUsersPath(uID.String()), nil, nil) | ||
if resp != nil { | ||
defer resp.Body.Close() | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("non %v status code for %v, returned %v", http.StatusOK, "GET user", resp.StatusCode) | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
return client.DecodeUser(resp) | ||
} | ||
|
||
// retrieve user for the given ID. | ||
func showUsers(ctx context.Context, client *api.Client, path string, ifModifiedSince *string, ifNoneMatch *string) (*http.Response, error) { | ||
req, err := newShowUsersRequest(ctx, client, path, ifModifiedSince, ifNoneMatch) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return client.Do(ctx, req) | ||
} | ||
|
||
// newShowUsersRequest create the request corresponding to the show action endpoint of the users resource. | ||
func newShowUsersRequest(ctx context.Context, client *api.Client, path string, ifModifiedSince *string, ifNoneMatch *string) (*http.Request, error) { | ||
scheme := client.Scheme | ||
if scheme == "" { | ||
scheme = "http" | ||
} | ||
u := url.URL{Host: client.Host, Scheme: scheme, Path: path} | ||
req, err := http.NewRequest("GET", u.String(), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
header := req.Header | ||
if ifModifiedSince != nil { | ||
|
||
header.Set("If-Modified-Since", *ifModifiedSince) | ||
} | ||
if ifNoneMatch != nil { | ||
|
||
header.Set("If-None-Match", *ifNoneMatch) | ||
} | ||
|
||
// This wasn't present in the auto-generated client for GET /api/users/ID | ||
// because we don't set "a.Security("jwt")" in auth's design/account.go | ||
// for the `Show Users` action. | ||
if client.JWTSigner != nil { | ||
client.JWTSigner.Sign(req) | ||
} | ||
return req, 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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, you are testing the real "openshiftio" space from prod here. Not sure we need such a test here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this test was there before, just moved it around a bit to a new file.
using the prod space "openshiftio" because that's the only one's that's constant and hence test-able. Ideal situation would be to create a space and validate it :)