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

feat(ui,cli): set service (name, type, region) on new consumer #6118

Merged
merged 1 commit into from
Mar 29, 2022
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
43 changes: 41 additions & 2 deletions cli/cdsctl/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ var authConsumerNewCmd = cli.Command{
Name: "duration",
Usage: "Validity period of the token generated for the consumer (in days)",
},
{
Name: "service-name",
Usage: "Name of the service",
},
{
Name: "service-type",
Usage: "Type of service (hatchery, etc.)",
},
{
Name: "service-region",
Usage: "Region where the service will be started",
},
},
}

Expand Down Expand Up @@ -167,13 +179,40 @@ func authConsumerNewRun(v cli.Values) error {
duration = time.Duration(iDuration) * (24 * time.Hour)
}

res, err := client.AuthConsumerCreateForUser(username, sdk.AuthConsumer{
var svcName = v.GetString("service-name")
if svcName == "" && !v.GetBool("no-interactive") {
svcName = cli.AskValue("Service name")
}

var svcType = v.GetString("service-type")
if svcType == "" && !v.GetBool("no-interactive") {
svcType = cli.AskValue("Service type")
}

var svcRegion = v.GetString("service-region")
if svcRegion == "" && !v.GetBool("no-interactive") {
svcRegion = cli.AskValue("Service region")
}

var consumer = sdk.AuthConsumer{
Name: name,
Description: description,
GroupIDs: groupIDs,
ScopeDetails: sdk.NewAuthConsumerScopeDetails(scopes...),
ValidityPeriods: sdk.NewAuthConsumerValidityPeriod(time.Now(), duration),
})
}

if svcName != "" {
consumer.ServiceName = &svcName
}
if svcType != "" {
consumer.ServiceType = &svcType
}
if svcRegion != "" {
consumer.ServiceRegion = &svcRegion
}

