Skip to content

Commit

Permalink
Merge pull request #1783 from ashera96/app-sub-implementation
Browse files Browse the repository at this point in the history
Add Application and Subscription Support
  • Loading branch information
Krishanx92 authored Nov 7, 2023
2 parents 61490d8 + efb1c39 commit 77500ed
Show file tree
Hide file tree
Showing 226 changed files with 12,708 additions and 6,429 deletions.
1 change: 1 addition & 0 deletions adapter/api/proto/wso2/discovery/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ message Api {
BackendJWTTokenInfo backendJWTTokenInfo = 25;
bytes apiDefinitionFile = 26;
string environment = 27;
bool subscriptionValidation = 28;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* 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.
*
*/
syntax = "proto3";

package discovery.service.subscription;

import "envoy/service/discovery/v3/discovery.proto";

option go_package = "github.com/envoyproxy/go-control-plane/wso2/discovery/service/subscription";
option java_package = "org.wso2.apk.enforcer.discovery.service.subscription";
option java_outer_classname = "AppMappingDSProto";
option java_multiple_files = true;
option java_generic_services = true;

// [#protodoc-title: AppMappingDS]
service ApplicationMappingDiscoveryService {
rpc StreamApplicationMappings(stream envoy.service.discovery.v3.DiscoveryRequest)
returns (stream envoy.service.discovery.v3.DiscoveryResponse) {
}
}
45 changes: 33 additions & 12 deletions adapter/api/proto/wso2/discovery/subscription/application.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* 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.
*
*/
syntax = "proto3";

package wso2.discovery.subscription;
Expand All @@ -11,17 +27,22 @@ option java_multiple_files = true;

// Application data model
message Application {
string eventId = 1;
string uuid = 1;
string name = 2;
string uuid = 3;
string owner = 4;
string policy = 5;
map<string, string> attributes = 6;
message Key {
string key = 1;
string keyManager = 2;
}
repeated Key keys = 7;
string organization = 8;
string timeStamp = 9;
string owner = 3;
map<string, string> attributes = 4;
}

message SecuritySchemes {
OAuth2 oAuth2 = 1;
}

message OAuth2 {
repeated Environment environments = 1;
}

message Environment {
string envID = 1;
string applicationIdentifier = 2;
string keyType = 3;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* 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.
*
*/
syntax = "proto3";

package wso2.discovery.subscription;
Expand All @@ -11,12 +27,10 @@ option java_multiple_files = true;

// ApplicationKeyMapping data model
message ApplicationKeyMapping {
string consumerKey = 1;
string keyType = 2;
string keyManager = 3;
int32 applicationId = 4;
int32 tenantId = 5;
string tenantDomain = 6;
int64 timestamp = 7;
string applicationUUID = 8;
string applicationUUID = 1;
string securityScheme = 2;
string applicationIdentifier = 3;
string keyType = 4;
string envID = 5;
int64 timestamp = 6;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* 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.
*
*/
syntax = "proto3";

package wso2.discovery.subscription;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* 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.
*
*/
syntax = "proto3";

package wso2.discovery.subscription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
* limitations under the License.
*
*/
syntax = "proto3";

package utils
package wso2.discovery.subscription;

import (
"github.com/wso2/apk/common-controller/internal/config"
)
option go_package = "github.com/envoyproxy/go-control-plane/wso2/discovery/subscription;subscription";
option java_package = "org.wso2.apk.enforcer.discovery.subscription";
option java_outer_classname = "ApplicationMappingProto";
option java_multiple_files = true;

// GetEnvironment takes the environment of the API. If the value is empty,
// it will return the default environment that is set in the config of the common controller.
func GetEnvironment(environment string) string {
if environment != "" {
return environment
}
return config.ReadConfigs().CommonController.Environment
// [#protodoc-title: ApplicationMapping]

// ApplicationMapping data model
message ApplicationMapping {
string uuid = 1;
string applicationRef = 2;
string subscriptionRef = 3;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* 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.
*
*/
syntax = "proto3";

package wso2.discovery.subscription;

import "wso2/discovery/subscription/applicationmapping.proto";

option go_package = "github.com/envoyproxy/go-control-plane/wso2/discovery/subscription;subscription";
option java_package = "org.wso2.apk.enforcer.discovery.subscription";
option java_outer_classname = "ApplicationMappingListProto";
option java_multiple_files = true;

// [#protodoc-title: ApplicationMappingList]

// ApplicationMappingList data model
message ApplicationMappingList {
repeated ApplicationMapping list = 2;
}
34 changes: 25 additions & 9 deletions adapter/api/proto/wso2/discovery/subscription/subscription.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* 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.
*
*/
syntax = "proto3";

package wso2.discovery.subscription;
Expand All @@ -11,13 +27,13 @@ option java_multiple_files = true;

// Subscription data model
message Subscription {
string eventId = 1;
string applicationRef = 2;
string apiRef = 3;
string policyId = 4;
string subStatus = 5;
string subscriber = 6;
string uuid = 7;
string timeStamp = 8;
string organization = 9;
string subStatus = 1;
string uuid = 2;
string organization = 3;
SubscribedAPI subscribedApi = 4;
}

message SubscribedAPI {
string name = 1;
string version = 2;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* 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.
*
*/
syntax = "proto3";

package wso2.discovery.subscription;
Expand Down
2 changes: 1 addition & 1 deletion adapter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/pelletier/go-toml v1.8.1
github.com/sirupsen/logrus v1.9.0
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -73,6 +72,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230731193218-e0aa005b6bdf // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
Expand Down
19 changes: 4 additions & 15 deletions adapter/internal/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ func init() {

const grpcMaxConcurrentStreams = 1000000

func runManagementServer(conf *config.Config, server xdsv3.Server, enforcerServer wso2_server.Server, enforcerSdsServer wso2_server.Server,
enforcerAppDsSrv wso2_server.Server, enforcerAPIDsSrv wso2_server.Server, enforcerAppPolicyDsSrv wso2_server.Server,
enforcerSubPolicyDsSrv wso2_server.Server, enforcerAppKeyMappingDsSrv wso2_server.Server,
func runManagementServer(conf *config.Config, server xdsv3.Server, enforcerServer wso2_server.Server,
enforcerAPIDsSrv wso2_server.Server, enforcerAppPolicyDsSrv wso2_server.Server, enforcerSubPolicyDsSrv wso2_server.Server,
enforcerKeyManagerDsSrv wso2_server.Server, enforcerRevokedTokenDsSrv wso2_server.Server,
enforcerThrottleDataDsSrv wso2_server.Server, enforcerJwtIssuerDsSrv wso2_server.Server, port uint) {
var grpcOptions []grpc.ServerOption
Expand Down Expand Up @@ -120,12 +119,9 @@ func runManagementServer(conf *config.Config, server xdsv3.Server, enforcerServe
discoveryv3.RegisterAggregatedDiscoveryServiceServer(grpcServer, server)
configservice.RegisterConfigDiscoveryServiceServer(grpcServer, enforcerServer)
apiservice.RegisterApiDiscoveryServiceServer(grpcServer, enforcerServer)
subscriptionservice.RegisterSubscriptionDiscoveryServiceServer(grpcServer, enforcerSdsServer)
subscriptionservice.RegisterApplicationDiscoveryServiceServer(grpcServer, enforcerAppDsSrv)
subscriptionservice.RegisterApiListDiscoveryServiceServer(grpcServer, enforcerAPIDsSrv)
subscriptionservice.RegisterApplicationPolicyDiscoveryServiceServer(grpcServer, enforcerAppPolicyDsSrv)
subscriptionservice.RegisterSubscriptionPolicyDiscoveryServiceServer(grpcServer, enforcerSubPolicyDsSrv)
subscriptionservice.RegisterApplicationKeyMappingDiscoveryServiceServer(grpcServer, enforcerAppKeyMappingDsSrv)
keymanagerservice.RegisterKMDiscoveryServiceServer(grpcServer, enforcerKeyManagerDsSrv)
keymanagerservice.RegisterRevokedTokenDiscoveryServiceServer(grpcServer, enforcerRevokedTokenDsSrv)
subscriptionservice.RegisterJWTIssuerDiscoveryServiceServer(grpcServer, enforcerJwtIssuerDsSrv)
Expand Down Expand Up @@ -166,32 +162,25 @@ func Run(conf *config.Config) {
logger.LoggerAPK.Info("Starting adapter ....")
cache := xds.GetXdsCache()
enforcerCache := xds.GetEnforcerCache()
enforcerSubscriptionCache := xds.GetEnforcerSubscriptionCache()
enforcerApplicationCache := xds.GetEnforcerApplicationCache()
enforcerAPICache := xds.GetEnforcerAPICache()
enforcerApplicationPolicyCache := xds.GetEnforcerApplicationPolicyCache()
enforcerSubscriptionPolicyCache := xds.GetEnforcerSubscriptionPolicyCache()
enforcerApplicationKeyMappingCache := xds.GetEnforcerApplicationKeyMappingCache()
enforcerKeyManagerCache := xds.GetEnforcerKeyManagerCache()
enforcerRevokedTokenCache := xds.GetEnforcerRevokedTokenCache()
enforcerThrottleDataCache := xds.GetEnforcerThrottleDataCache()
enforcerJWtIssuerCache := xds.GetEnforcerJWTIssuerCache()
srv := xdsv3.NewServer(ctx, cache, &routercb.Callbacks{})
enforcerXdsSrv := wso2_server.NewServer(ctx, enforcerCache, &enforcerCallbacks.Callbacks{})
enforcerSdsSrv := wso2_server.NewServer(ctx, enforcerSubscriptionCache, &enforcerCallbacks.Callbacks{})
enforcerAppDsSrv := wso2_server.NewServer(ctx, enforcerApplicationCache, &enforcerCallbacks.Callbacks{})
enforcerJwtIssuerDsSrv := wso2_server.NewServer(ctx, enforcerJWtIssuerCache, &enforcerCallbacks.Callbacks{})
enforcerAPIDsSrv := wso2_server.NewServer(ctx, enforcerAPICache, &enforcerCallbacks.Callbacks{})
enforcerAppPolicyDsSrv := wso2_server.NewServer(ctx, enforcerApplicationPolicyCache, &enforcerCallbacks.Callbacks{})
enforcerSubPolicyDsSrv := wso2_server.NewServer(ctx, enforcerSubscriptionPolicyCache, &enforcerCallbacks.Callbacks{})
enforcerAppKeyMappingDsSrv := wso2_server.NewServer(ctx, enforcerApplicationKeyMappingCache, &enforcerCallbacks.Callbacks{})
enforcerKeyManagerDsSrv := wso2_server.NewServer(ctx, enforcerKeyManagerCache, &enforcerCallbacks.Callbacks{})
enforcerRevokedTokenDsSrv := wso2_server.NewServer(ctx, enforcerRevokedTokenCache, &enforcerCallbacks.Callbacks{})
enforcerThrottleDataDsSrv := wso2_server.NewServer(ctx, enforcerThrottleDataCache, &enforcerCallbacks.Callbacks{})

runManagementServer(conf, srv, enforcerXdsSrv, enforcerSdsSrv, enforcerAppDsSrv, enforcerAPIDsSrv,
enforcerAppPolicyDsSrv, enforcerSubPolicyDsSrv, enforcerAppKeyMappingDsSrv, enforcerKeyManagerDsSrv,
enforcerRevokedTokenDsSrv, enforcerThrottleDataDsSrv, enforcerJwtIssuerDsSrv, port)
runManagementServer(conf, srv, enforcerXdsSrv, enforcerAPIDsSrv, enforcerAppPolicyDsSrv, enforcerSubPolicyDsSrv,
enforcerKeyManagerDsSrv, enforcerRevokedTokenDsSrv, enforcerThrottleDataDsSrv, enforcerJwtIssuerDsSrv, port)

// Set enforcer startup configs
xds.UpdateEnforcerConfig(conf)
Expand Down
Loading

0 comments on commit 77500ed

Please sign in to comment.