Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package main |
| 18 | |
| 19 | import ( |
| 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 |
| 31 | type Authentication struct { |
| 32 | Login string |
| 33 | Password string |
| 34 | } |
| 35 | |
| 36 | // GetRequestMetadata gets the current request metadata |
| 37 | func (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 |
| 45 | func (a *Authentication) RequireTransportSecurity() bool { |
| 46 | return true |
| 47 | } |
| 48 | |
| 49 | func 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 | |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 66 | c := api.NewAbstractOLTClient(conn) |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 67 | |
| 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()) |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 73 | 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 Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 74 | 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 | } |