-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement the initial retrieve context call (#1)
**Issue #, if available:** ## Description of changes: As the initial feature we are displaying the context of the user. For now we only include the `CallerIdentity` details but this can be extended in the future. **Checklist** <!--- Leave unchecked if your change doesn't seem to apply --> * [x] Update tests * [x] Update docs * [x] PR title follows [conventional commit semantics](https://www.conventionalcommits.org/en/v1.0.0-beta.2/#commit-message-for-a-fix-using-an-optional-issue-number) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
- Loading branch information
Showing
19 changed files
with
492 additions
and
35 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
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 was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
docs/content/1-user-guide/1-retrieve-credential-context.md
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,10 @@ | ||
--- | ||
title: "Retrieve credential context" | ||
weight: 1 | ||
--- | ||
|
||
## Retrieve credential context | ||
|
||
```shell | ||
aws-iam-user --profile [Name of your profile] --region [AWS region used for API calls] | ||
``` |
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,69 @@ | ||
package adapters | ||
|
||
import ( | ||
"errors" | ||
"github.com/conijnio/aws-iam-user/pkg/models" | ||
"testing" | ||
) | ||
|
||
type MockAdapter struct { | ||
LoadUserFailure bool | ||
} | ||
|
||
func (u *MockAdapter) LoadUser() (*models.User, error) { | ||
if u.LoadUserFailure { | ||
return &models.User{}, errors.New("failed") | ||
} | ||
return &models.User{}, nil | ||
} | ||
|
||
func TestAdapterRegistration(t *testing.T) { | ||
adapter := &MockAdapter{} | ||
RegisterAdapter("eu-west-1", "default", adapter) | ||
|
||
if res := HasAdapter("eu-west-1", "default"); !res { | ||
t.Errorf("Expected True received %t", res) | ||
} | ||
|
||
if GetAdapter("eu-west-1", "default") != adapter { | ||
t.Errorf("Expected the given adapter to be returned") | ||
} | ||
} | ||
|
||
func TestSecondAdapterRegistrationDifferentProfile(t *testing.T) { | ||
adapter := &MockAdapter{} | ||
RegisterAdapter("eu-west-1", "default", adapter) | ||
|
||
if res := HasAdapter("eu-west-1", "default"); !res { | ||
t.Errorf("Expected True received %t", res) | ||
} | ||
|
||
if GetAdapter("eu-west-1", "default") != adapter { | ||
t.Errorf("Expected the given adapter to be returned") | ||
} | ||
} | ||
|
||
func TestThirdAdapterRegistrationDifferentProfile(t *testing.T) { | ||
adapter := &MockAdapter{} | ||
RegisterAdapter("eu-west-1", "default", adapter) | ||
|
||
if res := HasAdapter("eu-west-1", "default"); !res { | ||
t.Errorf("Expected True received %t", res) | ||
} | ||
|
||
if GetAdapter("eu-west-1", "default") != adapter { | ||
t.Errorf("Expected the given adapter to be returned") | ||
} | ||
} | ||
|
||
func TestHasUnknownProfileAdapter(t *testing.T) { | ||
if res := HasAdapter("eu-west-1", "non-existing-adapter"); res { | ||
t.Errorf("Expected False received %t", res) | ||
} | ||
} | ||
|
||
func TestHasUnknownRegionAdapter(t *testing.T) { | ||
if res := HasAdapter("eu-unknown-1", "non-existing-adapter"); res { | ||
t.Errorf("Expected False received %t", res) | ||
} | ||
} |
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,30 @@ | ||
package adapters | ||
|
||
var registeredAdapters = map[string]map[string]IUserAdapter{} | ||
|
||
func prepareRegionMap(region string) { | ||
if _, exists := registeredAdapters[region]; !exists { | ||
registeredAdapters[region] = make(map[string]IUserAdapter) | ||
} | ||
} | ||
|
||
func RegisterAdapter(region string, profile string, adapter IUserAdapter) { | ||
prepareRegionMap(region) | ||
registeredAdapters[region][profile] = adapter | ||
} | ||
|
||
func HasAdapter(region string, profile string) bool { | ||
if _, exists := registeredAdapters[region]; !exists { | ||
return false | ||
} | ||
|
||
if _, exists := registeredAdapters[region][profile]; !exists { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
func GetAdapter(region string, profile string) IUserAdapter { | ||
return registeredAdapters[region][profile] | ||
} |
Oops, something went wrong.