blob: 94cd1e51e32bd42d27d1f704bdaa13a404a79da7 [file] [log] [blame]
Author Namea594e632018-08-10 11:33:58 -04001/*
2 Copyright 2017 the original author or authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17package main
18
19import (
20 "log"
21
22 "runtime/debug"
23
24 "gerrit.opencord.org/abstract-olt/api"
25 "golang.org/x/net/context"
26 "google.golang.org/grpc"
27 "google.golang.org/grpc/credentials"
28)
29
30// Authentication holds the login/password
31type Authentication struct {
32 Login string
33 Password string
34}
35
36// GetRequestMetadata gets the current request metadata
37func (a *Authentication) GetRequestMetadata(context.Context, ...string) (map[string]string, error) {
38 return map[string]string{
39 "login": a.Login,
40 "password": a.Password,
41 }, nil
42}
43
44// RequireTransportSecurity indicates whether the credentials requires transport security
45func (a *Authentication) RequireTransportSecurity() bool {
46 return true
47}
48
49func main() {
50 var conn *grpc.ClientConn
51 creds, err := credentials.NewClientTLSFromFile("cert/server.crt", "AbstractOLT.dev.atl.foundry.att.com")
52 if err != nil {
53 log.Fatalf("could not load tls cert: %s", err)
54 }
55 // Setup the login/pass
56 auth := Authentication{
57 Login: "john",
58 Password: "doe",
59 }
60 conn, err = grpc.Dial(":7777", grpc.WithTransportCredentials(creds), grpc.WithPerRPCCredentials(&auth))
61 if err != nil {
62 log.Fatalf("did not connect: %s", err)
63 }
64 defer conn.Close()
65
donNewtonAlpha5234b132018-08-16 14:12:28 -040066 c := api.NewAbstractOLTClient(conn)
Author Namea594e632018-08-10 11:33:58 -040067
68 response, err := c.CreateChassis(context.Background(), &api.AddChassisMessage{CLLI: "my cilli", VCoreIP: "192.168.0.1", VCorePort: 9191})
69 if err != nil {
70 log.Fatalf("Error when calling SayHello: %s", err)
71 }
72 log.Printf("Response from server: %s", response.GetDeviceID())
donNewtonAlpha5234b132018-08-16 14:12:28 -040073 newResponse, err := c.CreateOLTChassis(context.Background(), &api.AddOLTChassisMessage{CLLI: "my cilli", SlotIP: "12.2.2.0", SlotPort: 9191, Hostname: "SlotOne", Type: api.AddOLTChassisMessage_edgecore})
Author Namea594e632018-08-10 11:33:58 -040074 if err != nil {
75 debug.PrintStack()
76 log.Fatalf("Error when calling SayHello: %s", err)
77 }
78 log.Printf("Response from server: %s", newResponse.GetDeviceID())
79}