Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authz bundle url to env #116

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion env/iasConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ type Identity interface {
GetCertificate() string // Returns the client certificate. Optional
GetKey() string // Returns the client certificate key. Optional
GetCertificateExpiresAt() string // Returns the client certificate expiration time. Optional
GetAuthorizationInstanceID() string // Returns the AMS instance id if authorization is enabled
IsCertificateBased() bool // Returns true, in case GetCertificate() and GetKey returns non-empty values
GetAuthorizationInstanceID() string // Returns the AMS instance id if authorization is enabled
GetAuthorizationBundleURL() string // Returns the AMS Bundle URL if authorization is enabled
}

// DefaultIdentity represents the parsed credentials from the ias binding
Expand All @@ -57,6 +58,7 @@ type DefaultIdentity struct {
Key string `json:"key"`
CertificateExpiresAt string `json:"certificate_expires_at"`
AuthorizationInstanceID string `json:"authorization_instance_id"`
AuthorizationBundleURL string `json:"authorization_bundle_url"`
}

// ParseIdentityConfig parses the IAS config from the applications environment
Expand Down Expand Up @@ -239,3 +241,8 @@ func (c DefaultIdentity) GetCertificateExpiresAt() string {
func (c DefaultIdentity) GetAuthorizationInstanceID() string {
return c.AuthorizationInstanceID
}

// GetAuthorizationBundleURL implements the env.Identity interface.
func (c DefaultIdentity) GetAuthorizationBundleURL() string {
return c.AuthorizationBundleURL
}
5 changes: 3 additions & 2 deletions env/iasConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var testConfig = &DefaultIdentity{
ZoneUUID: uuid.MustParse("bef12345-de57-480f-be92-1d8c1c7abf16"),
AppTID: "70cd0de3-528a-4655-b56a-5862591def5c",
AuthorizationInstanceID: "8d5423d7-bda4-461c-9670-1b9adc142f0a",
AuthorizationBundleURL: "https://mytenant.accounts400.ondemand.com/sap/ams/v1/bundles",
}

func TestParseIdentityConfig(t *testing.T) {
Expand All @@ -35,13 +36,13 @@ func TestParseIdentityConfig(t *testing.T) {
}{
{
name: "[CF] single identity service instance bound",
env: "{\"identity\":[{\"binding_name\":null,\"credentials\":{\"clientid\":\"cef76757-de57-480f-be92-1d8c1c7abf16\",\"clientsecret\":\"[the_CLIENT.secret:3[/abc\",\"domains\":[\"accounts400.ondemand.com\",\"my.arbitrary.domain\"],\"token_url\":\"https://mytenant.accounts400.ondemand.com/oauth2/token\",\"url\":\"https://mytenant.accounts400.ondemand.com\",\"zone_uuid\":\"bef12345-de57-480f-be92-1d8c1c7abf16\", \"app_tid\":\"70cd0de3-528a-4655-b56a-5862591def5c\", \"authorization_instance_id\":\"8d5423d7-bda4-461c-9670-1b9adc142f0a\"},\"instance_name\":\"my-ams-instance\",\"label\":\"identity\",\"name\":\"my-ams-instance\",\"plan\":\"application\",\"provider\":null,\"syslog_drain_url\":null,\"tags\":[\"ias\"],\"volume_mounts\":[]}]}",
env: `{"identity":[{"binding_name":null,"credentials":{"clientid":"cef76757-de57-480f-be92-1d8c1c7abf16","clientsecret":"[the_CLIENT.secret:3[/abc","domains":["accounts400.ondemand.com","my.arbitrary.domain"],"token_url":"https://mytenant.accounts400.ondemand.com/oauth2/token","url":"https://mytenant.accounts400.ondemand.com","zone_uuid":"bef12345-de57-480f-be92-1d8c1c7abf16", "app_tid":"70cd0de3-528a-4655-b56a-5862591def5c", "authorization_instance_id":"8d5423d7-bda4-461c-9670-1b9adc142f0a", "authorization_bundle_url":"https://mytenant.accounts400.ondemand.com/sap/ams/v1/bundles"},"instance_name":"my-ams-instance","label":"identity","name":"my-ams-instance","plan":"application","provider":null,"syslog_drain_url":null,"tags":["ias"],"volume_mounts":[]}]}`,
want: testConfig,
wantErr: false,
},
{
name: "[CF] multiple identity service bindings",
env: "{\"identity\":[{\"binding_name\":null,\"credentials\":{\"clientid\":\"cef76757-de57-480f-be92-1d8c1c7abf16\",\"clientsecret\":\"[the_CLIENT.secret:3[/abc\",\"domains\":[\"accounts400.ondemand.com\",\"my.arbitrary.domain\"],\"token_url\":\"https://mytenant.accounts400.ondemand.com/oauth2/token\",\"url\":\"https://mytenant.accounts400.ondemand.com\"},\"instance_name\":\"my-ams-instance\",\"label\":\"identity\",\"name\":\"my-ams-instance\",\"plan\":\"application\",\"provider\":null,\"syslog_drain_url\":null,\"tags\":[\"ias\"],\"volume_mounts\":[]},{\"binding_name\":null,\"credentials\":{\"clientid\":\"cef76757-de57-480f-be92-1d8c1c7abf16\",\"clientsecret\":\"the_CLIENT.secret:3[/abc\",\"domain\":\"accounts400.ondemand.com\",\"token_url\":\"https://mytenant.accounts400.ondemand.com/oauth2/token\",\"url\":\"https://mytenant.accounts400.ondemand.com\"},\"instance_name\":\"my-ams-instance\",\"label\":\"identity\",\"name\":\"my-ams-instance\",\"plan\":\"application\",\"provider\":null,\"syslog_drain_url\":null,\"tags\":[\"ias\"],\"volume_mounts\":[]}]}",
env: `{"identity":[{"binding_name":null,"credentials":{"clientid":"cef76757-de57-480f-be92-1d8c1c7abf16","clientsecret":"[the_CLIENT.secret:3[/abc","domains":["accounts400.ondemand.com","my.arbitrary.domain"],"token_url":"https://mytenant.accounts400.ondemand.com/oauth2/token","url":"https://mytenant.accounts400.ondemand.com"},"instance_name":"my-ams-instance","label":"identity","name":"my-ams-instance","plan":"application","provider":null,"syslog_drain_url":null,"tags":["ias"],"volume_mounts":[]},{"binding_name":null,"credentials":{"clientid":"cef76757-de57-480f-be92-1d8c1c7abf16","clientsecret":"the_CLIENT.secret:3[/abc","domain":"accounts400.ondemand.com","token_url":"https://mytenant.accounts400.ondemand.com/oauth2/token","url":"https://mytenant.accounts400.ondemand.com"},"instance_name":"my-ams-instance","label":"identity","name":"my-ams-instance","plan":"application","provider":null,"syslog_drain_url":null,"tags":["ias"],"volume_mounts":[]}]}`,
want: nil,
wantErr: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"url": "https://mytenant.accounts400.ondemand.com",
"zone_uuid": "bef12345-de57-480f-be92-1d8c1c7abf16",
"app_tid": "70cd0de3-528a-4655-b56a-5862591def5c",
"authorization_instance_id": "8d5423d7-bda4-461c-9670-1b9adc142f0a"
"authorization_instance_id": "8d5423d7-bda4-461c-9670-1b9adc142f0a",
"authorization_bundle_url": "https://mytenant.accounts400.ondemand.com/sap/ams/v1/bundles"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://mytenant.accounts400.ondemand.com/sap/ams/v1/bundles
4 changes: 4 additions & 0 deletions mocks/mockServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ type MockConfig struct {
Key string
CertificateExpiresAt string
AuthorizationInstanceID string
AuthorizationBundleURL string
}

// GetClientID implements the env.Identity interface.
Expand Down Expand Up @@ -380,6 +381,9 @@ func (c MockConfig) IsCertificateBased() bool {
// GetAuthorizationInstanceID implements the env.Identity interface.
func (c MockConfig) GetAuthorizationInstanceID() string { return c.AuthorizationInstanceID }

// GetAuthorizationInstanceID implements the env.Identity interface.
func (c MockConfig) GetAuthorizationBundleURL() string { return c.AuthorizationBundleURL }

// JSONWebKeySet represents the data which is returned by the tenants /oauth2/certs endpoint
type JSONWebKeySet struct {
Keys []*JSONWebKey `json:"keys"`
Expand Down
Loading