From 7a8b7341873d6269a7f2dbb33640513303a378fa Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Sat, 19 May 2018 13:44:39 -0600 Subject: [PATCH] Add license headers Licenseybird returns. --- pkg/events/context.go | 16 +++++ pkg/events/doc.go | 16 +++++ pkg/events/events.go | 16 +++++ pkg/events/events_test.go | 16 +++++ pkg/events/lua/doc.go | 16 +++++ pkg/events/lua/emitter.go | 16 +++++ pkg/events/lua/emitter_test.go | 16 +++++ pkg/events/lua/load_scripts.go | 16 +++++ pkg/events/lua/load_scripts_test.go | 16 +++++ pkg/events/lua/luamatic.go | 107 ++++++++++++++++++++++++++++ 10 files changed, 251 insertions(+) create mode 100644 pkg/events/lua/luamatic.go diff --git a/pkg/events/context.go b/pkg/events/context.go index d8686c749..2111c0216 100644 --- a/pkg/events/context.go +++ b/pkg/events/context.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + package events import ( diff --git a/pkg/events/doc.go b/pkg/events/doc.go index 7f16be84c..fe6f6dabc 100644 --- a/pkg/events/doc.go +++ b/pkg/events/doc.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + /* Package events provides an event system for Helm. * * This is not a general purpose event framework. It is a system for handling Helm diff --git a/pkg/events/events.go b/pkg/events/events.go index 950f4132a..817675423 100644 --- a/pkg/events/events.go +++ b/pkg/events/events.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + package events const ( diff --git a/pkg/events/events_test.go b/pkg/events/events_test.go index 1e1e5ca3b..7b706a66e 100644 --- a/pkg/events/events_test.go +++ b/pkg/events/events_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + package events import ( diff --git a/pkg/events/lua/doc.go b/pkg/events/lua/doc.go index a77422136..0d48a7621 100644 --- a/pkg/events/lua/doc.go +++ b/pkg/events/lua/doc.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + // Package lua provides Lua event handling bindings // // This package takes the Helm Go event system and extends it on into Lua. The diff --git a/pkg/events/lua/emitter.go b/pkg/events/lua/emitter.go index db78b24a0..53d7de3bf 100644 --- a/pkg/events/lua/emitter.go +++ b/pkg/events/lua/emitter.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + package lua import ( diff --git a/pkg/events/lua/emitter_test.go b/pkg/events/lua/emitter_test.go index d81a35b66..1e8915fce 100644 --- a/pkg/events/lua/emitter_test.go +++ b/pkg/events/lua/emitter_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + package lua import ( diff --git a/pkg/events/lua/load_scripts.go b/pkg/events/lua/load_scripts.go index e93facbca..d28630df8 100644 --- a/pkg/events/lua/load_scripts.go +++ b/pkg/events/lua/load_scripts.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + package lua import ( diff --git a/pkg/events/lua/load_scripts_test.go b/pkg/events/lua/load_scripts_test.go index d177d7a33..2fa3b413e 100644 --- a/pkg/events/lua/load_scripts_test.go +++ b/pkg/events/lua/load_scripts_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + package lua import ( diff --git a/pkg/events/lua/luamatic.go b/pkg/events/lua/luamatic.go new file mode 100644 index 000000000..200298d74 --- /dev/null +++ b/pkg/events/lua/luamatic.go @@ -0,0 +1,107 @@ +/* +Copyright 2018 The Kubernetes Authors 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. +*/ + +package lua + +/* + +import ( + "reflect" + + "github.com/yuin/gopher-lua" +) + +// LuaTagName is the tag to be parsed as a Lua annotation +// This is mutable for nefarious purposes. +var LuaTagName = "lua" + +var ErrUnsupportedKind = errors.New("unsupported kind") + +func luamatic(name string, v interface{}, vm *lua.Lstate) error { + val := reflect.Indirect(reflect.ValueOf(v)) + switch val.Kind() { + // TODO: are reflect.Interface, reflect.Ptr, and reflect.Uintptr okay? + // TODO: can Complex64/128 be represented by Lua + // TODO: is there any processing we need to do on maps, slices, and arrays? + case reflect.UnsafePointer, reflect.Chan, reflect.Invalid: + return ErrUnsupportedKind + case reflect.Struct: + + // In this case, we create a UserData with associated metatable + mt := vm.NewTypeMetatable(name) + // Next we have to walk the struct and find the fields to add. + t := val.Type() + for i := 0; i < t.NumField(); i++ { + f := t.Field(i) + tag := gettag(&f) + iface := val.Field(i).Interface() + if tag.omit { + continue + } + + // Now we have a struct tag on a field, and should make it accessible + // to Lua. Set value to Nil at this point + } + mt.SetField(mt, tag.name, lua.LNil) + vm.SetGlobal(name, mt) + + ud := vm.NewUserData() + ud.Value = v + ud.SetMetatable(ud, vm.GetTypeMetatable(name)) + vm.Push(ud) + return nil + default: + obj.Set(n, v) + for _, a := range aliases { + obj.Set(a, v) + } + return nil + } +} + +func gettag(field *reflect.StructField) luaTag { + t := field.Tag.Get(LuaTagName) + if len(t) == 0 { + return luaTag{name: field.Name} + } + + // We preserve the convention used by JSON, YAML, and other tags so that + // an evil library user can change LuaTagName to something and get rational + // output from this. + data := strings.Split(t, ",") + n := data[0] + if n == "-" { + return luaTag{name: field.Name, omit: true} + } + ot := luaTag{name: n} + if len(data) == 1 { + return ot + } + for _, k := range data[1:] { + switch item := k; { + case strings.HasPrefix(item, "alias="): + ot.aliases = append(ot.aliases, strings.TrimPrefix(item, "alias=")) + } + } + return ot +} + +type luaTag struct { + name string + omit bool + aliases []string +} +*/