Skip to content

Commit 025cb87

Browse files
authored
Add client source files. (istio#3)
* Add client source files. * Remove servicecontrol build target. * Add options as private variable. * Add bazel build in travis.yml.
1 parent d0b7624 commit 025cb87

File tree

8 files changed

+324
-0
lines changed

8 files changed

+324
-0
lines changed

mixerclient/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
*.exe
2828
*.out
2929
*.app
30+
31+
/bazel-*

mixerclient/.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ install:
2424

2525
script:
2626
- script/check-style
27+
- bazel build :all

mixerclient/BUILD

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2017 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
licenses(["notice"])
16+
17+
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
18+
19+
cc_library(
20+
name = "mixer_client_lib",
21+
srcs = [
22+
"src/client_impl.h",
23+
"src/client_impl.cc",
24+
],
25+
hdrs = [
26+
"include/client.h",
27+
"include/options.h",
28+
],
29+
visibility = ["//visibility:public"],
30+
deps = [
31+
"//external:boringssl_crypto",
32+
"//external:mixer_api_cc_proto",
33+
],
34+
)

mixerclient/BUILD.googleapis

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
licenses(["notice"])
2+
3+
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
4+
5+
cc_proto_library(
6+
name = "service_config",
7+
srcs = [
8+
"google/api/annotations.proto",
9+
"google/api/auth.proto",
10+
"google/api/backend.proto",
11+
"google/api/billing.proto",
12+
"google/api/consumer.proto",
13+
"google/api/context.proto",
14+
"google/api/control.proto",
15+
"google/api/documentation.proto",
16+
"google/api/endpoint.proto",
17+
"google/api/http.proto",
18+
"google/api/label.proto",
19+
"google/api/log.proto",
20+
"google/api/logging.proto",
21+
"google/api/metric.proto",
22+
"google/api/monitored_resource.proto",
23+
"google/api/monitoring.proto",
24+
"google/api/service.proto",
25+
"google/api/system_parameter.proto",
26+
"google/api/usage.proto",
27+
"google/rpc/status.proto",
28+
],
29+
include = ".",
30+
visibility = ["//visibility:public"],
31+
deps = [
32+
"//external:cc_wkt_protos",
33+
],
34+
protoc = "//external:protoc",
35+
default_runtime = "//external:protobuf",
36+
)

mixerclient/BUILD.mixerapi

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
#
17+
licenses(["notice"])
18+
19+
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
20+
21+
cc_proto_library(
22+
name = "mixer_api_cc_proto",
23+
srcs = glob(
24+
["mixer/api/v1/*.proto"],
25+
),
26+
default_runtime = "//external:protobuf",
27+
protoc = "//external:protoc",
28+
visibility = ["//visibility:public"],
29+
deps = [
30+
"//external:cc_wkt_protos",
31+
"//external:service_config",
32+
],
33+
)

mixerclient/WORKSPACE

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2017 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# A Bazel (http://bazel.io) workspace for Istio Mixer client
16+
17+
git_repository(
18+
name = "boringssl",
19+
commit = "2f29d38cc5e6c1bfae4ce22b4b032fb899cdb705", # 2016-07-12
20+
remote = "https://boringssl.googlesource.com/boringssl",
21+
)
22+
23+
bind(
24+
name = "boringssl_crypto",
25+
actual = "@boringssl//:crypto",
26+
)
27+
28+
git_repository(
29+
name = "protobuf_git",
30+
commit = "a428e42072765993ff674fda72863c9f1aa2d268", # v3.1.0
31+
remote = "https://github.com/google/protobuf.git",
32+
)
33+
34+
bind(
35+
name = "protoc",
36+
actual = "@protobuf_git//:protoc",
37+
)
38+
39+
bind(
40+
name = "protobuf",
41+
actual = "@protobuf_git//:protobuf",
42+
)
43+
44+
bind(
45+
name = "cc_wkt_protos",
46+
actual = "@protobuf_git//:cc_wkt_protos",
47+
)
48+
49+
bind(
50+
name = "cc_wkt_protos_genproto",
51+
actual = "@protobuf_git//:cc_wkt_protos_genproto",
52+
)
53+
54+
new_git_repository(
55+
name = "googleapis_git",
56+
commit = "6c1d6d4067364a21f8ffefa3401b213d652bf121", # common-protos-1_3_1
57+
remote = "https://github.com/googleapis/googleapis.git",
58+
build_file = "BUILD.googleapis",
59+
)
60+
61+
bind(
62+
name = "service_config",
63+
actual = "@googleapis_git//:service_config",
64+
)
65+
66+
bind(
67+
name = "service_config_genproto",
68+
actual = "@googleapis_git//:service_config_genproto",
69+
)
70+
71+
new_git_repository(
72+
name = "mixerapi_git",
73+
commit = "fc5a396185edc72d06d1937f30a8148a37d4fc1b",
74+
remote = "https://github.com/istio/api.git",
75+
build_file = "BUILD.mixerapi",
76+
)
77+
bind(
78+
name = "mixer_api_cc_proto",
79+
actual = "@mixerapi_git//:mixer_api_cc_proto",
80+
)

mixerclient/src/client_impl.cc

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* Copyright 2017 Google Inc. All Rights Reserved.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
#include "src/client_impl.h"
16+
#include "mixer/api/v1/service.pb.h"
17+
18+
using ::istio::mixer::v1::CheckRequest;
19+
using ::istio::mixer::v1::CheckResponse;
20+
using ::istio::mixer::v1::ReportRequest;
21+
using ::istio::mixer::v1::ReportResponse;
22+
using ::istio::mixer::v1::QuotaRequest;
23+
using ::istio::mixer::v1::QuotaResponse;
24+
25+
using ::google::protobuf::util::Status;
26+
using ::google::protobuf::util::error::Code;
27+
28+
namespace istio {
29+
namespace mixer_client {
30+
31+
MixerClientImpl::MixerClientImpl(MixerClientOptions &options)
32+
: options_(options) {}
33+
34+
MixerClientImpl::~MixerClientImpl() {}
35+
36+
void MixerClientImpl::Check(const CheckRequest &check_request,
37+
CheckResponse *check_response,
38+
DoneFunc on_check_done) {
39+
if (options_.check_transport == NULL) {
40+
on_check_done(Status(Code::INVALID_ARGUMENT, "transport is NULL."));
41+
return;
42+
}
43+
44+
options_.check_transport(check_request, check_response, on_check_done);
45+
}
46+
47+
void MixerClientImpl::Report(const ReportRequest &report_request,
48+
ReportResponse *report_response,
49+
DoneFunc on_report_done) {
50+
if (options_.report_transport == NULL) {
51+
on_report_done(Status(Code::INVALID_ARGUMENT, "transport is NULL."));
52+
return;
53+
}
54+
55+
options_.report_transport(report_request, report_response, on_report_done);
56+
}
57+
58+
void MixerClientImpl::Quota(const QuotaRequest &quota_request,
59+
QuotaResponse *quota_response,
60+
DoneFunc on_quota_done) {
61+
if (options_.quota_transport == NULL) {
62+
on_quota_done(Status(Code::INVALID_ARGUMENT, "transport is NULL."));
63+
return;
64+
}
65+
66+
options_.quota_transport(quota_request, quota_response, on_quota_done);
67+
}
68+
69+
// Creates a MixerClient object.
70+
std::unique_ptr<MixerClient> CreateMixerClient(MixerClientOptions &options) {
71+
return std::unique_ptr<MixerClient>(new MixerClientImpl(options));
72+
}
73+
74+
} // namespace mixer_client
75+
} // namespace istio

mixerclient/src/client_impl.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Copyright 2017 Google Inc. All Rights Reserved.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
#ifndef MIXERCLIENT_CLIENT_IMPL_H
17+
#define MIXERCLIENT_CLIENT_IMPL_H
18+
19+
#include "include/client.h"
20+
21+
namespace istio {
22+
namespace mixer_client {
23+
24+
class MixerClientImpl : public MixerClient {
25+
public:
26+
// Constructor
27+
MixerClientImpl(MixerClientOptions &options);
28+
29+
// Destructor
30+
virtual ~MixerClientImpl();
31+
32+
// The async call.
33+
// on_check_done is called with the check status after cached
34+
// check_response is returned in case of cache hit, otherwise called after
35+
// check_response is returned from the Controller service.
36+
//
37+
// check_response must be alive until on_check_done is called.
38+
virtual void Check(const ::istio::mixer::v1::CheckRequest &check_request,
39+
::istio::mixer::v1::CheckResponse *check_response,
40+
DoneFunc on_check_done);
41+
42+
// This is async call. on_report_done is always called when the
43+
// report request is finished.
44+
virtual void Report(const ::istio::mixer::v1::ReportRequest &report_request,
45+
::istio::mixer::v1::ReportResponse *report_response,
46+
DoneFunc on_report_done);
47+
48+
// This is async call. on_quota_done is always called when the
49+
// quota request is finished.
50+
virtual void Quota(const ::istio::mixer::v1::QuotaRequest &quota_request,
51+
::istio::mixer::v1::QuotaResponse *quota_response,
52+
DoneFunc on_quota_done);
53+
54+
private:
55+
const MixerClientOptions &options_;
56+
57+
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MixerClientImpl);
58+
};
59+
60+
} // namespace mixer_client
61+
} // namespace istio
62+
63+
#endif // MIXERCLIENT_CLIENT_IMPL_H

0 commit comments

Comments
 (0)