forked from vmware/go-vcloud-director
-
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.
Add ability to authorize using a Service Account (vmware#562)
* add ability to authorize using a service account --------- Signed-off-by: Adam Jasinski <jasinskia@vmware.com>
- Loading branch information
Showing
10 changed files
with
175 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,2 @@ | ||
* Add `SetServiceAccountApiToken` method of `*VCDClient` that allows | ||
authenticating using a service account token file and handles the refresh token rotation [GH-562] |
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,75 @@ | ||
//go:build unit || ALL | ||
|
||
/* | ||
* Copyright 2023 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | ||
*/ | ||
|
||
package govcd | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_readFileAndUnmarshalJSON(t *testing.T) { | ||
type args struct { | ||
filename string | ||
object *testEntity | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *testEntity | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "simpleCase", | ||
args: args{ | ||
filename: "test-resources/test.json", | ||
object: &testEntity{}, | ||
}, | ||
want: &testEntity{Name: "test"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "emptyFile", | ||
args: args{ | ||
filename: "test-resources/test_empty.json", | ||
object: &testEntity{}, | ||
}, | ||
want: &testEntity{}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "emptyJSON", | ||
args: args{ | ||
filename: "test-resources/test_emptyjson.json", | ||
object: &testEntity{}, | ||
}, | ||
want: &testEntity{}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "nonexistentFile", | ||
args: args{ | ||
filename: "thisfiledoesntexist.json", | ||
object: &testEntity{}, | ||
}, | ||
want: &testEntity{}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := readFileAndUnmarshalJSON(tt.args.filename, tt.args.object) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("readFileAndUnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
|
||
if !reflect.DeepEqual(tt.args.object, tt.want) { | ||
t.Errorf("readFileAndUnmarshalJSON() = %v, want %v", tt.args.object, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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 @@ | ||
{ "Name": "test" } |
Empty file.
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 @@ | ||
{} |
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