res, err := client.AuthConsumerCreateForUser(username, consumer)
if err != nil {
return err
}
Expand Down
15 changes: 8 additions & 7 deletions engine/api/auth_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ func (api *API) postConsumerByUserHandler() service.Handler {

// Create the new built in consumer from request data
consumerOpts := builtin.NewConsumerOptions{
Name: reqData.Name,
Description: reqData.Description,
Duration: reqData.ValidityPeriods.Latest().Duration,
GroupIDs: reqData.GroupIDs,
Scopes: reqData.ScopeDetails,
ServiceName: reqData.ServiceName,
ServiceType: reqData.ServiceType,
Name: reqData.Name,
Description: reqData.Description,
Duration: reqData.ValidityPeriods.Latest().Duration,
GroupIDs: reqData.GroupIDs,
Scopes: reqData.ScopeDetails,
ServiceName: reqData.ServiceName,
ServiceType: reqData.ServiceType,
ServiceRegion: reqData.ServiceRegion,
}
newConsumer, token, err := builtin.NewConsumer(ctx, tx, consumerOpts, consumer)
if err != nil {
Expand Down
16 changes: 9 additions & 7 deletions engine/api/authentication/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ func (d AuthDriver) CheckSigninRequest(req sdk.AuthConsumerSigninRequest) error
// NewConsumer returns a new builtin consumer for given data.
// The parent consumer should be given with all data loaded including the authentified user.
type NewConsumerOptions struct {
Name string
Description string
Duration time.Duration
GroupIDs []int64
Scopes sdk.AuthConsumerScopeDetails
ServiceName *string
ServiceType *string
Name string
Description string
Duration time.Duration
GroupIDs []int64
Scopes sdk.AuthConsumerScopeDetails
ServiceName *string
ServiceType *string
ServiceRegion *string
}

func NewConsumer(ctx context.Context, db gorpmapper.SqlExecutorWithTx, opts NewConsumerOptions, parentConsumer *sdk.AuthConsumer) (*sdk.AuthConsumer, string, error) {
Expand Down Expand Up @@ -112,6 +113,7 @@ func NewConsumer(ctx context.Context, db gorpmapper.SqlExecutorWithTx, opts NewC
ValidityPeriods: sdk.NewAuthConsumerValidityPeriod(time.Now(), opts.Duration),
ServiceName: opts.ServiceName,
ServiceType: opts.ServiceType,
ServiceRegion: opts.ServiceRegion,
}

if err := authentication.InsertConsumer(ctx, db, &c); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions ui/src/app/model/authentication.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export class AuthConsumer {
warnings: Array<AuthConsumerWarning>;
validity_periods: Array<AuthConsumerValidityPeriod>;
last_authentication: string;
service_name: string;
service_type: string;
service_region: string;

// UI fields
parent: AuthConsumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export enum FormStepName {
INFORMATIONS = 0,
GROUPS = 1,
SCOPES = 2,
TOKEN = 3
SERVICE = 3,
TOKEN = 4
}

@Component({
Expand Down Expand Up @@ -182,6 +183,9 @@ export class ConsumerCreateModalComponent {
case FormStepName.SCOPES:
this.activeStep = FormStepName.GROUPS;
break;
case FormStepName.SERVICE:
this.activeStep = FormStepName.SCOPES;
break;
default:
return;
}
Expand All @@ -201,6 +205,9 @@ export class ConsumerCreateModalComponent {
this.activeStep = FormStepName.SCOPES;
break;
case FormStepName.SCOPES:
this.activeStep = FormStepName.SERVICE;
break;
case FormStepName.SERVICE:
this.save();
return;
default:
Expand Down Expand Up @@ -234,6 +241,8 @@ export class ConsumerCreateModalComponent {
return true;
case FormStepName.SCOPES:
return this.selectedScopeDetails.length > 0;
case FormStepName.SERVICE:
return true;
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,38 @@
</table>
</div>
</sui-accordion-panel>
<sui-accordion-panel [isOpen]="activeStep === formStepName.SERVICE" [isDisabled]="true">
<div title (click)="clickOpenStep(formStepName.SERVICE)">
<i class="dropdown icon"></i>
Service
</div>
<div content>
<div class="ui form">
<div class="ui message">
<p>Optional fields for consumer used by services (eg. hatcheries).</p>
</div>
<div class="ui wide field">
<div class="fields">
<div class="six wide field">
<label>{{'common_name' | translate}}</label>
<input class="ui input" type="text" name="name"
[(ngModel)]="newConsumer.service_name">
</div>
<div class="six wide field">
<label>Type</label>
<input class="ui input" type="text" name="type"
[(ngModel)]="newConsumer.service_type">
</div>
<div class="six wide field">
<label>Region</label>
<input class="ui input" type="text" name="region"
[(ngModel)]="newConsumer.service_region">
</div>
</div>
</div>
</div>
</div>
</sui-accordion-panel>
</sui-accordion>
<app-consumer-display-signin-token *ngIf="newConsumer.id" [consumer]="newConsumer"
[signinToken]="signinToken">
Expand All @@ -77,15 +109,15 @@
<div class="actions">
<div class="ui grid">
<div class="four wide column left aligned">
<button *ngIf="activeStep === formStepName.GROUPS || activeStep === formStepName.SCOPES"
<button *ngIf="activeStep === formStepName.GROUPS || activeStep === formStepName.SCOPES || activeStep === formStepName.SERVICE"
class="ui primary button" (click)="clickBack()">
{{ 'btn_back' | translate }}
</button>
</div>
<div class="eight wide column centered">
<button *ngIf="activeStep !== formStepName.TOKEN" class="ui green button" [class.loading]="loading"
(click)="clickNext()">
<ng-container *ngIf="activeStep === formStepName.SCOPES; then createButton; else nextButton">
<ng-container *ngIf="activeStep === formStepName.SERVICE; then createButton; else nextButton">
</ng-container>
<ng-template #createButton>
<i class="save icon"></i>{{ 'btn_create' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@
<div class="two fields">
<div class="field">
<label>Last authentication</label>
{{consumer.last_authentication}}
{{consumer.last_authentication ? consumer.last_authentication : 'never'}}
</div>
<div class="field" *ngIf="consumer.service_name || consumer.service_type || consumer.service_region">
<label>Service detail</label>
<ul>
<li>Name: {{consumer.service_name}}</li>
<li>Type: {{consumer.service_type}}</li>
<li>Region: {{consumer.service_region}}</li>
</ul>
</div>
</div>
<div class="field">
Expand Down