-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from okta/m2m_process_credentials
AWS CLI process credentials JSON output
- Loading branch information
Showing
14 changed files
with
282 additions
and
103 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 was deleted.
Oops, something went wrong.
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,35 @@ | ||
/* | ||
* Copyright (c) 2023-Present, Okta, 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. | ||
*/ | ||
|
||
package aws | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCredentialJSON(t *testing.T) { | ||
hbtGo := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) | ||
c := Credential{ | ||
Expiration: &hbtGo, | ||
} | ||
credStr, err := json.Marshal(c) | ||
require.NoError(t, err) | ||
require.Equal(t, `{"Expiration":"2009-11-10T23:00:00Z"}`, string(credStr)) | ||
} |
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,50 @@ | ||
/* | ||
* Copyright (c) 2023-Present, Okta, 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. | ||
*/ | ||
|
||
package output | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/okta/okta-aws-cli/internal/aws" | ||
"github.com/okta/okta-aws-cli/internal/config" | ||
) | ||
|
||
// ProcessCredentials AWS CLI Process Credentials output formatter | ||
// https://docs.aws.amazon.com/sdkref/latest/guide/feature-process-credentials.html | ||
type ProcessCredentials struct{} | ||
|
||
// NewProcessCredentials Creates a new ProcessCredentials | ||
func NewProcessCredentials() *ProcessCredentials { | ||
return &ProcessCredentials{} | ||
} | ||
|
||
// Output Satisfies the Outputter interface and outputs AWS credentials as JSON | ||
// to STDOUT | ||
func (p *ProcessCredentials) Output(c *config.Config, ac *aws.Credential) error { | ||
// See AWS docs: "Note As of this writing, the Version key must be set to 1. | ||
// This might increment over time as the structure evolves." | ||
ac.Version = 1 | ||
|
||
credJSON, err := json.MarshalIndent(ac, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("%s", credJSON) | ||
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,45 @@ | ||
/* | ||
* Copyright (c) 2023-Present, Okta, 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. | ||
*/ | ||
|
||
package output | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
"github.com/okta/okta-aws-cli/internal/aws" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestProcessCredentials(t *testing.T) { | ||
credsJSON := ` | ||
{ | ||
"Version": 1, | ||
"AccessKeyId": "an AWS access key", | ||
"SecretAccessKey": "your AWS secret access key", | ||
"SessionToken": "the AWS session token for temporary credentials", | ||
"Expiration": "2009-11-10T23:00:00Z" | ||
}` | ||
result := aws.Credential{} | ||
err := json.Unmarshal([]byte(credsJSON), &result) | ||
require.NoError(t, err) | ||
require.Equal(t, "an AWS access key", result.AccessKeyID) | ||
require.Equal(t, "your AWS secret access key", result.SecretAccessKey) | ||
require.Equal(t, "the AWS session token for temporary credentials", result.SessionToken) | ||
when := time.Time(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) | ||
require.Equal(t, &when, result.Expiration) | ||
} |
Oops, something went wrong.