repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
looplab/eventhorizon | eventbus/gcp/eventbus.go | AggregateID | func (e event) AggregateID() uuid.UUID {
id, err := uuid.Parse(e.evt.AggregateID)
if err != nil {
return uuid.Nil
}
return id
} | go | func (e event) AggregateID() uuid.UUID {
id, err := uuid.Parse(e.evt.AggregateID)
if err != nil {
return uuid.Nil
}
return id
} | [
"func",
"(",
"e",
"event",
")",
"AggregateID",
"(",
")",
"uuid",
".",
"UUID",
"{",
"id",
",",
"err",
":=",
"uuid",
".",
"Parse",
"(",
"e",
".",
"evt",
".",
"AggregateID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"uuid",
".",
"Nil",
"... | // AggrgateID implements the AggrgateID method of the eventhorizon.Event interface. | [
"AggrgateID",
"implements",
"the",
"AggrgateID",
"method",
"of",
"the",
"eventhorizon",
".",
"Event",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventbus/gcp/eventbus.go#L281-L287 | train |
looplab/eventhorizon | eventhandler.go | HandleEvent | func (h EventHandlerFunc) HandleEvent(ctx context.Context, e Event) error {
return h(ctx, e)
} | go | func (h EventHandlerFunc) HandleEvent(ctx context.Context, e Event) error {
return h(ctx, e)
} | [
"func",
"(",
"h",
"EventHandlerFunc",
")",
"HandleEvent",
"(",
"ctx",
"context",
".",
"Context",
",",
"e",
"Event",
")",
"error",
"{",
"return",
"h",
"(",
"ctx",
",",
"e",
")",
"\n",
"}"
] | // HandleEvent implements the HandleEvent method of the EventHandler. | [
"HandleEvent",
"implements",
"the",
"HandleEvent",
"method",
"of",
"the",
"EventHandler",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler.go#L40-L42 | train |
looplab/eventhorizon | eventhandler.go | UseEventHandlerMiddleware | func UseEventHandlerMiddleware(h EventHandler, middleware ...EventHandlerMiddleware) EventHandler {
// Apply in reverse order.
for i := len(middleware) - 1; i >= 0; i-- {
m := middleware[i]
h = m(h)
}
return h
} | go | func UseEventHandlerMiddleware(h EventHandler, middleware ...EventHandlerMiddleware) EventHandler {
// Apply in reverse order.
for i := len(middleware) - 1; i >= 0; i-- {
m := middleware[i]
h = m(h)
}
return h
} | [
"func",
"UseEventHandlerMiddleware",
"(",
"h",
"EventHandler",
",",
"middleware",
"...",
"EventHandlerMiddleware",
")",
"EventHandler",
"{",
"// Apply in reverse order.",
"for",
"i",
":=",
"len",
"(",
"middleware",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
... | // UseEventHandlerMiddleware wraps a EventHandler in one or more middleware. | [
"UseEventHandlerMiddleware",
"wraps",
"a",
"EventHandler",
"in",
"one",
"or",
"more",
"middleware",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler.go#L55-L62 | train |
looplab/eventhorizon | eventstore/mongodb/eventstore.go | NewEventStoreWithSession | func NewEventStoreWithSession(session *mgo.Session, dbPrefix string) (*EventStore, error) {
if session == nil {
return nil, ErrNoDBSession
}
s := &EventStore{
session: session,
dbPrefix: dbPrefix,
}
return s, nil
} | go | func NewEventStoreWithSession(session *mgo.Session, dbPrefix string) (*EventStore, error) {
if session == nil {
return nil, ErrNoDBSession
}
s := &EventStore{
session: session,
dbPrefix: dbPrefix,
}
return s, nil
} | [
"func",
"NewEventStoreWithSession",
"(",
"session",
"*",
"mgo",
".",
"Session",
",",
"dbPrefix",
"string",
")",
"(",
"*",
"EventStore",
",",
"error",
")",
"{",
"if",
"session",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNoDBSession",
"\n",
"}",
"\n\n",
... | // NewEventStoreWithSession creates a new EventStore with a session. | [
"NewEventStoreWithSession",
"creates",
"a",
"new",
"EventStore",
"with",
"a",
"session",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventstore/mongodb/eventstore.go#L71-L82 | train |
looplab/eventhorizon | eventstore/mongodb/eventstore.go | Clear | func (s *EventStore) Clear(ctx context.Context) error {
if err := s.session.DB(s.dbName(ctx)).C("events").DropCollection(); err != nil {
return eh.EventStoreError{
BaseErr: err,
Err: ErrCouldNotClearDB,
Namespace: eh.NamespaceFromContext(ctx),
}
}
return nil
} | go | func (s *EventStore) Clear(ctx context.Context) error {
if err := s.session.DB(s.dbName(ctx)).C("events").DropCollection(); err != nil {
return eh.EventStoreError{
BaseErr: err,
Err: ErrCouldNotClearDB,
Namespace: eh.NamespaceFromContext(ctx),
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"EventStore",
")",
"Clear",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"err",
":=",
"s",
".",
"session",
".",
"DB",
"(",
"s",
".",
"dbName",
"(",
"ctx",
")",
")",
".",
"C",
"(",
"\"",
"\"",
")",
"."... | // Clear clears the event storage. | [
"Clear",
"clears",
"the",
"event",
"storage",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventstore/mongodb/eventstore.go#L281-L290 | train |
looplab/eventhorizon | eventstore/mongodb/eventstore.go | String | func (e event) String() string {
return fmt.Sprintf("%s@%d", e.dbEvent.EventType, e.dbEvent.Version)
} | go | func (e event) String() string {
return fmt.Sprintf("%s@%d", e.dbEvent.EventType, e.dbEvent.Version)
} | [
"func",
"(",
"e",
"event",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"dbEvent",
".",
"EventType",
",",
"e",
".",
"dbEvent",
".",
"Version",
")",
"\n",
"}"
] | // String implements the String method of the eventhorizon.Event interface. | [
"String",
"implements",
"the",
"String",
"method",
"of",
"the",
"eventhorizon",
".",
"Event",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventstore/mongodb/eventstore.go#L392-L394 | train |
looplab/eventhorizon | examples/guestlist/domain/projectors.go | Project | func (p *InvitationProjector) Project(ctx context.Context, event eh.Event, entity eh.Entity) (eh.Entity, error) {
i, ok := entity.(*Invitation)
if !ok {
return nil, errors.New("model is of incorrect type")
}
// Apply the changes for the event.
switch event.EventType() {
case InviteCreatedEvent:
data, ok := e... | go | func (p *InvitationProjector) Project(ctx context.Context, event eh.Event, entity eh.Entity) (eh.Entity, error) {
i, ok := entity.(*Invitation)
if !ok {
return nil, errors.New("model is of incorrect type")
}
// Apply the changes for the event.
switch event.EventType() {
case InviteCreatedEvent:
data, ok := e... | [
"func",
"(",
"p",
"*",
"InvitationProjector",
")",
"Project",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"eh",
".",
"Event",
",",
"entity",
"eh",
".",
"Entity",
")",
"(",
"eh",
".",
"Entity",
",",
"error",
")",
"{",
"i",
",",
"ok",
":=",
... | // Project implements the Project method of the Projector interface. | [
"Project",
"implements",
"the",
"Project",
"method",
"of",
"the",
"Projector",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/projectors.go#L65-L100 | train |
looplab/eventhorizon | examples/guestlist/domain/projectors.go | NewGuestListProjector | func NewGuestListProjector(repo eh.ReadWriteRepo, eventID uuid.UUID) *GuestListProjector {
p := &GuestListProjector{
repo: repo,
eventID: eventID,
}
return p
} | go | func NewGuestListProjector(repo eh.ReadWriteRepo, eventID uuid.UUID) *GuestListProjector {
p := &GuestListProjector{
repo: repo,
eventID: eventID,
}
return p
} | [
"func",
"NewGuestListProjector",
"(",
"repo",
"eh",
".",
"ReadWriteRepo",
",",
"eventID",
"uuid",
".",
"UUID",
")",
"*",
"GuestListProjector",
"{",
"p",
":=",
"&",
"GuestListProjector",
"{",
"repo",
":",
"repo",
",",
"eventID",
":",
"eventID",
",",
"}",
"\... | // NewGuestListProjector creates a new GuestListProjector. | [
"NewGuestListProjector",
"creates",
"a",
"new",
"GuestListProjector",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/projectors.go#L128-L134 | train |
looplab/eventhorizon | command.go | UnregisterCommand | func UnregisterCommand(commandType CommandType) {
if commandType == CommandType("") {
panic("eventhorizon: attempt to unregister empty command type")
}
commandsMu.Lock()
defer commandsMu.Unlock()
if _, ok := commands[commandType]; !ok {
panic(fmt.Sprintf("eventhorizon: unregister of non-registered type %q", c... | go | func UnregisterCommand(commandType CommandType) {
if commandType == CommandType("") {
panic("eventhorizon: attempt to unregister empty command type")
}
commandsMu.Lock()
defer commandsMu.Unlock()
if _, ok := commands[commandType]; !ok {
panic(fmt.Sprintf("eventhorizon: unregister of non-registered type %q", c... | [
"func",
"UnregisterCommand",
"(",
"commandType",
"CommandType",
")",
"{",
"if",
"commandType",
"==",
"CommandType",
"(",
"\"",
"\"",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"commandsMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"commands... | // UnregisterCommand removes the registration of the command factory for
// a type. This is mainly useful in mainenance situations where the command type
// needs to be switched at runtime. | [
"UnregisterCommand",
"removes",
"the",
"registration",
"of",
"the",
"command",
"factory",
"for",
"a",
"type",
".",
"This",
"is",
"mainly",
"useful",
"in",
"mainenance",
"situations",
"where",
"the",
"command",
"type",
"needs",
"to",
"be",
"switched",
"at",
"ru... | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/command.go#L87-L98 | train |
looplab/eventhorizon | command.go | CreateCommand | func CreateCommand(commandType CommandType) (Command, error) {
commandsMu.RLock()
defer commandsMu.RUnlock()
if factory, ok := commands[commandType]; ok {
return factory(), nil
}
return nil, ErrCommandNotRegistered
} | go | func CreateCommand(commandType CommandType) (Command, error) {
commandsMu.RLock()
defer commandsMu.RUnlock()
if factory, ok := commands[commandType]; ok {
return factory(), nil
}
return nil, ErrCommandNotRegistered
} | [
"func",
"CreateCommand",
"(",
"commandType",
"CommandType",
")",
"(",
"Command",
",",
"error",
")",
"{",
"commandsMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"commandsMu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"factory",
",",
"ok",
":=",
"commands",
"[",... | // CreateCommand creates an command of a type with an ID using the factory
// registered with RegisterCommand. | [
"CreateCommand",
"creates",
"an",
"command",
"of",
"a",
"type",
"with",
"an",
"ID",
"using",
"the",
"factory",
"registered",
"with",
"RegisterCommand",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/command.go#L102-L109 | train |
looplab/eventhorizon | command.go | CheckCommand | func CheckCommand(cmd Command) error {
rv := reflect.Indirect(reflect.ValueOf(cmd))
rt := rv.Type()
for i := 0; i < rt.NumField(); i++ {
field := rt.Field(i)
if field.PkgPath != "" {
continue // Skip private field.
}
tag := field.Tag.Get("eh")
if tag == "optional" {
continue // Optional field.
}
... | go | func CheckCommand(cmd Command) error {
rv := reflect.Indirect(reflect.ValueOf(cmd))
rt := rv.Type()
for i := 0; i < rt.NumField(); i++ {
field := rt.Field(i)
if field.PkgPath != "" {
continue // Skip private field.
}
tag := field.Tag.Get("eh")
if tag == "optional" {
continue // Optional field.
}
... | [
"func",
"CheckCommand",
"(",
"cmd",
"Command",
")",
"error",
"{",
"rv",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"cmd",
")",
")",
"\n",
"rt",
":=",
"rv",
".",
"Type",
"(",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i"... | // CheckCommand checks a command for errors. | [
"CheckCommand",
"checks",
"a",
"command",
"for",
"errors",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/command.go#L121-L141 | train |
looplab/eventhorizon | eventhandler/cron/eventhandler.go | ScheduleEvent | func (h *EventHandler) ScheduleEvent(ctx context.Context, cronLine string, eventFunc func(time.Time) eh.Event) error {
expr, err := cronexpr.Parse(cronLine)
if err != nil {
return err
}
go func() {
for {
nextTime := expr.Next(time.Now())
select {
case <-time.After(nextTime.Sub(time.Now())):
h.even... | go | func (h *EventHandler) ScheduleEvent(ctx context.Context, cronLine string, eventFunc func(time.Time) eh.Event) error {
expr, err := cronexpr.Parse(cronLine)
if err != nil {
return err
}
go func() {
for {
nextTime := expr.Next(time.Now())
select {
case <-time.After(nextTime.Sub(time.Now())):
h.even... | [
"func",
"(",
"h",
"*",
"EventHandler",
")",
"ScheduleEvent",
"(",
"ctx",
"context",
".",
"Context",
",",
"cronLine",
"string",
",",
"eventFunc",
"func",
"(",
"time",
".",
"Time",
")",
"eh",
".",
"Event",
")",
"error",
"{",
"expr",
",",
"err",
":=",
"... | // ScheduleEvent schedules an event to be sent on regular intervals, using
// a line in the crontab format to setup the timing. The eventFunc should create
// the event to send given the triggered time as input. Cancelling the context
// will stop the triggering of more events. | [
"ScheduleEvent",
"schedules",
"an",
"event",
"to",
"be",
"sent",
"on",
"regular",
"intervals",
"using",
"a",
"line",
"in",
"the",
"crontab",
"format",
"to",
"setup",
"the",
"timing",
".",
"The",
"eventFunc",
"should",
"create",
"the",
"event",
"to",
"send",
... | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler/cron/eventhandler.go#L54-L73 | train |
looplab/eventhorizon | matcher.go | MatchEvent | func MatchEvent(t EventType) EventMatcher {
return func(e Event) bool {
return e != nil && e.EventType() == t
}
} | go | func MatchEvent(t EventType) EventMatcher {
return func(e Event) bool {
return e != nil && e.EventType() == t
}
} | [
"func",
"MatchEvent",
"(",
"t",
"EventType",
")",
"EventMatcher",
"{",
"return",
"func",
"(",
"e",
"Event",
")",
"bool",
"{",
"return",
"e",
"!=",
"nil",
"&&",
"e",
".",
"EventType",
"(",
")",
"==",
"t",
"\n",
"}",
"\n",
"}"
] | // MatchEvent matches a specific event type, nil events never match. | [
"MatchEvent",
"matches",
"a",
"specific",
"event",
"type",
"nil",
"events",
"never",
"match",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/matcher.go#L28-L32 | train |
looplab/eventhorizon | matcher.go | MatchAggregate | func MatchAggregate(t AggregateType) EventMatcher {
return func(e Event) bool {
return e != nil && e.AggregateType() == t
}
} | go | func MatchAggregate(t AggregateType) EventMatcher {
return func(e Event) bool {
return e != nil && e.AggregateType() == t
}
} | [
"func",
"MatchAggregate",
"(",
"t",
"AggregateType",
")",
"EventMatcher",
"{",
"return",
"func",
"(",
"e",
"Event",
")",
"bool",
"{",
"return",
"e",
"!=",
"nil",
"&&",
"e",
".",
"AggregateType",
"(",
")",
"==",
"t",
"\n",
"}",
"\n",
"}"
] | // MatchAggregate matches a specific aggregate type, nil events never match. | [
"MatchAggregate",
"matches",
"a",
"specific",
"aggregate",
"type",
"nil",
"events",
"never",
"match",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/matcher.go#L35-L39 | train |
looplab/eventhorizon | matcher.go | MatchAnyOf | func MatchAnyOf(matchers ...EventMatcher) EventMatcher {
return func(e Event) bool {
for _, m := range matchers {
if m(e) {
return true
}
}
return false
}
} | go | func MatchAnyOf(matchers ...EventMatcher) EventMatcher {
return func(e Event) bool {
for _, m := range matchers {
if m(e) {
return true
}
}
return false
}
} | [
"func",
"MatchAnyOf",
"(",
"matchers",
"...",
"EventMatcher",
")",
"EventMatcher",
"{",
"return",
"func",
"(",
"e",
"Event",
")",
"bool",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"matchers",
"{",
"if",
"m",
"(",
"e",
")",
"{",
"return",
"true",
"\n"... | // MatchAnyOf matches if any of several matchers matches. | [
"MatchAnyOf",
"matches",
"if",
"any",
"of",
"several",
"matchers",
"matches",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/matcher.go#L42-L51 | train |
looplab/eventhorizon | matcher.go | MatchAnyEventOf | func MatchAnyEventOf(types ...EventType) EventMatcher {
return func(e Event) bool {
for _, t := range types {
if MatchEvent(t)(e) {
return true
}
}
return false
}
} | go | func MatchAnyEventOf(types ...EventType) EventMatcher {
return func(e Event) bool {
for _, t := range types {
if MatchEvent(t)(e) {
return true
}
}
return false
}
} | [
"func",
"MatchAnyEventOf",
"(",
"types",
"...",
"EventType",
")",
"EventMatcher",
"{",
"return",
"func",
"(",
"e",
"Event",
")",
"bool",
"{",
"for",
"_",
",",
"t",
":=",
"range",
"types",
"{",
"if",
"MatchEvent",
"(",
"t",
")",
"(",
"e",
")",
"{",
... | // MatchAnyEventOf matches if any of several matchers matches. | [
"MatchAnyEventOf",
"matches",
"if",
"any",
"of",
"several",
"matchers",
"matches",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/matcher.go#L54-L63 | train |
looplab/eventhorizon | commandhandler/bus/commandhandler.go | HandleCommand | func (h *CommandHandler) HandleCommand(ctx context.Context, cmd eh.Command) error {
h.handlersMu.RLock()
defer h.handlersMu.RUnlock()
if handler, ok := h.handlers[cmd.CommandType()]; ok {
return handler.HandleCommand(ctx, cmd)
}
return ErrHandlerNotFound
} | go | func (h *CommandHandler) HandleCommand(ctx context.Context, cmd eh.Command) error {
h.handlersMu.RLock()
defer h.handlersMu.RUnlock()
if handler, ok := h.handlers[cmd.CommandType()]; ok {
return handler.HandleCommand(ctx, cmd)
}
return ErrHandlerNotFound
} | [
"func",
"(",
"h",
"*",
"CommandHandler",
")",
"HandleCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"eh",
".",
"Command",
")",
"error",
"{",
"h",
".",
"handlersMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"h",
".",
"handlersMu",
".",
"RU... | // HandleCommand handles a command with a handler capable of handling it. | [
"HandleCommand",
"handles",
"a",
"command",
"with",
"a",
"handler",
"capable",
"of",
"handling",
"it",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/commandhandler/bus/commandhandler.go#L46-L55 | train |
looplab/eventhorizon | commandhandler/bus/commandhandler.go | SetHandler | func (h *CommandHandler) SetHandler(handler eh.CommandHandler, cmdType eh.CommandType) error {
h.handlersMu.Lock()
defer h.handlersMu.Unlock()
if _, ok := h.handlers[cmdType]; ok {
return ErrHandlerAlreadySet
}
h.handlers[cmdType] = handler
return nil
} | go | func (h *CommandHandler) SetHandler(handler eh.CommandHandler, cmdType eh.CommandType) error {
h.handlersMu.Lock()
defer h.handlersMu.Unlock()
if _, ok := h.handlers[cmdType]; ok {
return ErrHandlerAlreadySet
}
h.handlers[cmdType] = handler
return nil
} | [
"func",
"(",
"h",
"*",
"CommandHandler",
")",
"SetHandler",
"(",
"handler",
"eh",
".",
"CommandHandler",
",",
"cmdType",
"eh",
".",
"CommandType",
")",
"error",
"{",
"h",
".",
"handlersMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"handlersMu",
... | // SetHandler adds a handler for a specific command. | [
"SetHandler",
"adds",
"a",
"handler",
"for",
"a",
"specific",
"command",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/commandhandler/bus/commandhandler.go#L58-L68 | train |
looplab/eventhorizon | eventstore/memory/eventstore.go | NewEventStore | func NewEventStore() *EventStore {
s := &EventStore{
db: map[string]map[uuid.UUID]aggregateRecord{},
}
return s
} | go | func NewEventStore() *EventStore {
s := &EventStore{
db: map[string]map[uuid.UUID]aggregateRecord{},
}
return s
} | [
"func",
"NewEventStore",
"(",
")",
"*",
"EventStore",
"{",
"s",
":=",
"&",
"EventStore",
"{",
"db",
":",
"map",
"[",
"string",
"]",
"map",
"[",
"uuid",
".",
"UUID",
"]",
"aggregateRecord",
"{",
"}",
",",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // NewEventStore creates a new EventStore using memory as storage. | [
"NewEventStore",
"creates",
"a",
"new",
"EventStore",
"using",
"memory",
"as",
"storage",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventstore/memory/eventstore.go#L39-L44 | train |
looplab/eventhorizon | eventstore/trace/eventstore.go | StartTracing | func (s *EventStore) StartTracing() {
s.traceMu.Lock()
defer s.traceMu.Unlock()
s.tracing = true
} | go | func (s *EventStore) StartTracing() {
s.traceMu.Lock()
defer s.traceMu.Unlock()
s.tracing = true
} | [
"func",
"(",
"s",
"*",
"EventStore",
")",
"StartTracing",
"(",
")",
"{",
"s",
".",
"traceMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"traceMu",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"tracing",
"=",
"true",
"\n",
"}"
] | // StartTracing starts the tracing of events. | [
"StartTracing",
"starts",
"the",
"tracing",
"of",
"events",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventstore/trace/eventstore.go#L61-L66 | train |
looplab/eventhorizon | eventstore/trace/eventstore.go | StopTracing | func (s *EventStore) StopTracing() {
s.traceMu.Lock()
defer s.traceMu.Unlock()
s.tracing = false
} | go | func (s *EventStore) StopTracing() {
s.traceMu.Lock()
defer s.traceMu.Unlock()
s.tracing = false
} | [
"func",
"(",
"s",
"*",
"EventStore",
")",
"StopTracing",
"(",
")",
"{",
"s",
".",
"traceMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"traceMu",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"tracing",
"=",
"false",
"\n",
"}"
] | // StopTracing stops the tracing of events. | [
"StopTracing",
"stops",
"the",
"tracing",
"of",
"events",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventstore/trace/eventstore.go#L69-L74 | train |
looplab/eventhorizon | eventstore/trace/eventstore.go | GetTrace | func (s *EventStore) GetTrace() []eh.Event {
s.traceMu.RLock()
defer s.traceMu.RUnlock()
return s.trace
} | go | func (s *EventStore) GetTrace() []eh.Event {
s.traceMu.RLock()
defer s.traceMu.RUnlock()
return s.trace
} | [
"func",
"(",
"s",
"*",
"EventStore",
")",
"GetTrace",
"(",
")",
"[",
"]",
"eh",
".",
"Event",
"{",
"s",
".",
"traceMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"traceMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"s",
".",
"trace",
"... | // GetTrace returns the events that happened during the tracing. | [
"GetTrace",
"returns",
"the",
"events",
"that",
"happened",
"during",
"the",
"tracing",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventstore/trace/eventstore.go#L77-L82 | train |
looplab/eventhorizon | eventstore/trace/eventstore.go | ResetTrace | func (s *EventStore) ResetTrace() {
s.traceMu.Lock()
defer s.traceMu.Unlock()
s.trace = make([]eh.Event, 0)
} | go | func (s *EventStore) ResetTrace() {
s.traceMu.Lock()
defer s.traceMu.Unlock()
s.trace = make([]eh.Event, 0)
} | [
"func",
"(",
"s",
"*",
"EventStore",
")",
"ResetTrace",
"(",
")",
"{",
"s",
".",
"traceMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"traceMu",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"trace",
"=",
"make",
"(",
"[",
"]",
"eh",
".",
... | // ResetTrace resets the trace. | [
"ResetTrace",
"resets",
"the",
"trace",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventstore/trace/eventstore.go#L85-L90 | train |
looplab/eventhorizon | examples/guestlist/domain/aggregate.go | NewInvitationAggregate | func NewInvitationAggregate(id uuid.UUID) *InvitationAggregate {
return &InvitationAggregate{
AggregateBase: events.NewAggregateBase(InvitationAggregateType, id),
}
} | go | func NewInvitationAggregate(id uuid.UUID) *InvitationAggregate {
return &InvitationAggregate{
AggregateBase: events.NewAggregateBase(InvitationAggregateType, id),
}
} | [
"func",
"NewInvitationAggregate",
"(",
"id",
"uuid",
".",
"UUID",
")",
"*",
"InvitationAggregate",
"{",
"return",
"&",
"InvitationAggregate",
"{",
"AggregateBase",
":",
"events",
".",
"NewAggregateBase",
"(",
"InvitationAggregateType",
",",
"id",
")",
",",
"}",
... | // NewInvitationAggregate creates a new InvitationAggregate with an ID. | [
"NewInvitationAggregate",
"creates",
"a",
"new",
"InvitationAggregate",
"with",
"an",
"ID",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/aggregate.go#L58-L62 | train |
looplab/eventhorizon | examples/guestlist/domain/aggregate.go | HandleCommand | func (a *InvitationAggregate) HandleCommand(ctx context.Context, cmd eh.Command) error {
switch cmd := cmd.(type) {
case *CreateInvite:
a.StoreEvent(InviteCreatedEvent,
&InviteCreatedData{
cmd.Name,
cmd.Age,
},
time.Now(),
)
return nil
case *AcceptInvite:
if a.name == "" {
return fmt.Err... | go | func (a *InvitationAggregate) HandleCommand(ctx context.Context, cmd eh.Command) error {
switch cmd := cmd.(type) {
case *CreateInvite:
a.StoreEvent(InviteCreatedEvent,
&InviteCreatedData{
cmd.Name,
cmd.Age,
},
time.Now(),
)
return nil
case *AcceptInvite:
if a.name == "" {
return fmt.Err... | [
"func",
"(",
"a",
"*",
"InvitationAggregate",
")",
"HandleCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"eh",
".",
"Command",
")",
"error",
"{",
"switch",
"cmd",
":=",
"cmd",
".",
"(",
"type",
")",
"{",
"case",
"*",
"CreateInvite",
":",
... | // HandleCommand implements the HandleCommand method of the Aggregate interface. | [
"HandleCommand",
"implements",
"the",
"HandleCommand",
"method",
"of",
"the",
"Aggregate",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/aggregate.go#L65-L134 | train |
looplab/eventhorizon | examples/guestlist/domain/aggregate.go | ApplyEvent | func (a *InvitationAggregate) ApplyEvent(ctx context.Context, event eh.Event) error {
switch event.EventType() {
case InviteCreatedEvent:
if data, ok := event.Data().(*InviteCreatedData); ok {
a.name = data.Name
a.age = data.Age
} else {
log.Println("invalid event data type:", event.Data())
}
case Inv... | go | func (a *InvitationAggregate) ApplyEvent(ctx context.Context, event eh.Event) error {
switch event.EventType() {
case InviteCreatedEvent:
if data, ok := event.Data().(*InviteCreatedData); ok {
a.name = data.Name
a.age = data.Age
} else {
log.Println("invalid event data type:", event.Data())
}
case Inv... | [
"func",
"(",
"a",
"*",
"InvitationAggregate",
")",
"ApplyEvent",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"eh",
".",
"Event",
")",
"error",
"{",
"switch",
"event",
".",
"EventType",
"(",
")",
"{",
"case",
"InviteCreatedEvent",
":",
"if",
"dat... | // ApplyEvent implements the ApplyEvent method of the Aggregate interface. | [
"ApplyEvent",
"implements",
"the",
"ApplyEvent",
"method",
"of",
"the",
"Aggregate",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/aggregate.go#L137-L156 | train |
looplab/eventhorizon | aggregate.go | CreateAggregate | func CreateAggregate(aggregateType AggregateType, id uuid.UUID) (Aggregate, error) {
aggregatesMu.RLock()
defer aggregatesMu.RUnlock()
if factory, ok := aggregates[aggregateType]; ok {
return factory(id), nil
}
return nil, ErrAggregateNotRegistered
} | go | func CreateAggregate(aggregateType AggregateType, id uuid.UUID) (Aggregate, error) {
aggregatesMu.RLock()
defer aggregatesMu.RUnlock()
if factory, ok := aggregates[aggregateType]; ok {
return factory(id), nil
}
return nil, ErrAggregateNotRegistered
} | [
"func",
"CreateAggregate",
"(",
"aggregateType",
"AggregateType",
",",
"id",
"uuid",
".",
"UUID",
")",
"(",
"Aggregate",
",",
"error",
")",
"{",
"aggregatesMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"aggregatesMu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
... | // CreateAggregate creates an aggregate of a type with an ID using the factory
// registered with RegisterAggregate. | [
"CreateAggregate",
"creates",
"an",
"aggregate",
"of",
"a",
"type",
"with",
"an",
"ID",
"using",
"the",
"factory",
"registered",
"with",
"RegisterAggregate",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/aggregate.go#L94-L101 | train |
optiopay/klar | main.go | filterWhitelist | func filterWhitelist(whitelist *vulnerabilitiesWhitelist, vs []*clair.Vulnerability, imageName string) []*clair.Vulnerability {
generalWhitelist := whitelist.General
imageWhitelist := whitelist.Images
filteredVs := make([]*clair.Vulnerability, 0, len(vs))
for _, v := range vs {
if _, exists := generalWhitelist[... | go | func filterWhitelist(whitelist *vulnerabilitiesWhitelist, vs []*clair.Vulnerability, imageName string) []*clair.Vulnerability {
generalWhitelist := whitelist.General
imageWhitelist := whitelist.Images
filteredVs := make([]*clair.Vulnerability, 0, len(vs))
for _, v := range vs {
if _, exists := generalWhitelist[... | [
"func",
"filterWhitelist",
"(",
"whitelist",
"*",
"vulnerabilitiesWhitelist",
",",
"vs",
"[",
"]",
"*",
"clair",
".",
"Vulnerability",
",",
"imageName",
"string",
")",
"[",
"]",
"*",
"clair",
".",
"Vulnerability",
"{",
"generalWhitelist",
":=",
"whitelist",
".... | //Filter out whitelisted vulnerabilites | [
"Filter",
"out",
"whitelisted",
"vulnerabilites"
] | 99ad65f257636385fed0c6ef0997dc020687ee71 | https://github.com/optiopay/klar/blob/99ad65f257636385fed0c6ef0997dc020687ee71/main.go#L133-L149 | train |
optiopay/klar | docker/docker.go | Pull | func (i *Image) Pull() error {
resp, err := i.pullReq()
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusUnauthorized {
i.Token, err = i.requestToken(resp)
io.Copy(ioutil.Discard, resp.Body)
if err != nil {
return err
}
// try again
resp, err = i.pullReq()
if... | go | func (i *Image) Pull() error {
resp, err := i.pullReq()
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusUnauthorized {
i.Token, err = i.requestToken(resp)
io.Copy(ioutil.Discard, resp.Body)
if err != nil {
return err
}
// try again
resp, err = i.pullReq()
if... | [
"func",
"(",
"i",
"*",
"Image",
")",
"Pull",
"(",
")",
"error",
"{",
"resp",
",",
"err",
":=",
"i",
".",
"pullReq",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"... | // Pull retrieves information about layers from docker registry.
// It gets docker registry token if needed. | [
"Pull",
"retrieves",
"information",
"about",
"layers",
"from",
"docker",
"registry",
".",
"It",
"gets",
"docker",
"registry",
"token",
"if",
"needed",
"."
] | 99ad65f257636385fed0c6ef0997dc020687ee71 | https://github.com/optiopay/klar/blob/99ad65f257636385fed0c6ef0997dc020687ee71/docker/docker.go#L235-L267 | train |
optiopay/klar | klar.go | parseWhitelistFile | func parseWhitelistFile(whitelistFile string) (*vulnerabilitiesWhitelist, error) {
whitelistYAML := vulnerabilitiesWhitelistYAML{}
whitelist := vulnerabilitiesWhitelist{}
//read the whitelist file
whitelistBytes, err := ioutil.ReadFile(whitelistFile)
if err != nil {
return nil, fmt.Errorf("could not read file %... | go | func parseWhitelistFile(whitelistFile string) (*vulnerabilitiesWhitelist, error) {
whitelistYAML := vulnerabilitiesWhitelistYAML{}
whitelist := vulnerabilitiesWhitelist{}
//read the whitelist file
whitelistBytes, err := ioutil.ReadFile(whitelistFile)
if err != nil {
return nil, fmt.Errorf("could not read file %... | [
"func",
"parseWhitelistFile",
"(",
"whitelistFile",
"string",
")",
"(",
"*",
"vulnerabilitiesWhitelist",
",",
"error",
")",
"{",
"whitelistYAML",
":=",
"vulnerabilitiesWhitelistYAML",
"{",
"}",
"\n",
"whitelist",
":=",
"vulnerabilitiesWhitelist",
"{",
"}",
"\n\n",
"... | //Parse the whitelist file | [
"Parse",
"the",
"whitelist",
"file"
] | 99ad65f257636385fed0c6ef0997dc020687ee71 | https://github.com/optiopay/klar/blob/99ad65f257636385fed0c6ef0997dc020687ee71/klar.go#L187-L217 | train |
optiopay/klar | clair/clair.go | NewClair | func NewClair(url string, version int, timeout time.Duration) Clair {
api, err := newAPI(url, version, timeout)
if err != nil {
panic(fmt.Sprintf("cant't create API client version %d %s: %s", version, url, err))
}
return Clair{url, api}
} | go | func NewClair(url string, version int, timeout time.Duration) Clair {
api, err := newAPI(url, version, timeout)
if err != nil {
panic(fmt.Sprintf("cant't create API client version %d %s: %s", version, url, err))
}
return Clair{url, api}
} | [
"func",
"NewClair",
"(",
"url",
"string",
",",
"version",
"int",
",",
"timeout",
"time",
".",
"Duration",
")",
"Clair",
"{",
"api",
",",
"err",
":=",
"newAPI",
"(",
"url",
",",
"version",
",",
"timeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p... | // NewClair construct Clair entity using potentially incomplete server URL
// If protocol is missing HTTP will be used. If port is missing 6060 will be used | [
"NewClair",
"construct",
"Clair",
"entity",
"using",
"potentially",
"incomplete",
"server",
"URL",
"If",
"protocol",
"is",
"missing",
"HTTP",
"will",
"be",
"used",
".",
"If",
"port",
"is",
"missing",
"6060",
"will",
"be",
"used"
] | 99ad65f257636385fed0c6ef0997dc020687ee71 | https://github.com/optiopay/klar/blob/99ad65f257636385fed0c6ef0997dc020687ee71/clair/clair.go#L75-L82 | train |
optiopay/klar | clair/clair.go | Analyse | func (c *Clair) Analyse(image *docker.Image) ([]*Vulnerability, error) {
// Filter the empty layers in image
image.FsLayers = filterEmptyLayers(image.FsLayers)
layerLength := len(image.FsLayers)
if layerLength == 0 {
fmt.Fprintf(os.Stderr, "no need to analyse image %s/%s:%s as there is no non-emtpy layer\n",
i... | go | func (c *Clair) Analyse(image *docker.Image) ([]*Vulnerability, error) {
// Filter the empty layers in image
image.FsLayers = filterEmptyLayers(image.FsLayers)
layerLength := len(image.FsLayers)
if layerLength == 0 {
fmt.Fprintf(os.Stderr, "no need to analyse image %s/%s:%s as there is no non-emtpy layer\n",
i... | [
"func",
"(",
"c",
"*",
"Clair",
")",
"Analyse",
"(",
"image",
"*",
"docker",
".",
"Image",
")",
"(",
"[",
"]",
"*",
"Vulnerability",
",",
"error",
")",
"{",
"// Filter the empty layers in image",
"image",
".",
"FsLayers",
"=",
"filterEmptyLayers",
"(",
"im... | // Analyse sent each layer from Docker image to Clair and returns
// a list of found vulnerabilities | [
"Analyse",
"sent",
"each",
"layer",
"from",
"Docker",
"image",
"to",
"Clair",
"and",
"returns",
"a",
"list",
"of",
"found",
"vulnerabilities"
] | 99ad65f257636385fed0c6ef0997dc020687ee71 | https://github.com/optiopay/klar/blob/99ad65f257636385fed0c6ef0997dc020687ee71/clair/clair.go#L110-L129 | train |
StackExchange/wmi | wmi.go | QueryNamespace | func QueryNamespace(query string, dst interface{}, namespace string) error {
return Query(query, dst, nil, namespace)
} | go | func QueryNamespace(query string, dst interface{}, namespace string) error {
return Query(query, dst, nil, namespace)
} | [
"func",
"QueryNamespace",
"(",
"query",
"string",
",",
"dst",
"interface",
"{",
"}",
",",
"namespace",
"string",
")",
"error",
"{",
"return",
"Query",
"(",
"query",
",",
"dst",
",",
"nil",
",",
"namespace",
")",
"\n",
"}"
] | // QueryNamespace invokes Query with the given namespace on the local machine. | [
"QueryNamespace",
"invokes",
"Query",
"with",
"the",
"given",
"namespace",
"on",
"the",
"local",
"machine",
"."
] | e0a55b97c70558c92ce14085e41b35a894e93d3d | https://github.com/StackExchange/wmi/blob/e0a55b97c70558c92ce14085e41b35a894e93d3d/wmi.go#L58-L60 | train |
StackExchange/wmi | wmi.go | CreateQuery | func CreateQuery(src interface{}, where string) string {
var b bytes.Buffer
b.WriteString("SELECT ")
s := reflect.Indirect(reflect.ValueOf(src))
t := s.Type()
if s.Kind() == reflect.Slice {
t = t.Elem()
}
if t.Kind() != reflect.Struct {
return ""
}
var fields []string
for i := 0; i < t.NumField(); i++ {
... | go | func CreateQuery(src interface{}, where string) string {
var b bytes.Buffer
b.WriteString("SELECT ")
s := reflect.Indirect(reflect.ValueOf(src))
t := s.Type()
if s.Kind() == reflect.Slice {
t = t.Elem()
}
if t.Kind() != reflect.Struct {
return ""
}
var fields []string
for i := 0; i < t.NumField(); i++ {
... | [
"func",
"CreateQuery",
"(",
"src",
"interface",
"{",
"}",
",",
"where",
"string",
")",
"string",
"{",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"b",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"s",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect"... | // CreateQuery returns a WQL query string that queries all columns of src. where
// is an optional string that is appended to the query, to be used with WHERE
// clauses. In such a case, the "WHERE" string should appear at the beginning. | [
"CreateQuery",
"returns",
"a",
"WQL",
"query",
"string",
"that",
"queries",
"all",
"columns",
"of",
"src",
".",
"where",
"is",
"an",
"optional",
"string",
"that",
"is",
"appended",
"to",
"the",
"query",
"to",
"be",
"used",
"with",
"WHERE",
"clauses",
".",
... | e0a55b97c70558c92ce14085e41b35a894e93d3d | https://github.com/StackExchange/wmi/blob/e0a55b97c70558c92ce14085e41b35a894e93d3d/wmi.go#L470-L490 | train |
StackExchange/wmi | swbemservices.go | InitializeSWbemServices | func InitializeSWbemServices(c *Client, connectServerArgs ...interface{}) (*SWbemServices, error) {
//fmt.Println("InitializeSWbemServices: Starting")
//TODO: implement connectServerArgs as optional argument for init with connectServer call
s := new(SWbemServices)
s.cWMIClient = c
s.queries = make(chan *queryReque... | go | func InitializeSWbemServices(c *Client, connectServerArgs ...interface{}) (*SWbemServices, error) {
//fmt.Println("InitializeSWbemServices: Starting")
//TODO: implement connectServerArgs as optional argument for init with connectServer call
s := new(SWbemServices)
s.cWMIClient = c
s.queries = make(chan *queryReque... | [
"func",
"InitializeSWbemServices",
"(",
"c",
"*",
"Client",
",",
"connectServerArgs",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"SWbemServices",
",",
"error",
")",
"{",
"//fmt.Println(\"InitializeSWbemServices: Starting\")",
"//TODO: implement connectServerArgs as option... | // InitializeSWbemServices will return a new SWbemServices object that can be used to query WMI | [
"InitializeSWbemServices",
"will",
"return",
"a",
"new",
"SWbemServices",
"object",
"that",
"can",
"be",
"used",
"to",
"query",
"WMI"
] | e0a55b97c70558c92ce14085e41b35a894e93d3d | https://github.com/StackExchange/wmi/blob/e0a55b97c70558c92ce14085e41b35a894e93d3d/swbemservices.go#L34-L49 | train |
StackExchange/wmi | swbemservices.go | Close | func (s *SWbemServices) Close() error {
s.lQueryorClose.Lock()
if s == nil || s.sWbemLocatorIDispatch == nil {
s.lQueryorClose.Unlock()
return fmt.Errorf("SWbemServices is not Initialized")
}
if s.queries == nil {
s.lQueryorClose.Unlock()
return fmt.Errorf("SWbemServices has been closed")
}
//fmt.Println(... | go | func (s *SWbemServices) Close() error {
s.lQueryorClose.Lock()
if s == nil || s.sWbemLocatorIDispatch == nil {
s.lQueryorClose.Unlock()
return fmt.Errorf("SWbemServices is not Initialized")
}
if s.queries == nil {
s.lQueryorClose.Unlock()
return fmt.Errorf("SWbemServices has been closed")
}
//fmt.Println(... | [
"func",
"(",
"s",
"*",
"SWbemServices",
")",
"Close",
"(",
")",
"error",
"{",
"s",
".",
"lQueryorClose",
".",
"Lock",
"(",
")",
"\n",
"if",
"s",
"==",
"nil",
"||",
"s",
".",
"sWbemLocatorIDispatch",
"==",
"nil",
"{",
"s",
".",
"lQueryorClose",
".",
... | // Close will clear and release all of the SWbemServices resources | [
"Close",
"will",
"clear",
"and",
"release",
"all",
"of",
"the",
"SWbemServices",
"resources"
] | e0a55b97c70558c92ce14085e41b35a894e93d3d | https://github.com/StackExchange/wmi/blob/e0a55b97c70558c92ce14085e41b35a894e93d3d/swbemservices.go#L52-L74 | train |
coreos/ignition | internal/systemd/systemd.go | WaitOnDevices | func WaitOnDevices(devs []string, stage string) error {
conn, err := dbus.NewSystemdConnection()
if err != nil {
return err
}
results := map[string]chan string{}
for _, dev := range devs {
unitName := unit.UnitNamePathEscape(dev + ".device")
results[unitName] = make(chan string, 1)
if _, err = conn.Start... | go | func WaitOnDevices(devs []string, stage string) error {
conn, err := dbus.NewSystemdConnection()
if err != nil {
return err
}
results := map[string]chan string{}
for _, dev := range devs {
unitName := unit.UnitNamePathEscape(dev + ".device")
results[unitName] = make(chan string, 1)
if _, err = conn.Start... | [
"func",
"WaitOnDevices",
"(",
"devs",
"[",
"]",
"string",
",",
"stage",
"string",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"dbus",
".",
"NewSystemdConnection",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"re... | // WaitOnDevices waits for the devices named in devs to be plugged before returning. | [
"WaitOnDevices",
"waits",
"for",
"the",
"devices",
"named",
"in",
"devs",
"to",
"be",
"plugged",
"before",
"returning",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/systemd/systemd.go#L25-L50 | train |
coreos/ignition | config/config.go | Parse | func Parse(raw []byte) (types_exp.Config, report.Report, error) {
if len(raw) == 0 {
return types_exp.Config{}, report.Report{}, errors.ErrEmpty
}
stub := versionStub{}
rpt, err := util.HandleParseErrors(raw, &stub)
if err != nil {
return types_exp.Config{}, rpt, err
}
version, err := semver.NewVersion(stu... | go | func Parse(raw []byte) (types_exp.Config, report.Report, error) {
if len(raw) == 0 {
return types_exp.Config{}, report.Report{}, errors.ErrEmpty
}
stub := versionStub{}
rpt, err := util.HandleParseErrors(raw, &stub)
if err != nil {
return types_exp.Config{}, rpt, err
}
version, err := semver.NewVersion(stu... | [
"func",
"Parse",
"(",
"raw",
"[",
"]",
"byte",
")",
"(",
"types_exp",
".",
"Config",
",",
"report",
".",
"Report",
",",
"error",
")",
"{",
"if",
"len",
"(",
"raw",
")",
"==",
"0",
"{",
"return",
"types_exp",
".",
"Config",
"{",
"}",
",",
"report"... | // Parse parses a config of any supported version and returns the equivalent config at the latest
// supported version. | [
"Parse",
"parses",
"a",
"config",
"of",
"any",
"supported",
"version",
"and",
"returns",
"the",
"equivalent",
"config",
"at",
"the",
"latest",
"supported",
"version",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/config.go#L38-L62 | train |
coreos/ignition | internal/resource/url.go | FetchToBuffer | func (f *Fetcher) FetchToBuffer(u url.URL, opts FetchOptions) ([]byte, error) {
file, err := ioutil.TempFile("", "ignition")
if err != nil {
return nil, err
}
defer os.Remove(file.Name())
defer file.Close()
err = f.Fetch(u, file, opts)
if err != nil {
return nil, err
}
_, err = file.Seek(0, os.SEEK_SET)
i... | go | func (f *Fetcher) FetchToBuffer(u url.URL, opts FetchOptions) ([]byte, error) {
file, err := ioutil.TempFile("", "ignition")
if err != nil {
return nil, err
}
defer os.Remove(file.Name())
defer file.Close()
err = f.Fetch(u, file, opts)
if err != nil {
return nil, err
}
_, err = file.Seek(0, os.SEEK_SET)
i... | [
"func",
"(",
"f",
"*",
"Fetcher",
")",
"FetchToBuffer",
"(",
"u",
"url",
".",
"URL",
",",
"opts",
"FetchOptions",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"",
"\"",
",",
"\"",... | // FetchToBuffer will fetch the given url into a temporrary file, and then read
// in the contents of the file and delete it. It will return the downloaded
// contents, or an error if one was encountered. | [
"FetchToBuffer",
"will",
"fetch",
"the",
"given",
"url",
"into",
"a",
"temporrary",
"file",
"and",
"then",
"read",
"in",
"the",
"contents",
"of",
"the",
"file",
"and",
"delete",
"it",
".",
"It",
"will",
"return",
"the",
"downloaded",
"contents",
"or",
"an"... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/url.go#L102-L122 | train |
coreos/ignition | internal/resource/url.go | FetchFromTFTP | func (f *Fetcher) FetchFromTFTP(u url.URL, dest *os.File, opts FetchOptions) error {
if !strings.ContainsRune(u.Host, ':') {
u.Host = u.Host + ":69"
}
c, err := tftp.NewClient(u.Host)
if err != nil {
return err
}
wt, err := c.Receive(u.Path, "octet")
if err != nil {
return err
}
// The TFTP library takes... | go | func (f *Fetcher) FetchFromTFTP(u url.URL, dest *os.File, opts FetchOptions) error {
if !strings.ContainsRune(u.Host, ':') {
u.Host = u.Host + ":69"
}
c, err := tftp.NewClient(u.Host)
if err != nil {
return err
}
wt, err := c.Receive(u.Path, "octet")
if err != nil {
return err
}
// The TFTP library takes... | [
"func",
"(",
"f",
"*",
"Fetcher",
")",
"FetchFromTFTP",
"(",
"u",
"url",
".",
"URL",
",",
"dest",
"*",
"os",
".",
"File",
",",
"opts",
"FetchOptions",
")",
"error",
"{",
"if",
"!",
"strings",
".",
"ContainsRune",
"(",
"u",
".",
"Host",
",",
"':'",
... | // FetchFromTFTP fetches a resource from u via TFTP into dest, returning an
// error if one is encountered. | [
"FetchFromTFTP",
"fetches",
"a",
"resource",
"from",
"u",
"via",
"TFTP",
"into",
"dest",
"returning",
"an",
"error",
"if",
"one",
"is",
"encountered",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/url.go#L153-L211 | train |
coreos/ignition | internal/resource/url.go | FetchFromDataURL | func (f *Fetcher) FetchFromDataURL(u url.URL, dest *os.File, opts FetchOptions) error {
if opts.Compression != "" {
return ErrCompressionUnsupported
}
url, err := dataurl.DecodeString(u.String())
if err != nil {
return err
}
return f.decompressCopyHashAndVerify(dest, bytes.NewBuffer(url.Data), opts)
} | go | func (f *Fetcher) FetchFromDataURL(u url.URL, dest *os.File, opts FetchOptions) error {
if opts.Compression != "" {
return ErrCompressionUnsupported
}
url, err := dataurl.DecodeString(u.String())
if err != nil {
return err
}
return f.decompressCopyHashAndVerify(dest, bytes.NewBuffer(url.Data), opts)
} | [
"func",
"(",
"f",
"*",
"Fetcher",
")",
"FetchFromDataURL",
"(",
"u",
"url",
".",
"URL",
",",
"dest",
"*",
"os",
".",
"File",
",",
"opts",
"FetchOptions",
")",
"error",
"{",
"if",
"opts",
".",
"Compression",
"!=",
"\"",
"\"",
"{",
"return",
"ErrCompre... | // FetchFromDataURL writes the data stored in the dataurl u into dest, returning
// an error if one is encountered. | [
"FetchFromDataURL",
"writes",
"the",
"data",
"stored",
"in",
"the",
"dataurl",
"u",
"into",
"dest",
"returning",
"an",
"error",
"if",
"one",
"is",
"encountered",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/url.go#L251-L261 | train |
coreos/ignition | internal/resource/url.go | FetchFromS3 | func (f *Fetcher) FetchFromS3(u url.URL, dest *os.File, opts FetchOptions) error {
if opts.Compression != "" {
return ErrCompressionUnsupported
}
ctx := context.Background()
if f.client != nil && f.client.timeout != 0 {
var cancelFn context.CancelFunc
ctx, cancelFn = context.WithTimeout(ctx, f.client.timeout)... | go | func (f *Fetcher) FetchFromS3(u url.URL, dest *os.File, opts FetchOptions) error {
if opts.Compression != "" {
return ErrCompressionUnsupported
}
ctx := context.Background()
if f.client != nil && f.client.timeout != 0 {
var cancelFn context.CancelFunc
ctx, cancelFn = context.WithTimeout(ctx, f.client.timeout)... | [
"func",
"(",
"f",
"*",
"Fetcher",
")",
"FetchFromS3",
"(",
"u",
"url",
".",
"URL",
",",
"dest",
"*",
"os",
".",
"File",
",",
"opts",
"FetchOptions",
")",
"error",
"{",
"if",
"opts",
".",
"Compression",
"!=",
"\"",
"\"",
"{",
"return",
"ErrCompression... | // FetchFromS3 gets data from an S3 bucket as described by u and writes it into
// dest, returning an error if one is encountered. It will attempt to acquire
// IAM credentials from the EC2 metadata service, and if this fails will attempt
// to fetch the object with anonymous credentials. | [
"FetchFromS3",
"gets",
"data",
"from",
"an",
"S3",
"bucket",
"as",
"described",
"by",
"u",
"and",
"writes",
"it",
"into",
"dest",
"returning",
"an",
"error",
"if",
"one",
"is",
"encountered",
".",
"It",
"will",
"attempt",
"to",
"acquire",
"IAM",
"credentia... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/url.go#L267-L338 | train |
coreos/ignition | internal/resource/url.go | uncompress | func (f *Fetcher) uncompress(r io.Reader, opts FetchOptions) (io.ReadCloser, error) {
switch opts.Compression {
case "":
return ioutil.NopCloser(r), nil
case "gzip":
return gzip.NewReader(r)
default:
return nil, configErrors.ErrCompressionInvalid
}
} | go | func (f *Fetcher) uncompress(r io.Reader, opts FetchOptions) (io.ReadCloser, error) {
switch opts.Compression {
case "":
return ioutil.NopCloser(r), nil
case "gzip":
return gzip.NewReader(r)
default:
return nil, configErrors.ErrCompressionInvalid
}
} | [
"func",
"(",
"f",
"*",
"Fetcher",
")",
"uncompress",
"(",
"r",
"io",
".",
"Reader",
",",
"opts",
"FetchOptions",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"switch",
"opts",
".",
"Compression",
"{",
"case",
"\"",
"\"",
":",
"return",
... | // uncompress will wrap the given io.Reader in a decompresser specified in the
// FetchOptions, and return an io.ReadCloser with the decompressed data stream. | [
"uncompress",
"will",
"wrap",
"the",
"given",
"io",
".",
"Reader",
"in",
"a",
"decompresser",
"specified",
"in",
"the",
"FetchOptions",
"and",
"return",
"an",
"io",
".",
"ReadCloser",
"with",
"the",
"decompressed",
"data",
"stream",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/url.go#L363-L372 | train |
coreos/ignition | internal/resource/url.go | decompressCopyHashAndVerify | func (f *Fetcher) decompressCopyHashAndVerify(dest io.Writer, src io.Reader, opts FetchOptions) error {
decompressor, err := f.uncompress(src, opts)
if err != nil {
return err
}
defer decompressor.Close()
if opts.Hash != nil {
opts.Hash.Reset()
dest = io.MultiWriter(dest, opts.Hash)
}
_, err = io.Copy(dest... | go | func (f *Fetcher) decompressCopyHashAndVerify(dest io.Writer, src io.Reader, opts FetchOptions) error {
decompressor, err := f.uncompress(src, opts)
if err != nil {
return err
}
defer decompressor.Close()
if opts.Hash != nil {
opts.Hash.Reset()
dest = io.MultiWriter(dest, opts.Hash)
}
_, err = io.Copy(dest... | [
"func",
"(",
"f",
"*",
"Fetcher",
")",
"decompressCopyHashAndVerify",
"(",
"dest",
"io",
".",
"Writer",
",",
"src",
"io",
".",
"Reader",
",",
"opts",
"FetchOptions",
")",
"error",
"{",
"decompressor",
",",
"err",
":=",
"f",
".",
"uncompress",
"(",
"src",... | // decompressCopyHashAndVerify will decompress src if necessary, copy src into
// dest until src returns an io.EOF while also calculating a hash if one is set,
// and will return an error if there's any problems with any of this or if the
// hash doesn't match the expected hash in the opts. | [
"decompressCopyHashAndVerify",
"will",
"decompress",
"src",
"if",
"necessary",
"copy",
"src",
"into",
"dest",
"until",
"src",
"returns",
"an",
"io",
".",
"EOF",
"while",
"also",
"calculating",
"a",
"hash",
"if",
"one",
"is",
"set",
"and",
"will",
"return",
"... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/url.go#L378-L403 | train |
coreos/ignition | internal/resource/http.go | RewriteCAsWithDataUrls | func (f *Fetcher) RewriteCAsWithDataUrls(cas []types.CaReference) error {
for i, ca := range cas {
blob, err := f.getCABlob(ca)
if err != nil {
return err
}
cas[i].Source = dataurl.EncodeBytes(blob)
}
return nil
} | go | func (f *Fetcher) RewriteCAsWithDataUrls(cas []types.CaReference) error {
for i, ca := range cas {
blob, err := f.getCABlob(ca)
if err != nil {
return err
}
cas[i].Source = dataurl.EncodeBytes(blob)
}
return nil
} | [
"func",
"(",
"f",
"*",
"Fetcher",
")",
"RewriteCAsWithDataUrls",
"(",
"cas",
"[",
"]",
"types",
".",
"CaReference",
")",
"error",
"{",
"for",
"i",
",",
"ca",
":=",
"range",
"cas",
"{",
"blob",
",",
"err",
":=",
"f",
".",
"getCABlob",
"(",
"ca",
")"... | // RewriteCAsWithDataUrls will modify the passed in slice of CA references to
// contain the actual CA file via a dataurl in their source field. | [
"RewriteCAsWithDataUrls",
"will",
"modify",
"the",
"passed",
"in",
"slice",
"of",
"CA",
"references",
"to",
"contain",
"the",
"actual",
"CA",
"file",
"via",
"a",
"dataurl",
"in",
"their",
"source",
"field",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/http.go#L174-L184 | train |
coreos/ignition | internal/resource/http.go | defaultHTTPClient | func defaultHTTPClient() (*http.Client, error) {
urand, err := earlyrand.UrandomReader()
if err != nil {
return nil, err
}
tlsConfig := tls.Config{
Rand: urand,
}
transport := http.Transport{
ResponseHeaderTimeout: time.Duration(defaultHttpResponseHeaderTimeout) * time.Second,
Dial: (&net.Dialer{
Time... | go | func defaultHTTPClient() (*http.Client, error) {
urand, err := earlyrand.UrandomReader()
if err != nil {
return nil, err
}
tlsConfig := tls.Config{
Rand: urand,
}
transport := http.Transport{
ResponseHeaderTimeout: time.Duration(defaultHttpResponseHeaderTimeout) * time.Second,
Dial: (&net.Dialer{
Time... | [
"func",
"defaultHTTPClient",
"(",
")",
"(",
"*",
"http",
".",
"Client",
",",
"error",
")",
"{",
"urand",
",",
"err",
":=",
"earlyrand",
".",
"UrandomReader",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n... | // DefaultHTTPClient builds the default `http.client` for Ignition. | [
"DefaultHTTPClient",
"builds",
"the",
"default",
"http",
".",
"client",
"for",
"Ignition",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/http.go#L187-L212 | train |
coreos/ignition | internal/resource/http.go | newHttpClient | func (f *Fetcher) newHttpClient() error {
defaultClient, err := defaultHTTPClient()
if err != nil {
return err
}
f.client = &HttpClient{
client: defaultClient,
logger: f.Logger,
timeout: time.Duration(defaultHttpTotalTimeout) * time.Second,
transport: defaultClient.Transport.(*http.Transport),
... | go | func (f *Fetcher) newHttpClient() error {
defaultClient, err := defaultHTTPClient()
if err != nil {
return err
}
f.client = &HttpClient{
client: defaultClient,
logger: f.Logger,
timeout: time.Duration(defaultHttpTotalTimeout) * time.Second,
transport: defaultClient.Transport.(*http.Transport),
... | [
"func",
"(",
"f",
"*",
"Fetcher",
")",
"newHttpClient",
"(",
")",
"error",
"{",
"defaultClient",
",",
"err",
":=",
"defaultHTTPClient",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"f",
".",
"client",
"=",
"&",
... | // newHttpClient populates the fetcher with the default HTTP client. | [
"newHttpClient",
"populates",
"the",
"fetcher",
"with",
"the",
"default",
"HTTP",
"client",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/resource/http.go#L215-L229 | train |
coreos/ignition | internal/registry/registry.go | Create | func Create(name string) *Registry {
return &Registry{name: name, registrants: map[string]Registrant{}}
} | go | func Create(name string) *Registry {
return &Registry{name: name, registrants: map[string]Registrant{}}
} | [
"func",
"Create",
"(",
"name",
"string",
")",
"*",
"Registry",
"{",
"return",
"&",
"Registry",
"{",
"name",
":",
"name",
",",
"registrants",
":",
"map",
"[",
"string",
"]",
"Registrant",
"{",
"}",
"}",
"\n",
"}"
] | // Create creates a new registry | [
"Create",
"creates",
"a",
"new",
"registry"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/registry/registry.go#L33-L35 | train |
coreos/ignition | internal/registry/registry.go | Register | func (r *Registry) Register(registrant Registrant) {
if _, ok := r.registrants[registrant.Name()]; ok {
panic(fmt.Sprintf("%s: registrant %q already registered", r.name, registrant.Name()))
}
r.registrants[registrant.Name()] = registrant
} | go | func (r *Registry) Register(registrant Registrant) {
if _, ok := r.registrants[registrant.Name()]; ok {
panic(fmt.Sprintf("%s: registrant %q already registered", r.name, registrant.Name()))
}
r.registrants[registrant.Name()] = registrant
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"Register",
"(",
"registrant",
"Registrant",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"r",
".",
"registrants",
"[",
"registrant",
".",
"Name",
"(",
")",
"]",
";",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
... | // Register registers a new registrant to a registry | [
"Register",
"registers",
"a",
"new",
"registrant",
"to",
"a",
"registry"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/registry/registry.go#L38-L43 | train |
coreos/ignition | internal/registry/registry.go | Names | func (r *Registry) Names() []string {
keys := []string{}
for key := range r.registrants {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
} | go | func (r *Registry) Names() []string {
keys := []string{}
for key := range r.registrants {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"Names",
"(",
")",
"[",
"]",
"string",
"{",
"keys",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"key",
":=",
"range",
"r",
".",
"registrants",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"key",
")"... | // Names returns the sorted registrant names | [
"Names",
"returns",
"the",
"sorted",
"registrant",
"names"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/registry/registry.go#L51-L58 | train |
coreos/ignition | internal/sgdisk/sgdisk.go | Begin | func Begin(logger *log.Logger, dev string) *Operation {
return &Operation{logger: logger, dev: dev}
} | go | func Begin(logger *log.Logger, dev string) *Operation {
return &Operation{logger: logger, dev: dev}
} | [
"func",
"Begin",
"(",
"logger",
"*",
"log",
".",
"Logger",
",",
"dev",
"string",
")",
"*",
"Operation",
"{",
"return",
"&",
"Operation",
"{",
"logger",
":",
"logger",
",",
"dev",
":",
"dev",
"}",
"\n",
"}"
] | // Begin begins an sgdisk operation | [
"Begin",
"begins",
"an",
"sgdisk",
"operation"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/sgdisk/sgdisk.go#L37-L39 | train |
coreos/ignition | internal/sgdisk/sgdisk.go | CreatePartition | func (op *Operation) CreatePartition(p types.Partition) {
op.parts = append(op.parts, p)
} | go | func (op *Operation) CreatePartition(p types.Partition) {
op.parts = append(op.parts, p)
} | [
"func",
"(",
"op",
"*",
"Operation",
")",
"CreatePartition",
"(",
"p",
"types",
".",
"Partition",
")",
"{",
"op",
".",
"parts",
"=",
"append",
"(",
"op",
".",
"parts",
",",
"p",
")",
"\n",
"}"
] | // CreatePartition adds the supplied partition to the list of partitions to be created as part of an operation. | [
"CreatePartition",
"adds",
"the",
"supplied",
"partition",
"to",
"the",
"list",
"of",
"partitions",
"to",
"be",
"created",
"as",
"part",
"of",
"an",
"operation",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/sgdisk/sgdisk.go#L42-L44 | train |
coreos/ignition | internal/sgdisk/sgdisk.go | Commit | func (op *Operation) Commit() error {
opts := op.buildOptions()
if len(opts) == 0 {
return nil
}
op.logger.Info("running sgdisk with options: %v", opts)
cmd := exec.Command(distro.SgdiskCmd(), opts...)
if _, err := op.logger.LogCmd(cmd, "deleting %d partitions and creating %d partitions on %q", len(op.deletions... | go | func (op *Operation) Commit() error {
opts := op.buildOptions()
if len(opts) == 0 {
return nil
}
op.logger.Info("running sgdisk with options: %v", opts)
cmd := exec.Command(distro.SgdiskCmd(), opts...)
if _, err := op.logger.LogCmd(cmd, "deleting %d partitions and creating %d partitions on %q", len(op.deletions... | [
"func",
"(",
"op",
"*",
"Operation",
")",
"Commit",
"(",
")",
"error",
"{",
"opts",
":=",
"op",
".",
"buildOptions",
"(",
")",
"\n",
"if",
"len",
"(",
"opts",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"op",
".",
"logger",
".",
"Inf... | // Commit commits an partitioning operation. | [
"Commit",
"commits",
"an",
"partitioning",
"operation",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/sgdisk/sgdisk.go#L101-L113 | train |
coreos/ignition | internal/exec/engine.go | Run | func (e Engine) Run(stageName string) error {
if e.Fetcher == nil || e.Logger == nil {
fmt.Fprintf(os.Stderr, "engine incorrectly configured\n")
return errors.ErrEngineConfiguration
}
baseConfig := types.Config{
Ignition: types.Ignition{Version: types.MaxVersion.String()},
}
systemBaseConfig, r, err := syst... | go | func (e Engine) Run(stageName string) error {
if e.Fetcher == nil || e.Logger == nil {
fmt.Fprintf(os.Stderr, "engine incorrectly configured\n")
return errors.ErrEngineConfiguration
}
baseConfig := types.Config{
Ignition: types.Ignition{Version: types.MaxVersion.String()},
}
systemBaseConfig, r, err := syst... | [
"func",
"(",
"e",
"Engine",
")",
"Run",
"(",
"stageName",
"string",
")",
"error",
"{",
"if",
"e",
".",
"Fetcher",
"==",
"nil",
"||",
"e",
".",
"Logger",
"==",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
... | // Run executes the stage of the given name. It returns true if the stage
// successfully ran and false if there were any errors. | [
"Run",
"executes",
"the",
"stage",
"of",
"the",
"given",
"name",
".",
"It",
"returns",
"true",
"if",
"the",
"stage",
"successfully",
"ran",
"and",
"false",
"if",
"there",
"were",
"any",
"errors",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/engine.go#L60-L102 | train |
coreos/ignition | internal/exec/engine.go | acquireConfig | func (e *Engine) acquireConfig() (cfg types.Config, err error) {
// First try read the config @ e.ConfigCache.
b, err := ioutil.ReadFile(e.ConfigCache)
if err == nil {
if err = json.Unmarshal(b, &cfg); err != nil {
e.Logger.Crit("failed to parse cached config: %v", err)
}
// Create an http client and fetch... | go | func (e *Engine) acquireConfig() (cfg types.Config, err error) {
// First try read the config @ e.ConfigCache.
b, err := ioutil.ReadFile(e.ConfigCache)
if err == nil {
if err = json.Unmarshal(b, &cfg); err != nil {
e.Logger.Crit("failed to parse cached config: %v", err)
}
// Create an http client and fetch... | [
"func",
"(",
"e",
"*",
"Engine",
")",
"acquireConfig",
"(",
")",
"(",
"cfg",
"types",
".",
"Config",
",",
"err",
"error",
")",
"{",
"// First try read the config @ e.ConfigCache.",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"e",
".",
"ConfigCac... | // acquireConfig returns the configuration, first checking a local cache
// before attempting to fetch it from the provider. | [
"acquireConfig",
"returns",
"the",
"configuration",
"first",
"checking",
"a",
"local",
"cache",
"before",
"attempting",
"to",
"fetch",
"it",
"from",
"the",
"provider",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/engine.go#L106-L175 | train |
coreos/ignition | internal/exec/engine.go | renderConfig | func (e *Engine) renderConfig(cfg types.Config) (types.Config, error) {
if cfgRef := cfg.Ignition.Config.Replace; cfgRef.Source != nil {
newCfg, err := e.fetchReferencedConfig(cfgRef)
if err != nil {
return types.Config{}, err
}
// Replace the HTTP client in the fetcher to be configured with the
// timeo... | go | func (e *Engine) renderConfig(cfg types.Config) (types.Config, error) {
if cfgRef := cfg.Ignition.Config.Replace; cfgRef.Source != nil {
newCfg, err := e.fetchReferencedConfig(cfgRef)
if err != nil {
return types.Config{}, err
}
// Replace the HTTP client in the fetcher to be configured with the
// timeo... | [
"func",
"(",
"e",
"*",
"Engine",
")",
"renderConfig",
"(",
"cfg",
"types",
".",
"Config",
")",
"(",
"types",
".",
"Config",
",",
"error",
")",
"{",
"if",
"cfgRef",
":=",
"cfg",
".",
"Ignition",
".",
"Config",
".",
"Replace",
";",
"cfgRef",
".",
"So... | // renderConfig evaluates "ignition.config.replace" and "ignition.config.append"
// in the given config and returns the result. If "ignition.config.replace" is
// set, the referenced and evaluted config will be returned. Otherwise, if
// "ignition.config.append" is set, each of the referenced configs will be
// evaluat... | [
"renderConfig",
"evaluates",
"ignition",
".",
"config",
".",
"replace",
"and",
"ignition",
".",
"config",
".",
"append",
"in",
"the",
"given",
"config",
"and",
"returns",
"the",
"result",
".",
"If",
"ignition",
".",
"config",
".",
"replace",
"is",
"set",
"... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/engine.go#L224-L265 | train |
coreos/ignition | internal/exec/engine.go | fetchReferencedConfig | func (e *Engine) fetchReferencedConfig(cfgRef types.ConfigReference) (types.Config, error) {
u, err := url.Parse(*cfgRef.Source)
if err != nil {
return types.Config{}, err
}
rawCfg, err := e.Fetcher.FetchToBuffer(*u, resource.FetchOptions{
Headers: resource.ConfigHeaders,
})
if err != nil {
return types.Con... | go | func (e *Engine) fetchReferencedConfig(cfgRef types.ConfigReference) (types.Config, error) {
u, err := url.Parse(*cfgRef.Source)
if err != nil {
return types.Config{}, err
}
rawCfg, err := e.Fetcher.FetchToBuffer(*u, resource.FetchOptions{
Headers: resource.ConfigHeaders,
})
if err != nil {
return types.Con... | [
"func",
"(",
"e",
"*",
"Engine",
")",
"fetchReferencedConfig",
"(",
"cfgRef",
"types",
".",
"ConfigReference",
")",
"(",
"types",
".",
"Config",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"*",
"cfgRef",
".",
"Source",
")... | // fetchReferencedConfig fetches and parses the requested config.
// cfgRef.Source must not ve nil | [
"fetchReferencedConfig",
"fetches",
"and",
"parses",
"the",
"requested",
"config",
".",
"cfgRef",
".",
"Source",
"must",
"not",
"ve",
"nil"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/engine.go#L269-L300 | train |
coreos/ignition | internal/exec/util/passwd.go | EnsureUser | func (u Util) EnsureUser(c types.PasswdUser) error {
exists, err := u.CheckIfUserExists(c)
if err != nil {
return err
}
args := []string{"--root", u.DestDir}
var cmd string
if exists {
cmd = distro.UsermodCmd()
if c.HomeDir != nil && *c.HomeDir != "" {
args = append(args, "--home", *c.HomeDir, "--move-... | go | func (u Util) EnsureUser(c types.PasswdUser) error {
exists, err := u.CheckIfUserExists(c)
if err != nil {
return err
}
args := []string{"--root", u.DestDir}
var cmd string
if exists {
cmd = distro.UsermodCmd()
if c.HomeDir != nil && *c.HomeDir != "" {
args = append(args, "--home", *c.HomeDir, "--move-... | [
"func",
"(",
"u",
"Util",
")",
"EnsureUser",
"(",
"c",
"types",
".",
"PasswdUser",
")",
"error",
"{",
"exists",
",",
"err",
":=",
"u",
".",
"CheckIfUserExists",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
... | // EnsureUser ensures that the user exists as described. If the user does not
// yet exist, they will be created, otherwise the existing user will be
// modified. | [
"EnsureUser",
"ensures",
"that",
"the",
"user",
"exists",
"as",
"described",
".",
"If",
"the",
"user",
"does",
"not",
"yet",
"exist",
"they",
"will",
"be",
"created",
"otherwise",
"the",
"existing",
"user",
"will",
"be",
"modified",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/passwd.go#L35-L113 | train |
coreos/ignition | internal/exec/util/passwd.go | CheckIfUserExists | func (u Util) CheckIfUserExists(c types.PasswdUser) (bool, error) {
code := -1
cmd := exec.Command(distro.ChrootCmd(), u.DestDir, distro.IdCmd(), c.Name)
stdout, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
code = exitErr.Sys().(syscall.WaitStatus).ExitStatus()
}
... | go | func (u Util) CheckIfUserExists(c types.PasswdUser) (bool, error) {
code := -1
cmd := exec.Command(distro.ChrootCmd(), u.DestDir, distro.IdCmd(), c.Name)
stdout, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
code = exitErr.Sys().(syscall.WaitStatus).ExitStatus()
}
... | [
"func",
"(",
"u",
"Util",
")",
"CheckIfUserExists",
"(",
"c",
"types",
".",
"PasswdUser",
")",
"(",
"bool",
",",
"error",
")",
"{",
"code",
":=",
"-",
"1",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"distro",
".",
"ChrootCmd",
"(",
")",
",",
... | // CheckIfUserExists will return Info log when user is empty | [
"CheckIfUserExists",
"will",
"return",
"Info",
"log",
"when",
"user",
"is",
"empty"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/passwd.go#L116-L132 | train |
coreos/ignition | internal/exec/util/passwd.go | writeAuthKeysFile | func writeAuthKeysFile(u *user.User, fp string, keys []byte) error {
if err := as_user.MkdirAll(u, filepath.Dir(fp), 0700); err != nil {
return err
}
f, err := as_user.OpenFile(u, fp, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_TRUNC, 0600)
if err != nil {
return err
}
if _, err = f.Write(keys); err != nil {
... | go | func writeAuthKeysFile(u *user.User, fp string, keys []byte) error {
if err := as_user.MkdirAll(u, filepath.Dir(fp), 0700); err != nil {
return err
}
f, err := as_user.OpenFile(u, fp, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_TRUNC, 0600)
if err != nil {
return err
}
if _, err = f.Write(keys); err != nil {
... | [
"func",
"writeAuthKeysFile",
"(",
"u",
"*",
"user",
".",
"User",
",",
"fp",
"string",
",",
"keys",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"as_user",
".",
"MkdirAll",
"(",
"u",
",",
"filepath",
".",
"Dir",
"(",
"fp",
")",
",",
"07... | // writeAuthKeysFile writes the content in keys to the path fp for the user,
// creating any directories in fp as needed. | [
"writeAuthKeysFile",
"writes",
"the",
"content",
"in",
"keys",
"to",
"the",
"path",
"fp",
"for",
"the",
"user",
"creating",
"any",
"directories",
"in",
"fp",
"as",
"needed",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/passwd.go#L145-L161 | train |
coreos/ignition | internal/exec/util/passwd.go | AuthorizeSSHKeys | func (u Util) AuthorizeSSHKeys(c types.PasswdUser) error {
if len(c.SSHAuthorizedKeys) == 0 {
return nil
}
return u.LogOp(func() error {
usr, err := u.userLookup(c.Name)
if err != nil {
return fmt.Errorf("unable to lookup user %q", c.Name)
}
// TODO(vc): introduce key names to config?
// TODO(vc): v... | go | func (u Util) AuthorizeSSHKeys(c types.PasswdUser) error {
if len(c.SSHAuthorizedKeys) == 0 {
return nil
}
return u.LogOp(func() error {
usr, err := u.userLookup(c.Name)
if err != nil {
return fmt.Errorf("unable to lookup user %q", c.Name)
}
// TODO(vc): introduce key names to config?
// TODO(vc): v... | [
"func",
"(",
"u",
"Util",
")",
"AuthorizeSSHKeys",
"(",
"c",
"types",
".",
"PasswdUser",
")",
"error",
"{",
"if",
"len",
"(",
"c",
".",
"SSHAuthorizedKeys",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"u",
".",
"LogOp",
"(",
... | // AuthorizeSSHKeys adds the provided SSH public keys to the user's authorized keys. | [
"AuthorizeSSHKeys",
"adds",
"the",
"provided",
"SSH",
"public",
"keys",
"to",
"the",
"user",
"s",
"authorized",
"keys",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/passwd.go#L164-L194 | train |
coreos/ignition | internal/exec/util/passwd.go | SetPasswordHash | func (u Util) SetPasswordHash(c types.PasswdUser) error {
if c.PasswordHash == nil {
return nil
}
pwhash := *c.PasswordHash
if *c.PasswordHash == "" {
pwhash = "*"
}
args := []string{
"--root", u.DestDir,
"--password", pwhash,
}
args = append(args, c.Name)
_, err := u.LogCmd(exec.Command(distro.Use... | go | func (u Util) SetPasswordHash(c types.PasswdUser) error {
if c.PasswordHash == nil {
return nil
}
pwhash := *c.PasswordHash
if *c.PasswordHash == "" {
pwhash = "*"
}
args := []string{
"--root", u.DestDir,
"--password", pwhash,
}
args = append(args, c.Name)
_, err := u.LogCmd(exec.Command(distro.Use... | [
"func",
"(",
"u",
"Util",
")",
"SetPasswordHash",
"(",
"c",
"types",
".",
"PasswdUser",
")",
"error",
"{",
"if",
"c",
".",
"PasswordHash",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"pwhash",
":=",
"*",
"c",
".",
"PasswordHash",
"\n",
"if"... | // SetPasswordHash sets the password hash of the specified user. | [
"SetPasswordHash",
"sets",
"the",
"password",
"hash",
"of",
"the",
"specified",
"user",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/passwd.go#L206-L226 | train |
coreos/ignition | internal/exec/util/passwd.go | CreateGroup | func (u Util) CreateGroup(g types.PasswdGroup) error {
args := []string{"--root", u.DestDir}
if g.Gid != nil {
args = append(args, "--gid",
strconv.FormatUint(uint64(*g.Gid), 10))
}
if g.PasswordHash != nil && *g.PasswordHash != "" {
args = append(args, "--password", *g.PasswordHash)
} else {
args = app... | go | func (u Util) CreateGroup(g types.PasswdGroup) error {
args := []string{"--root", u.DestDir}
if g.Gid != nil {
args = append(args, "--gid",
strconv.FormatUint(uint64(*g.Gid), 10))
}
if g.PasswordHash != nil && *g.PasswordHash != "" {
args = append(args, "--password", *g.PasswordHash)
} else {
args = app... | [
"func",
"(",
"u",
"Util",
")",
"CreateGroup",
"(",
"g",
"types",
".",
"PasswdGroup",
")",
"error",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"u",
".",
"DestDir",
"}",
"\n\n",
"if",
"g",
".",
"Gid",
"!=",
"nil",
"{",
"args",
"... | // CreateGroup creates the group as described. | [
"CreateGroup",
"creates",
"the",
"group",
"as",
"described",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/passwd.go#L229-L252 | train |
coreos/ignition | config/translate/translate.go | couldBeValidTranslator | func couldBeValidTranslator(t reflect.Type) bool {
if t.Kind() != reflect.Func {
return false
}
if t.NumIn() != 1 || t.NumOut() != 1 {
return false
}
if util.IsInvalidInConfig(t.In(0).Kind()) || util.IsInvalidInConfig(t.Out(0).Kind()) {
return false
}
return true
} | go | func couldBeValidTranslator(t reflect.Type) bool {
if t.Kind() != reflect.Func {
return false
}
if t.NumIn() != 1 || t.NumOut() != 1 {
return false
}
if util.IsInvalidInConfig(t.In(0).Kind()) || util.IsInvalidInConfig(t.Out(0).Kind()) {
return false
}
return true
} | [
"func",
"couldBeValidTranslator",
"(",
"t",
"reflect",
".",
"Type",
")",
"bool",
"{",
"if",
"t",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Func",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"t",
".",
"NumIn",
"(",
")",
"!=",
"1",
"||",
"t"... | // checks that t could reasonably be the type of a translator function | [
"checks",
"that",
"t",
"could",
"reasonably",
"be",
"the",
"type",
"of",
"a",
"translator",
"function"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/translate/translate.go#L78-L89 | train |
coreos/ignition | config/translate/translate.go | hasTranslator | func (t translator) hasTranslator(tFrom, tTo reflect.Type) bool {
return t.getTranslator(tFrom, tTo).IsValid()
} | go | func (t translator) hasTranslator(tFrom, tTo reflect.Type) bool {
return t.getTranslator(tFrom, tTo).IsValid()
} | [
"func",
"(",
"t",
"translator",
")",
"hasTranslator",
"(",
"tFrom",
",",
"tTo",
"reflect",
".",
"Type",
")",
"bool",
"{",
"return",
"t",
".",
"getTranslator",
"(",
"tFrom",
",",
"tTo",
")",
".",
"IsValid",
"(",
")",
"\n",
"}"
] | // helper to return if a custom translator was defined | [
"helper",
"to",
"return",
"if",
"a",
"custom",
"translator",
"was",
"defined"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/translate/translate.go#L125-L127 | train |
coreos/ignition | config/util/parsingErrors.go | HandleParseErrors | func HandleParseErrors(rawConfig []byte, to interface{}) (report.Report, error) {
err := json.Unmarshal(rawConfig, to)
if err == nil {
return report.Report{}, nil
}
// Handle json syntax and type errors first, since they are fatal but have offset info
if serr, ok := err.(*json.SyntaxError); ok {
line, col, hi... | go | func HandleParseErrors(rawConfig []byte, to interface{}) (report.Report, error) {
err := json.Unmarshal(rawConfig, to)
if err == nil {
return report.Report{}, nil
}
// Handle json syntax and type errors first, since they are fatal but have offset info
if serr, ok := err.(*json.SyntaxError); ok {
line, col, hi... | [
"func",
"HandleParseErrors",
"(",
"rawConfig",
"[",
"]",
"byte",
",",
"to",
"interface",
"{",
"}",
")",
"(",
"report",
".",
"Report",
",",
"error",
")",
"{",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"rawConfig",
",",
"to",
")",
"\n",
"if",
"err",
... | // HandleParseErrors will attempt to unmarshal an invalid rawConfig into "to".
// If it fails to unmarsh it will generate a report.Report from the errors. | [
"HandleParseErrors",
"will",
"attempt",
"to",
"unmarshal",
"an",
"invalid",
"rawConfig",
"into",
"to",
".",
"If",
"it",
"fails",
"to",
"unmarsh",
"it",
"will",
"generate",
"a",
"report",
".",
"Report",
"from",
"the",
"errors",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/util/parsingErrors.go#L27-L63 | train |
coreos/ignition | config/shared/validations/unit.go | ValidateInstallSection | func ValidateInstallSection(name string, enabled bool, contentsEmpty bool, contentSections []*unit.UnitOption) report.Report {
if !enabled {
// install sections don't matter for not-enabled units
return report.Report{}
}
if contentsEmpty {
// install sections don't matter if it has no contents, e.g. it's being... | go | func ValidateInstallSection(name string, enabled bool, contentsEmpty bool, contentSections []*unit.UnitOption) report.Report {
if !enabled {
// install sections don't matter for not-enabled units
return report.Report{}
}
if contentsEmpty {
// install sections don't matter if it has no contents, e.g. it's being... | [
"func",
"ValidateInstallSection",
"(",
"name",
"string",
",",
"enabled",
"bool",
",",
"contentsEmpty",
"bool",
",",
"contentSections",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
")",
"report",
".",
"Report",
"{",
"if",
"!",
"enabled",
"{",
"// install sections ... | // ValidateInstallSection is a helper to validate a given unit | [
"ValidateInstallSection",
"is",
"a",
"helper",
"to",
"validate",
"a",
"given",
"unit"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/shared/validations/unit.go#L26-L54 | train |
coreos/ignition | config/validate/astjson/node.go | posFromOffset | func posFromOffset(offset int, source []byte) (int, int, string) {
if source == nil {
return 0, 0, ""
}
return util.Highlight(source, int64(offset))
} | go | func posFromOffset(offset int, source []byte) (int, int, string) {
if source == nil {
return 0, 0, ""
}
return util.Highlight(source, int64(offset))
} | [
"func",
"posFromOffset",
"(",
"offset",
"int",
",",
"source",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"int",
",",
"string",
")",
"{",
"if",
"source",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"util",
... | // wrapper for errorutil that handles missing sources sanely and resets the reader afterwards | [
"wrapper",
"for",
"errorutil",
"that",
"handles",
"missing",
"sources",
"sanely",
"and",
"resets",
"the",
"reader",
"afterwards"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/validate/astjson/node.go#L64-L69 | train |
coreos/ignition | internal/log/log.go | New | func New(logToStdout bool) Logger {
logger := Logger{}
if !logToStdout {
var err error
logger.ops, err = syslog.New(syslog.LOG_DEBUG, "ignition")
if err != nil {
logger.ops = Stdout{}
logger.Err("unable to open syslog: %v", err)
}
return logger
}
logger.ops = Stdout{}
return logger
} | go | func New(logToStdout bool) Logger {
logger := Logger{}
if !logToStdout {
var err error
logger.ops, err = syslog.New(syslog.LOG_DEBUG, "ignition")
if err != nil {
logger.ops = Stdout{}
logger.Err("unable to open syslog: %v", err)
}
return logger
}
logger.ops = Stdout{}
return logger
} | [
"func",
"New",
"(",
"logToStdout",
"bool",
")",
"Logger",
"{",
"logger",
":=",
"Logger",
"{",
"}",
"\n",
"if",
"!",
"logToStdout",
"{",
"var",
"err",
"error",
"\n",
"logger",
".",
"ops",
",",
"err",
"=",
"syslog",
".",
"New",
"(",
"syslog",
".",
"L... | // New creates a new logger.
// If logToStdout is true, syslog is tried first. If syslog fails or logToStdout
// is false Stdout is used. | [
"New",
"creates",
"a",
"new",
"logger",
".",
"If",
"logToStdout",
"is",
"true",
"syslog",
"is",
"tried",
"first",
".",
"If",
"syslog",
"fails",
"or",
"logToStdout",
"is",
"false",
"Stdout",
"is",
"used",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/log/log.go#L48-L61 | train |
coreos/ignition | internal/log/log.go | Crit | func (l Logger) Crit(format string, a ...interface{}) error {
return l.log(l.ops.Crit, format, a...)
} | go | func (l Logger) Crit(format string, a ...interface{}) error {
return l.log(l.ops.Crit, format, a...)
} | [
"func",
"(",
"l",
"Logger",
")",
"Crit",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"l",
".",
"log",
"(",
"l",
".",
"ops",
".",
"Crit",
",",
"format",
",",
"a",
"...",
")",
"\n",
"}"
] | // Crit logs a message at critical priority. | [
"Crit",
"logs",
"a",
"message",
"at",
"critical",
"priority",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/log/log.go#L79-L81 | train |
coreos/ignition | internal/log/log.go | PushPrefix | func (l *Logger) PushPrefix(format string, a ...interface{}) {
l.prefixStack = append(l.prefixStack, fmt.Sprintf(format, a...))
} | go | func (l *Logger) PushPrefix(format string, a ...interface{}) {
l.prefixStack = append(l.prefixStack, fmt.Sprintf(format, a...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"PushPrefix",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"prefixStack",
"=",
"append",
"(",
"l",
".",
"prefixStack",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"a"... | // PushPrefix pushes the supplied message onto the Logger's prefix stack.
// The prefix stack is concatenated in FIFO order and prefixed to the start of every message logged via Logger. | [
"PushPrefix",
"pushes",
"the",
"supplied",
"message",
"onto",
"the",
"Logger",
"s",
"prefix",
"stack",
".",
"The",
"prefix",
"stack",
"is",
"concatenated",
"in",
"FIFO",
"order",
"and",
"prefixed",
"to",
"the",
"start",
"of",
"every",
"message",
"logged",
"v... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/log/log.go#L110-L112 | train |
coreos/ignition | internal/log/log.go | PopPrefix | func (l *Logger) PopPrefix() {
if len(l.prefixStack) == 0 {
l.Debug("popped from empty stack")
return
}
l.prefixStack = l.prefixStack[:len(l.prefixStack)-1]
} | go | func (l *Logger) PopPrefix() {
if len(l.prefixStack) == 0 {
l.Debug("popped from empty stack")
return
}
l.prefixStack = l.prefixStack[:len(l.prefixStack)-1]
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"PopPrefix",
"(",
")",
"{",
"if",
"len",
"(",
"l",
".",
"prefixStack",
")",
"==",
"0",
"{",
"l",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"l",
".",
"prefixStack",
"=",
"l",
"."... | // PopPrefix pops the top entry from the Logger's prefix stack.
// The prefix stack is concatenated in FIFO order and prefixed to the start of every message logged via Logger. | [
"PopPrefix",
"pops",
"the",
"top",
"entry",
"from",
"the",
"Logger",
"s",
"prefix",
"stack",
".",
"The",
"prefix",
"stack",
"is",
"concatenated",
"in",
"FIFO",
"order",
"and",
"prefixed",
"to",
"the",
"start",
"of",
"every",
"message",
"logged",
"via",
"Lo... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/log/log.go#L116-L122 | train |
coreos/ignition | internal/log/log.go | QuotedCmd | func QuotedCmd(cmd *exec.Cmd) string {
if len(cmd.Args) == 0 {
return fmt.Sprintf("%q", cmd.Path)
}
var q []string
for _, s := range cmd.Args {
q = append(q, fmt.Sprintf("%q", s))
}
return strings.Join(q, ` `)
} | go | func QuotedCmd(cmd *exec.Cmd) string {
if len(cmd.Args) == 0 {
return fmt.Sprintf("%q", cmd.Path)
}
var q []string
for _, s := range cmd.Args {
q = append(q, fmt.Sprintf("%q", s))
}
return strings.Join(q, ` `)
} | [
"func",
"QuotedCmd",
"(",
"cmd",
"*",
"exec",
".",
"Cmd",
")",
"string",
"{",
"if",
"len",
"(",
"cmd",
".",
"Args",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cmd",
".",
"Path",
")",
"\n",
"}",
"\n\n",
"var",
... | // QuotedCmd returns a concatenated, quoted form of cmd's cmdline | [
"QuotedCmd",
"returns",
"a",
"concatenated",
"quoted",
"form",
"of",
"cmd",
"s",
"cmdline"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/log/log.go#L125-L136 | train |
coreos/ignition | internal/log/log.go | log | func (l Logger) log(logFunc func(string) error, format string, a ...interface{}) error {
return logFunc(l.sprintf(format, a...))
} | go | func (l Logger) log(logFunc func(string) error, format string, a ...interface{}) error {
return logFunc(l.sprintf(format, a...))
} | [
"func",
"(",
"l",
"Logger",
")",
"log",
"(",
"logFunc",
"func",
"(",
"string",
")",
"error",
",",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"logFunc",
"(",
"l",
".",
"sprintf",
"(",
"format",
",",
"a",... | // log logs a formatted message using the supplied logFunc. | [
"log",
"logs",
"a",
"formatted",
"message",
"using",
"the",
"supplied",
"logFunc",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/log/log.go#L193-L195 | train |
coreos/ignition | internal/log/log.go | sprintf | func (l Logger) sprintf(format string, a ...interface{}) string {
m := []string{}
for _, pfx := range l.prefixStack {
m = append(m, fmt.Sprintf("%s:", pfx))
}
m = append(m, fmt.Sprintf(format, a...))
return strings.Join(m, " ")
} | go | func (l Logger) sprintf(format string, a ...interface{}) string {
m := []string{}
for _, pfx := range l.prefixStack {
m = append(m, fmt.Sprintf("%s:", pfx))
}
m = append(m, fmt.Sprintf(format, a...))
return strings.Join(m, " ")
} | [
"func",
"(",
"l",
"Logger",
")",
"sprintf",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"m",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"pfx",
":=",
"range",
"l",
".",
"prefixStack",
"{",
... | // sprintf returns the current prefix stack, if any, concatenated with the supplied format string and args in expanded form. | [
"sprintf",
"returns",
"the",
"current",
"prefix",
"stack",
"if",
"any",
"concatenated",
"with",
"the",
"supplied",
"format",
"string",
"and",
"args",
"in",
"expanded",
"form",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/log/log.go#L198-L205 | train |
coreos/ignition | internal/exec/stages/disks/filesystems.go | createFilesystems | func (s stage) createFilesystems(config types.Config) error {
fss := config.Storage.Filesystems
s.Logger.Info("fss: %v", fss)
if len(fss) == 0 {
return nil
}
s.Logger.PushPrefix("createFilesystems")
defer s.Logger.PopPrefix()
devs := []string{}
for _, fs := range fss {
devs = append(devs, string(fs.Devic... | go | func (s stage) createFilesystems(config types.Config) error {
fss := config.Storage.Filesystems
s.Logger.Info("fss: %v", fss)
if len(fss) == 0 {
return nil
}
s.Logger.PushPrefix("createFilesystems")
defer s.Logger.PopPrefix()
devs := []string{}
for _, fs := range fss {
devs = append(devs, string(fs.Devic... | [
"func",
"(",
"s",
"stage",
")",
"createFilesystems",
"(",
"config",
"types",
".",
"Config",
")",
"error",
"{",
"fss",
":=",
"config",
".",
"Storage",
".",
"Filesystems",
"\n",
"s",
".",
"Logger",
".",
"Info",
"(",
"\"",
"\"",
",",
"fss",
")",
"\n\n",... | // createFilesystems creates the filesystems described in config.Storage.Filesystems. | [
"createFilesystems",
"creates",
"the",
"filesystems",
"described",
"in",
"config",
".",
"Storage",
".",
"Filesystems",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/disks/filesystems.go#L38-L89 | train |
coreos/ignition | internal/exec/stages/disks/filesystems.go | canonicalizeFilesystemUUID | func canonicalizeFilesystemUUID(format, uuid string) string {
uuid = strings.ToLower(uuid)
if format == "vfat" {
// FAT uses a 32-bit volume ID instead of a UUID. blkid
// (and the rest of the world) formats it as A1B2-C3D4, but
// mkfs.fat doesn't permit the dash, so strip it. Older
// versions of Ignition w... | go | func canonicalizeFilesystemUUID(format, uuid string) string {
uuid = strings.ToLower(uuid)
if format == "vfat" {
// FAT uses a 32-bit volume ID instead of a UUID. blkid
// (and the rest of the world) formats it as A1B2-C3D4, but
// mkfs.fat doesn't permit the dash, so strip it. Older
// versions of Ignition w... | [
"func",
"canonicalizeFilesystemUUID",
"(",
"format",
",",
"uuid",
"string",
")",
"string",
"{",
"uuid",
"=",
"strings",
".",
"ToLower",
"(",
"uuid",
")",
"\n",
"if",
"format",
"==",
"\"",
"\"",
"{",
"// FAT uses a 32-bit volume ID instead of a UUID. blkid",
"// (a... | // canonicalizeFilesystemUUID does the minimum amount of canonicalization
// required to make two valid equivalent UUIDs compare equal, but doesn't
// attempt to fully validate the UUID. | [
"canonicalizeFilesystemUUID",
"does",
"the",
"minimum",
"amount",
"of",
"canonicalization",
"required",
"to",
"make",
"two",
"valid",
"equivalent",
"UUIDs",
"compare",
"equal",
"but",
"doesn",
"t",
"attempt",
"to",
"fully",
"validate",
"the",
"UUID",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/disks/filesystems.go#L224-L237 | train |
coreos/ignition | internal/util/tools/docs/docs.go | isDeprecatedConfig | func isDeprecatedConfig(r report.Report) bool {
if len(r.Entries) != 1 {
return false
}
if r.Entries[0].Kind == report.EntryDeprecated && r.Entries[0].Message == errors.ErrDeprecated.Error() {
return true
}
return false
} | go | func isDeprecatedConfig(r report.Report) bool {
if len(r.Entries) != 1 {
return false
}
if r.Entries[0].Kind == report.EntryDeprecated && r.Entries[0].Message == errors.ErrDeprecated.Error() {
return true
}
return false
} | [
"func",
"isDeprecatedConfig",
"(",
"r",
"report",
".",
"Report",
")",
"bool",
"{",
"if",
"len",
"(",
"r",
".",
"Entries",
")",
"!=",
"1",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"r",
".",
"Entries",
"[",
"0",
"]",
".",
"Kind",
"==",
"repor... | // isDeprecatedConfig returns if a report is from a deprecated config format. | [
"isDeprecatedConfig",
"returns",
"if",
"a",
"report",
"is",
"from",
"a",
"deprecated",
"config",
"format",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/util/tools/docs/docs.go#L82-L90 | train |
coreos/ignition | internal/exec/stages/disks/partitions.go | createPartitions | func (s stage) createPartitions(config types.Config) error {
if len(config.Storage.Disks) == 0 {
return nil
}
s.Logger.PushPrefix("createPartitions")
defer s.Logger.PopPrefix()
devs := []string{}
for _, disk := range config.Storage.Disks {
devs = append(devs, string(disk.Device))
}
if err := s.waitOnDevic... | go | func (s stage) createPartitions(config types.Config) error {
if len(config.Storage.Disks) == 0 {
return nil
}
s.Logger.PushPrefix("createPartitions")
defer s.Logger.PopPrefix()
devs := []string{}
for _, disk := range config.Storage.Disks {
devs = append(devs, string(disk.Device))
}
if err := s.waitOnDevic... | [
"func",
"(",
"s",
"stage",
")",
"createPartitions",
"(",
"config",
"types",
".",
"Config",
")",
"error",
"{",
"if",
"len",
"(",
"config",
".",
"Storage",
".",
"Disks",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"s",
".",
"Logger",
".",
... | // createPartitions creates the partitions described in config.Storage.Disks. | [
"createPartitions",
"creates",
"the",
"partitions",
"described",
"in",
"config",
".",
"Storage",
".",
"Disks",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/disks/partitions.go#L39-L67 | train |
coreos/ignition | internal/exec/stages/disks/partitions.go | partitionShouldBeInspected | func partitionShouldBeInspected(part types.Partition) bool {
if part.Number == 0 {
return false
}
return (part.StartMiB != nil && *part.StartMiB == 0) ||
(part.SizeMiB != nil && *part.SizeMiB == 0)
} | go | func partitionShouldBeInspected(part types.Partition) bool {
if part.Number == 0 {
return false
}
return (part.StartMiB != nil && *part.StartMiB == 0) ||
(part.SizeMiB != nil && *part.SizeMiB == 0)
} | [
"func",
"partitionShouldBeInspected",
"(",
"part",
"types",
".",
"Partition",
")",
"bool",
"{",
"if",
"part",
".",
"Number",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"(",
"part",
".",
"StartMiB",
"!=",
"nil",
"&&",
"*",
"part",
"."... | // partitionShouldBeInspected returns if the partition has zeroes that need to be resolved to sectors. | [
"partitionShouldBeInspected",
"returns",
"if",
"the",
"partition",
"has",
"zeroes",
"that",
"need",
"to",
"be",
"resolved",
"to",
"sectors",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/disks/partitions.go#L96-L102 | train |
coreos/ignition | internal/exec/stages/disks/partitions.go | parseLine | func parseLine(r *regexp.Regexp, line string) (int, error) {
matches := r.FindStringSubmatch(line)
switch len(matches) {
case 0:
return -1, nil
case 2:
return strconv.Atoi(matches[1])
default:
return 0, ErrBadSgdiskOutput
}
} | go | func parseLine(r *regexp.Regexp, line string) (int, error) {
matches := r.FindStringSubmatch(line)
switch len(matches) {
case 0:
return -1, nil
case 2:
return strconv.Atoi(matches[1])
default:
return 0, ErrBadSgdiskOutput
}
} | [
"func",
"parseLine",
"(",
"r",
"*",
"regexp",
".",
"Regexp",
",",
"line",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"matches",
":=",
"r",
".",
"FindStringSubmatch",
"(",
"line",
")",
"\n",
"switch",
"len",
"(",
"matches",
")",
"{",
"case",
... | // parseLine takes a regexp that captures an int and a string to match on. On success it returns
// the captured int and nil. If the regexp does not match it returns -1 and nil. If it encountered
// an error it returns 0 and the error. | [
"parseLine",
"takes",
"a",
"regexp",
"that",
"captures",
"an",
"int",
"and",
"a",
"string",
"to",
"match",
"on",
".",
"On",
"success",
"it",
"returns",
"the",
"captured",
"int",
"and",
"nil",
".",
"If",
"the",
"regexp",
"does",
"not",
"match",
"it",
"r... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/disks/partitions.go#L180-L190 | train |
coreos/ignition | internal/exec/stages/disks/partitions.go | getPartitionMap | func (s stage) getPartitionMap(device string) (util.DiskInfo, error) {
info := util.DiskInfo{}
err := s.Logger.LogOp(
func() error {
var err error
info, err = util.DumpDisk(device)
return err
}, "reading partition table of %q", device)
if err != nil {
return util.DiskInfo{}, err
}
return info, nil
} | go | func (s stage) getPartitionMap(device string) (util.DiskInfo, error) {
info := util.DiskInfo{}
err := s.Logger.LogOp(
func() error {
var err error
info, err = util.DumpDisk(device)
return err
}, "reading partition table of %q", device)
if err != nil {
return util.DiskInfo{}, err
}
return info, nil
} | [
"func",
"(",
"s",
"stage",
")",
"getPartitionMap",
"(",
"device",
"string",
")",
"(",
"util",
".",
"DiskInfo",
",",
"error",
")",
"{",
"info",
":=",
"util",
".",
"DiskInfo",
"{",
"}",
"\n",
"err",
":=",
"s",
".",
"Logger",
".",
"LogOp",
"(",
"func"... | // getPartitionMap returns a map of partitions on device, indexed by partition number | [
"getPartitionMap",
"returns",
"a",
"map",
"of",
"partitions",
"on",
"device",
"indexed",
"by",
"partition",
"number"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/disks/partitions.go#L266-L278 | train |
coreos/ignition | internal/exec/stages/disks/partitions.go | Less | func (p PartitionList) Less(i, j int) bool {
return p[i].Number != 0 && p[j].Number == 0
} | go | func (p PartitionList) Less(i, j int) bool {
return p[i].Number != 0 && p[j].Number == 0
} | [
"func",
"(",
"p",
"PartitionList",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"p",
"[",
"i",
"]",
".",
"Number",
"!=",
"0",
"&&",
"p",
"[",
"j",
"]",
".",
"Number",
"==",
"0",
"\n",
"}"
] | // We only care about partitions with number 0 being considered the "largest" elements
// so they are processed last. | [
"We",
"only",
"care",
"about",
"partitions",
"with",
"number",
"0",
"being",
"considered",
"the",
"largest",
"elements",
"so",
"they",
"are",
"processed",
"last",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/disks/partitions.go#L290-L292 | train |
coreos/ignition | internal/exec/stages/disks/partitions.go | partitionDisk | func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
if dev.WipeTable != nil && *dev.WipeTable {
op := sgdisk.Begin(s.Logger, devAlias)
s.Logger.Info("wiping partition table requested on %q", devAlias)
op.WipeTable(true)
op.Commit()
}
// Ensure all partitions with number 0 are last
sort.St... | go | func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
if dev.WipeTable != nil && *dev.WipeTable {
op := sgdisk.Begin(s.Logger, devAlias)
s.Logger.Info("wiping partition table requested on %q", devAlias)
op.WipeTable(true)
op.Commit()
}
// Ensure all partitions with number 0 are last
sort.St... | [
"func",
"(",
"s",
"stage",
")",
"partitionDisk",
"(",
"dev",
"types",
".",
"Disk",
",",
"devAlias",
"string",
")",
"error",
"{",
"if",
"dev",
".",
"WipeTable",
"!=",
"nil",
"&&",
"*",
"dev",
".",
"WipeTable",
"{",
"op",
":=",
"sgdisk",
".",
"Begin",
... | // partitionDisk partitions devAlias according to the spec given by dev | [
"partitionDisk",
"partitions",
"devAlias",
"according",
"to",
"the",
"spec",
"given",
"by",
"dev"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/disks/partitions.go#L299-L363 | train |
coreos/ignition | config/validate/validate.go | ValidateConfig | func ValidateConfig(rawConfig []byte, config interface{}) report.Report {
// Unmarshal again to a json.Node to get offset information for building a report
var ast json.Node
var r report.Report
configValue := reflect.ValueOf(config)
if err := json.Unmarshal(rawConfig, &ast); err != nil {
r.Add(report.Entry{
K... | go | func ValidateConfig(rawConfig []byte, config interface{}) report.Report {
// Unmarshal again to a json.Node to get offset information for building a report
var ast json.Node
var r report.Report
configValue := reflect.ValueOf(config)
if err := json.Unmarshal(rawConfig, &ast); err != nil {
r.Add(report.Entry{
K... | [
"func",
"ValidateConfig",
"(",
"rawConfig",
"[",
"]",
"byte",
",",
"config",
"interface",
"{",
"}",
")",
"report",
".",
"Report",
"{",
"// Unmarshal again to a json.Node to get offset information for building a report",
"var",
"ast",
"json",
".",
"Node",
"\n",
"var",
... | // ValidateConfig validates a raw config object into a given config version | [
"ValidateConfig",
"validates",
"a",
"raw",
"config",
"object",
"into",
"a",
"given",
"config",
"version"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/validate/validate.go#L34-L49 | train |
coreos/ignition | config/validate/validate.go | Validate | func Validate(vObj reflect.Value, ast astnode.AstNode, source []byte, checkUnusedKeys bool) (r report.Report) {
if !vObj.IsValid() {
return
}
line, col, highlight := 0, 0, ""
if ast != nil {
line, col, highlight = ast.ValueLineCol(source)
}
// See if we A) can call Validate on vObj, and B) should call Valid... | go | func Validate(vObj reflect.Value, ast astnode.AstNode, source []byte, checkUnusedKeys bool) (r report.Report) {
if !vObj.IsValid() {
return
}
line, col, highlight := 0, 0, ""
if ast != nil {
line, col, highlight = ast.ValueLineCol(source)
}
// See if we A) can call Validate on vObj, and B) should call Valid... | [
"func",
"Validate",
"(",
"vObj",
"reflect",
".",
"Value",
",",
"ast",
"astnode",
".",
"AstNode",
",",
"source",
"[",
"]",
"byte",
",",
"checkUnusedKeys",
"bool",
")",
"(",
"r",
"report",
".",
"Report",
")",
"{",
"if",
"!",
"vObj",
".",
"IsValid",
"("... | // Validate walks down a struct tree calling Validate on every node that implements it, building
// A report of all the errors, warnings, info, and deprecations it encounters. If checkUnusedKeys
// is true, Validate will generate warnings for unused keys in the ast, otherwise it will not. | [
"Validate",
"walks",
"down",
"a",
"struct",
"tree",
"calling",
"Validate",
"on",
"every",
"node",
"that",
"implements",
"it",
"building",
"A",
"report",
"of",
"all",
"the",
"errors",
"warnings",
"info",
"and",
"deprecations",
"it",
"encounters",
".",
"If",
"... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/validate/validate.go#L54-L105 | train |
coreos/ignition | config/validate/validate.go | similar | func similar(str string, candidates []string) string {
for _, candidate := range candidates {
if strings.EqualFold(str, candidate) {
return candidate
}
}
return ""
} | go | func similar(str string, candidates []string) string {
for _, candidate := range candidates {
if strings.EqualFold(str, candidate) {
return candidate
}
}
return ""
} | [
"func",
"similar",
"(",
"str",
"string",
",",
"candidates",
"[",
"]",
"string",
")",
"string",
"{",
"for",
"_",
",",
"candidate",
":=",
"range",
"candidates",
"{",
"if",
"strings",
".",
"EqualFold",
"(",
"str",
",",
"candidate",
")",
"{",
"return",
"ca... | // similar returns a string in candidates that is similar to str. Currently it just does case
// insensitive comparison, but it should be updated to use levenstein distances to catch typos | [
"similar",
"returns",
"a",
"string",
"in",
"candidates",
"that",
"is",
"similar",
"to",
"str",
".",
"Currently",
"it",
"just",
"does",
"case",
"insensitive",
"comparison",
"but",
"it",
"should",
"be",
"updated",
"to",
"use",
"levenstein",
"distances",
"to",
... | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/validate/validate.go#L292-L299 | train |
coreos/ignition | internal/exec/stages/files/passwd.go | createPasswd | func (s *stage) createPasswd(config types.Config) error {
if err := s.createGroups(config); err != nil {
return fmt.Errorf("failed to create groups: %v", err)
}
if err := s.createUsers(config); err != nil {
return fmt.Errorf("failed to create users: %v", err)
}
// to be safe, just blanket mark all passwd-rel... | go | func (s *stage) createPasswd(config types.Config) error {
if err := s.createGroups(config); err != nil {
return fmt.Errorf("failed to create groups: %v", err)
}
if err := s.createUsers(config); err != nil {
return fmt.Errorf("failed to create users: %v", err)
}
// to be safe, just blanket mark all passwd-rel... | [
"func",
"(",
"s",
"*",
"stage",
")",
"createPasswd",
"(",
"config",
"types",
".",
"Config",
")",
"error",
"{",
"if",
"err",
":=",
"s",
".",
"createGroups",
"(",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",... | // createPasswd creates the users and groups as described in config.Passwd. | [
"createPasswd",
"creates",
"the",
"users",
"and",
"groups",
"as",
"described",
"in",
"config",
".",
"Passwd",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/files/passwd.go#L24-L53 | train |
coreos/ignition | internal/exec/stages/files/passwd.go | createUsers | func (s stage) createUsers(config types.Config) error {
if len(config.Passwd.Users) == 0 {
return nil
}
s.Logger.PushPrefix("createUsers")
defer s.Logger.PopPrefix()
for _, u := range config.Passwd.Users {
if err := s.EnsureUser(u); err != nil {
return fmt.Errorf("failed to create user %q: %v",
u.Name,... | go | func (s stage) createUsers(config types.Config) error {
if len(config.Passwd.Users) == 0 {
return nil
}
s.Logger.PushPrefix("createUsers")
defer s.Logger.PopPrefix()
for _, u := range config.Passwd.Users {
if err := s.EnsureUser(u); err != nil {
return fmt.Errorf("failed to create user %q: %v",
u.Name,... | [
"func",
"(",
"s",
"stage",
")",
"createUsers",
"(",
"config",
"types",
".",
"Config",
")",
"error",
"{",
"if",
"len",
"(",
"config",
".",
"Passwd",
".",
"Users",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"s",
".",
"Logger",
".",
"Pus... | // createUsers creates the users as described in config.Passwd.Users. | [
"createUsers",
"creates",
"the",
"users",
"as",
"described",
"in",
"config",
".",
"Passwd",
".",
"Users",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/files/passwd.go#L56-L81 | train |
coreos/ignition | internal/exec/stages/files/passwd.go | createGroups | func (s stage) createGroups(config types.Config) error {
if len(config.Passwd.Groups) == 0 {
return nil
}
s.Logger.PushPrefix("createGroups")
defer s.Logger.PopPrefix()
for _, g := range config.Passwd.Groups {
if err := s.CreateGroup(g); err != nil {
return fmt.Errorf("failed to create group %q: %v",
g... | go | func (s stage) createGroups(config types.Config) error {
if len(config.Passwd.Groups) == 0 {
return nil
}
s.Logger.PushPrefix("createGroups")
defer s.Logger.PopPrefix()
for _, g := range config.Passwd.Groups {
if err := s.CreateGroup(g); err != nil {
return fmt.Errorf("failed to create group %q: %v",
g... | [
"func",
"(",
"s",
"stage",
")",
"createGroups",
"(",
"config",
"types",
".",
"Config",
")",
"error",
"{",
"if",
"len",
"(",
"config",
".",
"Passwd",
".",
"Groups",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"s",
".",
"Logger",
".",
"P... | // createGroups creates the users as described in config.Passwd.Groups. | [
"createGroups",
"creates",
"the",
"users",
"as",
"described",
"in",
"config",
".",
"Passwd",
".",
"Groups",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/files/passwd.go#L84-L99 | train |
coreos/ignition | internal/exec/util/user_group_lookup.go | userLookup | func (u Util) userLookup(name string) (*user.User, error) {
res := &C.lookup_res_t{}
if ret, err := C.user_lookup(C.CString(u.DestDir),
C.CString(name), res); ret < 0 {
return nil, fmt.Errorf("lookup failed: %v", err)
}
if res.name == nil {
return nil, fmt.Errorf("user %q not found", name)
}
homedir, err... | go | func (u Util) userLookup(name string) (*user.User, error) {
res := &C.lookup_res_t{}
if ret, err := C.user_lookup(C.CString(u.DestDir),
C.CString(name), res); ret < 0 {
return nil, fmt.Errorf("lookup failed: %v", err)
}
if res.name == nil {
return nil, fmt.Errorf("user %q not found", name)
}
homedir, err... | [
"func",
"(",
"u",
"Util",
")",
"userLookup",
"(",
"name",
"string",
")",
"(",
"*",
"user",
".",
"User",
",",
"error",
")",
"{",
"res",
":=",
"&",
"C",
".",
"lookup_res_t",
"{",
"}",
"\n\n",
"if",
"ret",
",",
"err",
":=",
"C",
".",
"user_lookup",
... | // userLookup looks up the user in u.DestDir. | [
"userLookup",
"looks",
"up",
"the",
"user",
"in",
"u",
".",
"DestDir",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/user_group_lookup.go#L31-L58 | train |
coreos/ignition | internal/exec/util/user_group_lookup.go | groupLookup | func (u Util) groupLookup(name string) (*user.Group, error) {
res := &C.lookup_res_t{}
if ret, err := C.group_lookup(C.CString(u.DestDir),
C.CString(name), res); ret < 0 {
return nil, fmt.Errorf("lookup failed: %v", err)
}
if res.name == nil {
return nil, fmt.Errorf("user %q not found", name)
}
grp := &u... | go | func (u Util) groupLookup(name string) (*user.Group, error) {
res := &C.lookup_res_t{}
if ret, err := C.group_lookup(C.CString(u.DestDir),
C.CString(name), res); ret < 0 {
return nil, fmt.Errorf("lookup failed: %v", err)
}
if res.name == nil {
return nil, fmt.Errorf("user %q not found", name)
}
grp := &u... | [
"func",
"(",
"u",
"Util",
")",
"groupLookup",
"(",
"name",
"string",
")",
"(",
"*",
"user",
".",
"Group",
",",
"error",
")",
"{",
"res",
":=",
"&",
"C",
".",
"lookup_res_t",
"{",
"}",
"\n\n",
"if",
"ret",
",",
"err",
":=",
"C",
".",
"group_lookup... | // groupLookup looks up the group in u.DestDir. | [
"groupLookup",
"looks",
"up",
"the",
"group",
"in",
"u",
".",
"DestDir",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/user_group_lookup.go#L61-L81 | train |
coreos/ignition | internal/exec/stages/files/files.go | relabel | func (s *stage) relabel(paths ...string) {
if s.toRelabel != nil {
s.toRelabel = append(s.toRelabel, paths...)
}
} | go | func (s *stage) relabel(paths ...string) {
if s.toRelabel != nil {
s.toRelabel = append(s.toRelabel, paths...)
}
} | [
"func",
"(",
"s",
"*",
"stage",
")",
"relabel",
"(",
"paths",
"...",
"string",
")",
"{",
"if",
"s",
".",
"toRelabel",
"!=",
"nil",
"{",
"s",
".",
"toRelabel",
"=",
"append",
"(",
"s",
".",
"toRelabel",
",",
"paths",
"...",
")",
"\n",
"}",
"\n",
... | // relabel adds one or more paths to the list of paths that need relabeling. | [
"relabel",
"adds",
"one",
"or",
"more",
"paths",
"to",
"the",
"list",
"of",
"paths",
"that",
"need",
"relabeling",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/files/files.go#L125-L129 | train |
coreos/ignition | internal/exec/stages/files/files.go | addRelabelUnit | func (s *stage) addRelabelUnit(config types.Config) error {
if s.toRelabel == nil || len(s.toRelabel) == 0 {
return nil
}
contents := `[Unit]
Description=Relabel files created by Ignition
DefaultDependencies=no
After=local-fs.target
Before=sysinit.target systemd-sysctl.service
ConditionSecurity=selinux
ConditionPa... | go | func (s *stage) addRelabelUnit(config types.Config) error {
if s.toRelabel == nil || len(s.toRelabel) == 0 {
return nil
}
contents := `[Unit]
Description=Relabel files created by Ignition
DefaultDependencies=no
After=local-fs.target
Before=sysinit.target systemd-sysctl.service
ConditionSecurity=selinux
ConditionPa... | [
"func",
"(",
"s",
"*",
"stage",
")",
"addRelabelUnit",
"(",
"config",
"types",
".",
"Config",
")",
"error",
"{",
"if",
"s",
".",
"toRelabel",
"==",
"nil",
"||",
"len",
"(",
"s",
".",
"toRelabel",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"... | // addRelabelUnit creates and enables a runtime systemd unit to run restorecon
// if there are files that need to be relabeled. | [
"addRelabelUnit",
"creates",
"and",
"enables",
"a",
"runtime",
"systemd",
"unit",
"to",
"run",
"restorecon",
"if",
"there",
"are",
"files",
"that",
"need",
"to",
"be",
"relabeled",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/stages/files/files.go#L133-L181 | train |
coreos/ignition | config/v3_1_experimental/types/disk.go | partitionNumbersCollide | func (n Disk) partitionNumbersCollide() bool {
m := map[int][]Partition{}
for _, p := range n.Partitions {
if p.Number != 0 {
// a number of 0 means next available number, multiple devices can specify this
m[p.Number] = append(m[p.Number], p)
}
}
for _, n := range m {
if len(n) > 1 {
// TODO(vc): ret... | go | func (n Disk) partitionNumbersCollide() bool {
m := map[int][]Partition{}
for _, p := range n.Partitions {
if p.Number != 0 {
// a number of 0 means next available number, multiple devices can specify this
m[p.Number] = append(m[p.Number], p)
}
}
for _, n := range m {
if len(n) > 1 {
// TODO(vc): ret... | [
"func",
"(",
"n",
"Disk",
")",
"partitionNumbersCollide",
"(",
")",
"bool",
"{",
"m",
":=",
"map",
"[",
"int",
"]",
"[",
"]",
"Partition",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"n",
".",
"Partitions",
"{",
"if",
"p",
".",
"Number",... | // partitionNumbersCollide returns true if partition numbers in n.Partitions are not unique. | [
"partitionNumbersCollide",
"returns",
"true",
"if",
"partition",
"numbers",
"in",
"n",
".",
"Partitions",
"are",
"not",
"unique",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/v3_1_experimental/types/disk.go#L56-L71 | train |
coreos/ignition | config/v3_1_experimental/types/disk.go | end | func (p Partition) end() int {
if *p.SizeMiB == 0 {
// a size of 0 means "fill available", just return the start as the end for those.
return *p.StartMiB
}
return *p.StartMiB + *p.SizeMiB - 1
} | go | func (p Partition) end() int {
if *p.SizeMiB == 0 {
// a size of 0 means "fill available", just return the start as the end for those.
return *p.StartMiB
}
return *p.StartMiB + *p.SizeMiB - 1
} | [
"func",
"(",
"p",
"Partition",
")",
"end",
"(",
")",
"int",
"{",
"if",
"*",
"p",
".",
"SizeMiB",
"==",
"0",
"{",
"// a size of 0 means \"fill available\", just return the start as the end for those.",
"return",
"*",
"p",
".",
"StartMiB",
"\n",
"}",
"\n",
"return... | // end returns the last sector of a partition. Only used by partitionsOverlap. Requires non-nil Start and Size. | [
"end",
"returns",
"the",
"last",
"sector",
"of",
"a",
"partition",
".",
"Only",
"used",
"by",
"partitionsOverlap",
".",
"Requires",
"non",
"-",
"nil",
"Start",
"and",
"Size",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/v3_1_experimental/types/disk.go#L88-L94 | train |
coreos/ignition | config/v3_1_experimental/types/disk.go | partitionsOverlap | func (n Disk) partitionsOverlap() bool {
for _, p := range n.Partitions {
// Starts of 0 are placed by sgdisk into the "largest available block" at that time.
// We aren't going to check those for overlap since we don't have the disk geometry.
if p.StartMiB == nil || p.SizeMiB == nil || *p.StartMiB == 0 {
con... | go | func (n Disk) partitionsOverlap() bool {
for _, p := range n.Partitions {
// Starts of 0 are placed by sgdisk into the "largest available block" at that time.
// We aren't going to check those for overlap since we don't have the disk geometry.
if p.StartMiB == nil || p.SizeMiB == nil || *p.StartMiB == 0 {
con... | [
"func",
"(",
"n",
"Disk",
")",
"partitionsOverlap",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"n",
".",
"Partitions",
"{",
"// Starts of 0 are placed by sgdisk into the \"largest available block\" at that time.",
"// We aren't going to check those for over... | // partitionsOverlap returns true if any explicitly dimensioned partitions overlap | [
"partitionsOverlap",
"returns",
"true",
"if",
"any",
"explicitly",
"dimensioned",
"partitions",
"overlap"
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/config/v3_1_experimental/types/disk.go#L97-L127 | train |
coreos/ignition | internal/exec/util/file.go | newHashedReader | func newHashedReader(reader io.ReadCloser, hasher hash.Hash) io.ReadCloser {
return struct {
io.Reader
io.Closer
}{
Reader: io.TeeReader(reader, hasher),
Closer: reader,
}
} | go | func newHashedReader(reader io.ReadCloser, hasher hash.Hash) io.ReadCloser {
return struct {
io.Reader
io.Closer
}{
Reader: io.TeeReader(reader, hasher),
Closer: reader,
}
} | [
"func",
"newHashedReader",
"(",
"reader",
"io",
".",
"ReadCloser",
",",
"hasher",
"hash",
".",
"Hash",
")",
"io",
".",
"ReadCloser",
"{",
"return",
"struct",
"{",
"io",
".",
"Reader",
"\n",
"io",
".",
"Closer",
"\n",
"}",
"{",
"Reader",
":",
"io",
".... | // newHashedReader returns a new ReadCloser that also writes to the provided hash. | [
"newHashedReader",
"returns",
"a",
"new",
"ReadCloser",
"that",
"also",
"writes",
"to",
"the",
"provided",
"hash",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/file.go#L49-L57 | train |
coreos/ignition | internal/exec/util/file.go | PerformFetch | func (u Util) PerformFetch(f FetchOp) error {
path := f.Node.Path
if err := MkdirForFile(path); err != nil {
return err
}
// Create a temporary file in the same directory to ensure it's on the same filesystem
tmp, err := ioutil.TempFile(filepath.Dir(path), "tmp")
if err != nil {
return err
}
defer tmp.Clo... | go | func (u Util) PerformFetch(f FetchOp) error {
path := f.Node.Path
if err := MkdirForFile(path); err != nil {
return err
}
// Create a temporary file in the same directory to ensure it's on the same filesystem
tmp, err := ioutil.TempFile(filepath.Dir(path), "tmp")
if err != nil {
return err
}
defer tmp.Clo... | [
"func",
"(",
"u",
"Util",
")",
"PerformFetch",
"(",
"f",
"FetchOp",
")",
"error",
"{",
"path",
":=",
"f",
".",
"Node",
".",
"Path",
"\n\n",
"if",
"err",
":=",
"MkdirForFile",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
... | // PerformFetch performs a fetch operation generated by PrepareFetch, retrieving
// the file and writing it to disk. Any encountered errors are returned. | [
"PerformFetch",
"performs",
"a",
"fetch",
"operation",
"generated",
"by",
"PrepareFetch",
"retrieving",
"the",
"file",
"and",
"writing",
"it",
"to",
"disk",
".",
"Any",
"encountered",
"errors",
"are",
"returned",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/file.go#L173-L237 | train |
coreos/ignition | internal/exec/util/file.go | MkdirForFile | func MkdirForFile(path string) error {
return os.MkdirAll(filepath.Dir(path), DefaultDirectoryPermissions)
} | go | func MkdirForFile(path string) error {
return os.MkdirAll(filepath.Dir(path), DefaultDirectoryPermissions)
} | [
"func",
"MkdirForFile",
"(",
"path",
"string",
")",
"error",
"{",
"return",
"os",
".",
"MkdirAll",
"(",
"filepath",
".",
"Dir",
"(",
"path",
")",
",",
"DefaultDirectoryPermissions",
")",
"\n",
"}"
] | // MkdirForFile helper creates the directory components of path. | [
"MkdirForFile",
"helper",
"creates",
"the",
"directory",
"components",
"of",
"path",
"."
] | 1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9 | https://github.com/coreos/ignition/blob/1eeb201e9e6045383cba2e37ad53b3f49ca7b5a9/internal/exec/util/file.go#L240-L242 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.