Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key=value pairs #421

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 145 additions & 86 deletions api/v1/challenge/challenge.pb.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions api/v1/challenge/challenge.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ message CreateChallengeRequest {

// The date after which the janitor will have permission to delete the instance.
google.protobuf.Timestamp until = 5 [(google.api.field_behavior) = OPTIONAL];

// A key=value configuration to pass to the instance when created.
map<string, string> config = 6 [(google.api.field_behavior) = OPTIONAL];
}

message RetrieveChallengeRequest {
Expand Down Expand Up @@ -111,6 +114,9 @@ message UpdateChallengeRequest {
google.protobuf.Timestamp until = 5 [(google.api.field_behavior) = OPTIONAL];

google.protobuf.FieldMask update_mask = 6;

// A key=value configuration to pass to the instance when created.
map<string, string> config = 7 [(google.api.field_behavior) = OPTIONAL];
}

message DeleteChallengeRequest {
Expand Down Expand Up @@ -139,6 +145,9 @@ message Challenge {

// The challenge running instances.
repeated instance.Instance instances = 5 [(google.api.field_behavior) = OPTIONAL];

// A key=value configuration to pass to the instance when created.
map<string, string> config = 6 [(google.api.field_behavior) = OPTIONAL];
}

// The UpdateStrategy to use in case of a Challenge scenario update with running instances.
Expand Down
2 changes: 2 additions & 0 deletions api/v1/challenge/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (store *Store) CreateChallenge(ctx context.Context, req *CreateChallengeReq
Hash: h,
Timeout: toDuration(req.Timeout),
Until: toTime(req.Until),
Config: req.Config,
}
if err := fschall.Save(); err != nil {
err := &errs.ErrInternal{Sub: err}
Expand All @@ -129,6 +130,7 @@ func (store *Store) CreateChallenge(ctx context.Context, req *CreateChallengeReq
Timeout: req.Timeout,
Until: req.Until,
Instances: []*instance.Instance{},
Config: req.Config,
}

// 6. Unlock RW challenge
Expand Down
2 changes: 2 additions & 0 deletions api/v1/challenge/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (store *Store) QueryChallenge(_ *emptypb.Empty, server ChallengeStore_Query
Until: until,
ConnectionInfo: fsist.ConnectionInfo,
Flag: fsist.Flag,
Config: fsist.Config,
})
}

Expand All @@ -134,6 +135,7 @@ func (store *Store) QueryChallenge(_ *emptypb.Empty, server ChallengeStore_Query
Timeout: toPBDuration(fschall.Timeout),
Until: toPBTimestamp(fschall.Until),
Instances: ists,
Config: fschall.Config,
}); err != nil {
cerr <- err
return
Expand Down
2 changes: 2 additions & 0 deletions api/v1/challenge/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (store *Store) RetrieveChallenge(ctx context.Context, req *RetrieveChalleng
Until: until,
ConnectionInfo: fsist.ConnectionInfo,
Flag: fsist.Flag,
Config: fsist.Config,
})
}

Expand All @@ -134,6 +135,7 @@ func (store *Store) RetrieveChallenge(ctx context.Context, req *RetrieveChalleng
Timeout: toPBDuration(fschall.Timeout),
Until: toPBTimestamp(fschall.Until),
Instances: ists,
Config: fschall.Config,
}, nil
}

Expand Down
27 changes: 16 additions & 11 deletions api/v1/challenge/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,18 @@ func (store *Store) UpdateChallenge(ctx context.Context, req *UpdateChallengeReq
}

// 5. Update challenge until/timeout and scenario on filesystem
updateConfig := false
um := req.GetUpdateMask()
if um.IsValid(req) {
if slices.Contains(um.Paths, "until") {
if req.Until != nil {
fschall.Until = toTime(req.Until)
} else {
fschall.Until = nil
}
fschall.Until = toTime(req.Until)
}
if slices.Contains(um.Paths, "timeout") {
if req.Timeout != nil {
fschall.Timeout = toDuration(req.Timeout)
} else {
fschall.Timeout = nil
}
fschall.Timeout = toDuration(req.Timeout)
}
if slices.Contains(um.Paths, "config") {
fschall.Config = req.Config
updateConfig = true
}
}

Expand Down Expand Up @@ -171,7 +168,11 @@ func (store *Store) UpdateChallenge(ctx context.Context, req *UpdateChallengeReq
logger.Info(ctx, "updating challenge",
zap.Int("instances", len(iids)),
zap.Bool("update_scenario", updateScenario),
zap.Bool("update_config", updateConfig),
)
if req.UpdateStrategy == nil {
req.UpdateStrategy = UpdateStrategy_update_in_place.Enum()
}
relock := &sync.WaitGroup{}
relock.Add(len(iids))
work := &sync.WaitGroup{}
Expand Down Expand Up @@ -222,8 +223,12 @@ func (store *Store) UpdateChallenge(ctx context.Context, req *UpdateChallengeReq
fsist.Until = common.ComputeUntil(fschall.Until, fschall.Timeout)

// 8.d. If scenario is not nil, update it
ndir := fschall.Directory
if updateScenario {
if err := iac.Update(ctx, *oldDir, req.UpdateStrategy.String(), fschall, fsist); err != nil {
ndir = *oldDir
}
if updateScenario || updateConfig {
if err := iac.Update(ctx, ndir, req.UpdateStrategy.String(), fschall, fsist); err != nil {
cerr <- err
return
}
Expand Down
8 changes: 8 additions & 0 deletions api/v1/instance/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func (man *Manager) CreateInstance(ctx context.Context, req *CreateInstanceReque
)
return nil, errs.ErrInternalNoSub
}
if err := iac.Additional(ctx, stack, fschall.Config, req.Config); err != nil {
logger.Error(ctx, "configuring additionals on stack",
zap.Error(err),
)
return nil, errs.ErrInternalNoSub
}

logger.Info(ctx, "creating instance")

Expand All @@ -148,6 +154,7 @@ func (man *Manager) CreateInstance(ctx context.Context, req *CreateInstanceReque
Since: now,
LastRenew: now,
Until: common.ComputeUntil(fschall.Until, fschall.Timeout),
Config: req.Config,
}
if err := iac.Extract(ctx, stack, sr, fsist); err != nil {
logger.Error(ctx, "extracting stack info",
Expand Down Expand Up @@ -183,5 +190,6 @@ func (man *Manager) CreateInstance(ctx context.Context, req *CreateInstanceReque
Until: until,
ConnectionInfo: fsist.ConnectionInfo,
Flag: fsist.Flag,
Config: req.Config,
}, nil
}
Loading
Loading